Skip to content

Commit f9451c7

Browse files
added experiments
1 parent 4b88085 commit f9451c7

12 files changed

+1264
-45
lines changed
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "a3f4079e-8dab-4a6a-b326-53c84cde572c",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"import numpy as np\n",
11+
"import matplotlib.pyplot as plt\n",
12+
"# import matplotlib.colors as mcolors\n",
13+
"import pickle\n",
14+
"import tikzplotlib\n",
15+
"from collections import defaultdict\n",
16+
"def tikzplotlib_fix_ncols(obj):\n",
17+
" \"\"\"\n",
18+
" workaround for matplotlib 3.6 renamed legend's _ncol to _ncols, which breaks tikzplotlib\n",
19+
" \"\"\"\n",
20+
" if hasattr(obj, \"_ncols\"):\n",
21+
" obj._ncol = obj._ncols\n",
22+
" for child in obj.get_children():\n",
23+
" tikzplotlib_fix_ncols(child)\n",
24+
"casename=\"henon\""
25+
]
26+
},
27+
{
28+
"cell_type": "code",
29+
"execution_count": 2,
30+
"id": "f95a6de7-6e84-43a0-86d6-d2bd23633036",
31+
"metadata": {},
32+
"outputs": [],
33+
"source": [
34+
"if casename==\"logistic\":\n",
35+
" from reservoirpy.datasets import logistic_map\n",
36+
" ts=logistic_map(100000, r=3.9, x0=0.5).flatten()\n",
37+
"elif casename==\"henon\":\n",
38+
" from run_reservoir import henon1d \n",
39+
" ts = henon1d(10000)"
40+
]
41+
},
42+
{
43+
"cell_type": "code",
44+
"execution_count": null,
45+
"id": "2cac7dd9",
46+
"metadata": {},
47+
"outputs": [],
48+
"source": [
49+
"num_qubits=6\n",
50+
"num_meas=3\n",
51+
"degree=2"
52+
]
53+
},
54+
{
55+
"cell_type": "code",
56+
"execution_count": null,
57+
"id": "4dec95e5-58ea-4932-8bc0-88e3a2285a25",
58+
"metadata": {},
59+
"outputs": [],
60+
"source": [
61+
"def get_data(ep, num_qubits, num_meas, method, noise=\"None\", decode=True):\n",
62+
" degree=num_meas\n",
63+
" num_reservoirs=20\n",
64+
" timeplex=1\n",
65+
" string_identifier=str(ep)+\"_casename\"+str(casename)+\"_num_qubits\"+str(num_qubits)+\"_num_meas\"+str(num_meas)\n",
66+
" string_identifier+=\"_degree\"+str(degree)+\"_num_reservoirs\"+str(num_reservoirs)+\"_timeplex\"+str(timeplex)\n",
67+
" string_identifier+=\"_method\"+str(method)+\"_noise\"+str(noise)\n",
68+
" if not decode:\n",
69+
" string_identifier+=\"_decodeFalse\"\n",
70+
" string_identifier+=\".pickle\"\n",
71+
" name=\"X_train\"+string_identifier\n",
72+
" # print(\"name=\",name)\n",
73+
" with open(name,\"rb\") as f:\n",
74+
" X_train = pickle.load(f)\n",
75+
" \n",
76+
" name=\"X_test\"+string_identifier\n",
77+
" with open(name,\"rb\") as f:\n",
78+
" X_test = pickle.load(f)\n",
79+
" \n",
80+
" name=\"score\"+string_identifier\n",
81+
" with open(name,\"rb\") as f:\n",
82+
" score = pickle.load(f)\n",
83+
" \n",
84+
" name=\"prediction\"+string_identifier\n",
85+
" with open(name,\"rb\") as f:\n",
86+
" prediction = pickle.load(f)\n",
87+
" \n",
88+
" name=\"state\"+string_identifier\n",
89+
" with open(name,\"rb\") as f:\n",
90+
" state = pickle.load(f)\n",
91+
" return X_train, X_test, score, prediction, state, string_identifier"
92+
]
93+
},
94+
{
95+
"cell_type": "code",
96+
"execution_count": 4,
97+
"id": "43ea3fa2-780c-4d55-b69b-7e1730bce1a0",
98+
"metadata": {},
99+
"outputs": [],
100+
"source": [
101+
"# X_train, X_test, score, prediction, state, basen = get_data(ep, 7, 6, \"classical\", \"None\")\n",
102+
"# _=plt.plot(state)"
103+
]
104+
},
105+
{
106+
"cell_type": "code",
107+
"execution_count": null,
108+
"id": "9fdee019",
109+
"metadata": {},
110+
"outputs": [],
111+
"source": [
112+
"for ep in [0,4]:\n",
113+
" X_train, X_test, score, prediction, states, basen = get_data(ep, num_qubits, num_meas, \"classical\", \"None\")\n",
114+
" data=states\n",
115+
" groups = defaultdict(list)\n",
116+
" for n, m, _ , stats in data:\n",
117+
" mean, var = stats\n",
118+
" x = n\n",
119+
" groups[n].append((x, float(mean), float(var)))\n",
120+
"\n",
121+
" # Plot each group\n",
122+
" plt.figure(figsize=(8,6))\n",
123+
"\n",
124+
" for n, values in groups.items():\n",
125+
" values.sort(key=lambda v: v[0]) # sort by x = n/m\n",
126+
" xs = [v[0] for v in values]\n",
127+
" ys = [v[1] for v in values]\n",
128+
" errs = [v[2] for v in values]\n",
129+
" plt.errorbar(xs, ys, yerr=errs, label=f\"n = {n}\", marker='o', capsize=4)\n",
130+
"\n",
131+
" plt.xlabel(\"degree\")\n",
132+
" plt.ylabel(\"Mean ± Variance\")\n",
133+
" plt.legend()\n",
134+
" plt.grid(True)\n",
135+
" plt.show()"
136+
]
137+
}
138+
],
139+
"metadata": {
140+
"kernelspec": {
141+
"display_name": "Python 3 (ipykernel)",
142+
"language": "python",
143+
"name": "python3"
144+
},
145+
"language_info": {
146+
"codemirror_mode": {
147+
"name": "ipython",
148+
"version": 3
149+
},
150+
"file_extension": ".py",
151+
"mimetype": "text/x-python",
152+
"name": "python",
153+
"nbconvert_exporter": "python",
154+
"pygments_lexer": "ipython3",
155+
"version": "3.8.12"
156+
}
157+
},
158+
"nbformat": 4,
159+
"nbformat_minor": 5
160+
}

examples/stabilizer/Unpickle logistic and henon map.ipynb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -606,14 +606,6 @@
606606
"print(nh)\n",
607607
"len(h), len(nh)"
608608
]
609-
},
610-
{
611-
"cell_type": "code",
612-
"execution_count": null,
613-
"id": "a9b6f0bf-beaf-4397-a2a4-59e0624a65a3",
614-
"metadata": {},
615-
"outputs": [],
616-
"source": []
617609
}
618610
],
619611
"metadata": {

examples/stabilizer/createIsingParams.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ def createanddumpsising(num_qubits):
1616
with open("isingparams_"+"num_qubits"+str(num_qubits)+"_num_reservoirs"+str(num_reservoirs)+".pickle","wb") as f:
1717
pickle.dump(isingparams, f)
1818

19-
createanddumpsising(3)
20-
createanddumpsising(4)
21-
createanddumpsising(5)
19+
for num_qubits in range (3,11):
20+
createanddumpsising(num_qubits)
21+
Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
from quantumreservoirpy.stabilizer import Stabilizer
22
import pickle
33

4-
def createanddumptableaus(num_qubits, num_measurements):
4+
def createanddumptableaus(num_qubits, num_measurements,degree=None):
55
num_tableaus = 100
66
tableaus = {}
77
for nr in range(1, num_tableaus+ 1):
8-
tableaus[nr] = Stabilizer.generate_tableau(num_qubits, num_measurements)
9-
with open("tableau_"+"num_qubits"+str(num_qubits)+"_num_measurements"+str(num_measurements)+"_num_tableaus"+str(num_tableaus)+".pickle","wb") as f:
10-
pickle.dump(tableaus, f)
8+
if degree is not None:
9+
tableaus[nr] = Stabilizer.generate_tableau(num_qubits, num_measurements,stab_method='degree', degree=degree)
10+
with open("tableau_"+"num_qubits"+str(num_qubits)+"_num_measurements"+str(num_measurements)+"degree"+str(degree)+"_num_tableaus"+str(num_tableaus)+".pickle","wb") as f:
11+
pickle.dump(tableaus, f)
12+
else:
13+
tableaus[nr] = Stabilizer.generate_tableau(num_qubits, num_measurements)
14+
with open("tableau_"+"num_qubits"+str(num_qubits)+"_num_measurements"+str(num_measurements)+"_num_tableaus"+str(num_tableaus)+".pickle","wb") as f:
15+
pickle.dump(tableaus, f)
1116

1217
createanddumptableaus(5,3)
1318
createanddumptableaus(4,3)
1419
createanddumptableaus(3,2)
15-
20+
for num_qubits in range (0,8):
21+
for num_meas in range (1,num_qubits):
22+
for deg in range (1,num_qubits):
23+
createanddumptableaus(num_qubits,num_meas,degree=deg)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
for name in {"henon","logistic"}
4+
do
5+
for i in {1..6}
6+
do
7+
sbatch run_reservoir_degree.sh 7 6 20 quantum_stab None 4 1 $name $i fixed_stab 1 1000
8+
done
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
for name in {"henon","logistic"}
4+
do
5+
for i in {1..7}
6+
do
7+
sbatch run_reservoir.sh 7 $i 20 classical None 4 1 $name 1 random 1 1000
8+
sbatch run_reservoir.sh 7 $i 20 quantum_part None 4 1 $name 1 random 1 1000
9+
sbatch run_reservoir.sh 7 $i 20 quantum_stab None 4 1 $name 1 random 1 1000
10+
done
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
for name in {"henon","logistic"}
4+
do
5+
for i in {3..10}
6+
do
7+
sbatch run_reservoir.sh $i $(i-1) 20 classical None 4 1 $name 1 random 1 1000
8+
sbatch run_reservoir.sh $i $(i-1) 20 quantum_part None 4 1 $name 1 random 1 1000
9+
sbatch run_reservoir.sh $i $(i-1) 20 quantum_stab None 4 1 $name 1 random 1 1000
10+
done

0 commit comments

Comments
 (0)