diff --git a/serialization_test_ghz.ipynb b/serialization_test_ghz.ipynb deleted file mode 100644 index f694dd4ac..000000000 --- a/serialization_test_ghz.ipynb +++ /dev/null @@ -1,189 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 355, - "metadata": {}, - "outputs": [], - "source": [ - "from time import perf_counter\n", - "from qat.purr.backends.echo import get_default_echo_hardware\n", - "import gc \n", - "gc.disable()" - ] - }, - { - "cell_type": "code", - "execution_count": 356, - "metadata": {}, - "outputs": [], - "source": [ - "num_qubits = 10\n", - "\n", - "def ghz_state(builder):\n", - " num_qubits = len(builder.model.qubits)\n", - " for i in range(num_qubits-1):\n", - " builder.cnot(builder.model.get_qubit(i), builder.model.get_qubit(i + 1))\n", - " for i in range(num_qubits):\n", - " builder.measure(builder.model.get_qubit(i))\n", - " return builder\n", - " " - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Old instructions" - ] - }, - { - "cell_type": "code", - "execution_count": 357, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Serialization time: 0.14612181298434734\n", - "Deserialization time: 0.051338869001483545\n" - ] - } - ], - "source": [ - "from qat.purr.compiler.builders import QuantumInstructionBuilder as LegacyQuantumInstructionBuilder\n", - "from qat.purr.compiler.emitter import InstructionEmitter as LegacyInstructionEmitter\n", - "import jsonpickle\n", - "from qat.purr.compiler.devices import (\n", - " CyclicRefPickler,\n", - " CyclicRefUnpickler\n", - ")\n", - "\n", - "model = get_default_echo_hardware(10)\n", - "\n", - "builder = model.create_builder()\n", - "builder = ghz_state(builder)\n", - "qatfile = LegacyInstructionEmitter().emit(builder.instructions, model)\n", - "\n", - "t_s_before = perf_counter()\n", - "with open(\"test.json\", \"w\") as f:\n", - " blob = jsonpickle.encode(qatfile, indent=4, context=CyclicRefPickler())\n", - " f.write(blob)\n", - "t_s_before = perf_counter() - t_s_before\n", - "print(f\"Serialization time: {t_s_before}\")\n", - "\n", - "t_d_before = perf_counter()\n", - "with open(\"test.json\", \"r\") as f:\n", - " qatfile = jsonpickle.decode(f.read(), context=CyclicRefUnpickler())\n", - "t_d_before = perf_counter() - t_d_before\n", - "print(f\"Deserialization time: {t_d_before}\")\n", - "\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "New instructions" - ] - }, - { - "cell_type": "code", - "execution_count": 358, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Serialization time: 0.0029328979726415128\n", - "Deserialization time: 0.007109844998922199\n" - ] - } - ], - "source": [ - "from qat.ir.builders import QuantumInstructionBuilder\n", - "from qat.ir.emitter import InstructionEmitter, QatFile\n", - "\n", - "model = get_default_echo_hardware(10)\n", - "\n", - "builder = QuantumInstructionBuilder(model)\n", - "builder = ghz_state(builder)\n", - "qatfile = InstructionEmitter().emit(builder.instructions, model)\n", - "\n", - "t_s_after = perf_counter()\n", - "with open(\"test2.json\", \"w\") as f:\n", - " blob = qatfile.serialize()\n", - " f.write(blob)\n", - "t_s_after = perf_counter() - t_s_after\n", - "print(f\"Serialization time: {t_s_after}\")\n", - "\n", - "t_d_after = perf_counter()\n", - "with open(\"test2.json\", \"r\") as f:\n", - " new_qatfile = QatFile.deserialize(f.read())\n", - "t_d_after = perf_counter() - t_d_after\n", - "print(f\"Deserialization time: {t_d_after}\")" - ] - }, - { - "cell_type": "code", - "execution_count": 359, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Seralization improvement: 49.82164887677386\n", - "Deseralization improvement: 7.220814097813124\n" - ] - } - ], - "source": [ - "print(f\"Seralization improvement: {t_s_before / t_s_after}\")\n", - "print(f\"Deseralization improvement: {t_d_before / t_d_after}\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Check that the types of the new qat file are correct" - ] - }, - { - "cell_type": "code", - "execution_count": 360, - "metadata": {}, - "outputs": [], - "source": [ - "for i, inst in enumerate(new_qatfile.timeline):\n", - " assert type(inst.instruction) == type(qatfile.timeline[i].instruction)\n", - "for i, inst in enumerate(new_qatfile.meta_instructions.instructions):\n", - " assert type(inst) == type(qatfile.meta_instructions.instructions[i])" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "qat-compiler-ILvFCGSW-py3.10", - "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.10.12" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -}