{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "9a2de8ed-b6e8-4fea-bda7-e4daab5b6789",
   "metadata": {},
   "outputs": [],
   "source": [
    "import json \n",
    "import numpy as np\n",
    "import pickle\n",
    "\n",
    "def read_from_jsonl(file_path):\n",
    "    # Read the .jsonl file\n",
    "    data = []\n",
    "    with open(file_path, 'r') as f:\n",
    "        for line in f:\n",
    "            # Parse each line as a JSON object and append to the list\n",
    "            data.append(json.loads(line.strip()))\n",
    "    \n",
    "    # Now, `data` contains all the JSON objects from the file\n",
    "    return data\n",
    "\n",
    "def write_to_jsonl(data,file_path):\n",
    "    with open(file_path, 'w') as f:\n",
    "        for item in data:\n",
    "            f.write(json.dumps(item) + '\\n')\n",
    "\n",
    "def save_to_file(object,file_name):\n",
    "    with open(file_name, 'wb') as file:\n",
    "        pickle.dump(object, file)\n",
    "\n",
    "def load_from_file(file_name):\n",
    "    with open(file_name, 'rb') as file:\n",
    "        loaded_data = pickle.load(file)\n",
    "        return loaded_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d7ed8f11-6fb6-4e80-94fd-75ffdc535a54",
   "metadata": {},
   "outputs": [],
   "source": [
    "norag = read_from_jsonl(\"scratch/code-generation/mbpp/results/deepseekcoder.jsonl\")\n",
    "bwrag = read_from_jsonl(\"/Users/imansaberi/Documents/research_projects/knowledge_graph/solutions/codellama7b/bwrag.jsonl\")\n",
    "fwrag = read_from_jsonl(\"/Users/imansaberi/Documents/research_projects/knowledge_graph/solutions/codellama7b/fwrag.jsonl\")\n",
    "bm25rag = read_from_jsonl(\"/Users/imansaberi/Documents/research_projects/knowledge_graph/solutions/codellama7b/norag.jsonl\")\n",
    "assertions = load_from_file(\"human_eval_assertions.pkl\")\n",
    "from human_eval.data import write_jsonl, read_problems\n",
    "problems = read_problems()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
