-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
178 additions
and
25 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file added
BIN
+30.5 MB
examples/music/wav/twinkle-incremental-1000-5-01H95GE7FQZS8W0PY22XVM5E07.wav
Binary file not shown.
Binary file added
BIN
+5.99 MB
examples/music/wav/twinkle-incremental-1500-5-01H95G3HVVSWVK9K3CTNYTWACF.wav
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 8, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from qreservoirpy import util\n", | ||
"from qreservoirpy.reservoirs import Static\n", | ||
"\n", | ||
"from qiskit.quantum_info import Clifford, random_clifford\n", | ||
"from qiskit.extensions import HamiltonianGate\n", | ||
"from qiskit.circuit.library import PauliGate\n", | ||
"from qiskit.circuit.library import U1Gate" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 14, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
"c:\\users\\otkul\\sintef\\repo\\reservoircomputingexamples\\qreservoirpy\\qreservoirpy\\reservoirbase.py:37: UserWarning: Argument 'backend' must inherit from qiskits abstract 'Backend'. Using 'aer_simulator' instead\n", | ||
" warnings.warn(\"Argument 'backend' must inherit from qiskits abstract 'Backend'. Using 'aer_simulator' instead\")\n", | ||
"C:\\Users\\otkul\\AppData\\Local\\Temp\\ipykernel_11028\\2734235736.py:18: DeprecationWarning: The property ``qiskit.quantum_info.operators.symplectic.clifford.Clifford.stabilizer`` is deprecated as of qiskit-terra 0.24.0. It will be removed no earlier than 3 months after the release date. Use Clifford.stab properties instead.\n", | ||
" ops = [elem[-self.n_logical:] for elem in cliff.stabilizer.to_labels()]\n" | ||
] | ||
}, | ||
{ | ||
"ename": "AttributeError", | ||
"evalue": "'ReservoirCircuit' object has no attribute 'initalize'", | ||
"output_type": "error", | ||
"traceback": [ | ||
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", | ||
"\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)", | ||
"Cell \u001b[1;32mIn[14], line 50\u001b[0m\n\u001b[0;32m 42\u001b[0m encoder[elem] \u001b[39m=\u001b[39m U1Gate(theta, \u001b[39mstr\u001b[39m(elem))\n\u001b[0;32m 44\u001b[0m qres \u001b[39m=\u001b[39m Stabilizer(\n\u001b[0;32m 45\u001b[0m n_qubits\u001b[39m=\u001b[39m\u001b[39m4\u001b[39m,\n\u001b[0;32m 46\u001b[0m n_ancilla\u001b[39m=\u001b[39m\u001b[39m2\u001b[39m,\n\u001b[0;32m 47\u001b[0m encoder\u001b[39m=\u001b[39mencoder\n\u001b[0;32m 48\u001b[0m )\n\u001b[1;32m---> 50\u001b[0m qres\u001b[39m.\u001b[39;49mcircuit([\u001b[39m0\u001b[39;49m, \u001b[39m1\u001b[39;49m, \u001b[39m2\u001b[39;49m], merge_registers\u001b[39m=\u001b[39;49m\u001b[39mTrue\u001b[39;49;00m, transpile\u001b[39m=\u001b[39;49m\u001b[39mFalse\u001b[39;49;00m)\u001b[39m.\u001b[39mdraw(\u001b[39m'\u001b[39m\u001b[39mmpl\u001b[39m\u001b[39m'\u001b[39m)\n", | ||
"File \u001b[1;32mc:\\users\\otkul\\sintef\\repo\\reservoircomputingexamples\\qreservoirpy\\qreservoirpy\\reservoirbase.py:54\u001b[0m, in \u001b[0;36mQReservoir.circuit\u001b[1;34m(self, timeseries, merge_registers, transpile)\u001b[0m\n\u001b[0;32m 52\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mcircuit\u001b[39m(\u001b[39mself\u001b[39m, timeseries, merge_registers\u001b[39m=\u001b[39m\u001b[39mFalse\u001b[39;00m, transpile\u001b[39m=\u001b[39m\u001b[39mTrue\u001b[39;00m):\n\u001b[0;32m 53\u001b[0m circ \u001b[39m=\u001b[39m ReservoirCircuit(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mn_qubits)\n\u001b[1;32m---> 54\u001b[0m circ \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m__build(circ, timeseries)\n\u001b[0;32m 56\u001b[0m \u001b[39mif\u001b[39;00m merge_registers:\n\u001b[0;32m 57\u001b[0m temp_circ \u001b[39m=\u001b[39m CountingCircuit(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mn_qubits, circ\u001b[39m.\u001b[39mnum_clbits)\n", | ||
"File \u001b[1;32mc:\\users\\otkul\\sintef\\repo\\reservoircomputingexamples\\qreservoirpy\\qreservoirpy\\reservoirbase.py:75\u001b[0m, in \u001b[0;36mQReservoir.__build\u001b[1;34m(self, circ, timeseries)\u001b[0m\n\u001b[0;32m 73\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mbefore(circ)\n\u001b[0;32m 74\u001b[0m \u001b[39mfor\u001b[39;00m t \u001b[39min\u001b[39;00m timeseries:\n\u001b[1;32m---> 75\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mduring(circ, t)\n\u001b[0;32m 76\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mafter(circ)\n\u001b[0;32m 78\u001b[0m \u001b[39mreturn\u001b[39;00m circ\n", | ||
"Cell \u001b[1;32mIn[14], line 28\u001b[0m, in \u001b[0;36mStabilizer.during\u001b[1;34m(self, circuit, timestep)\u001b[0m\n\u001b[0;32m 26\u001b[0m \u001b[39mfor\u001b[39;00m i \u001b[39min\u001b[39;00m \u001b[39mrange\u001b[39m(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mn_ancilla):\n\u001b[0;32m 27\u001b[0m anc \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mn_logical\n\u001b[1;32m---> 28\u001b[0m circuit\u001b[39m.\u001b[39;49minitalize(\u001b[39m'\u001b[39m\u001b[39m+\u001b[39m\u001b[39m'\u001b[39m, anc)\n\u001b[0;32m 29\u001b[0m circuit\u001b[39m.\u001b[39mappend(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mops[i], [anc] \u001b[39m+\u001b[39m \u001b[39mlist\u001b[39m(np\u001b[39m.\u001b[39marange(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mn_logical)))\n\u001b[0;32m 30\u001b[0m circuit\u001b[39m.\u001b[39mh(anc)\n", | ||
"\u001b[1;31mAttributeError\u001b[0m: 'ReservoirCircuit' object has no attribute 'initalize'" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"import numpy as np\n", | ||
"\n", | ||
"\n", | ||
"class Stabilizer(Static):\n", | ||
" def __init__(self, n_qubits, n_ancilla, encoder, memory=np.inf, backend=None) -> None:\n", | ||
" super().__init__(n_qubits + 1, memory, backend)\n", | ||
" self.n_logical = n_qubits\n", | ||
" self.n_ancilla = n_ancilla\n", | ||
" self.encoder = encoder\n", | ||
"\n", | ||
" OP = random_clifford(n_qubits)\n", | ||
"\n", | ||
" H = util.random_ising_H(num_qubits=n_qubits, num_terms=40)\n", | ||
" T = 1 #s\n", | ||
" self.reservoir = HamiltonianGate(H, T, label=\"UT\")\n", | ||
"\n", | ||
" cliff = Clifford(OP)\n", | ||
" ops = [elem[-self.n_logical:] for elem in cliff.stabilizer.to_labels()]\n", | ||
" self.ops = [PauliGate(elem).control(1) for elem in ops]\n", | ||
"\n", | ||
" def before(self, circuit):\n", | ||
" return super().before(circuit)\n", | ||
" def during(self, circuit, timestep):\n", | ||
" circuit.barrier()\n", | ||
"\n", | ||
" for i in range(self.n_ancilla):\n", | ||
" anc = self.n_logical\n", | ||
" circuit.initalize('+', anc)\n", | ||
" circuit.append(self.ops[i], [anc] + list(np.arange(self.n_logical)))\n", | ||
" circuit.h(anc)\n", | ||
" circuit.measure(anc)\n", | ||
" \n", | ||
" circuit.append(self.encoder[timestep], [0])\n", | ||
" circuit.append(self.reservoir, range(self.n_logical))\n", | ||
" def after(self, circuit):\n", | ||
" return super().after(circuit)\n", | ||
" \n", | ||
"encoder = {}\n", | ||
"timestep = [0, 1, 2]\n", | ||
"for elem in np.unique(timestep):\n", | ||
" theta = np.random.uniform(low=-2*np.pi, high=2*np.pi)\n", | ||
" encoder[elem] = U1Gate(theta, str(elem))\n", | ||
"\n", | ||
"qres = Stabilizer(\n", | ||
" n_qubits=4,\n", | ||
" n_ancilla=2,\n", | ||
" encoder=encoder\n", | ||
")\n", | ||
"\n", | ||
"qres.circuit([0, 1, 2], merge_registers=True, transpile=False).draw('mpl')" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "quantum", | ||
"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.9.13" | ||
}, | ||
"orig_nbformat": 4 | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.