Skip to content
This repository was archived by the owner on Aug 21, 2023. It is now read-only.

Commit 4240f90

Browse files
authored
Merge pull request #720 from Qiskit/quantumjim-patch-1
Add process fidelity
2 parents f210396 + 9f7ecab commit 4240f90

1 file changed

Lines changed: 73 additions & 56 deletions

File tree

qiskit/ignis/process_tomography.ipynb

Lines changed: 73 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"source": [
1414
"# Quantum Process Tomography\n",
1515
"\n",
16-
"* **Last Updated:** April 29, 2019\n",
16+
"* **Last Updated:** June 17, 2019\n",
1717
"* **Requires:** qiskit-terra 0.8, qiskit-ignis 0.1.1, qiskit-aer 0.2"
1818
]
1919
},
@@ -37,7 +37,7 @@
3737
"# Import QISKit classes\n",
3838
"import qiskit\n",
3939
"from qiskit import QuantumRegister, QuantumCircuit, Aer\n",
40-
"from qiskit.quantum_info import state_fidelity\n",
40+
"from qiskit.quantum_info import state_fidelity, process_fidelity\n",
4141
"from qiskit.tools.qi.qi import outer\n",
4242
"\n",
4343
"# Tomography functions\n",
@@ -60,17 +60,17 @@
6060
"data": {
6161
"text/plain": [
6262
"{(('Zp',), ('X',)): {'0': 4000},\n",
63-
" (('Zp',), ('Y',)): {'0': 1980, '1': 2020},\n",
64-
" (('Zp',), ('Z',)): {'0': 2053, '1': 1947},\n",
63+
" (('Zp',), ('Y',)): {'0': 2033, '1': 1967},\n",
64+
" (('Zp',), ('Z',)): {'0': 1985, '1': 2015},\n",
6565
" (('Zm',), ('X',)): {'1': 4000},\n",
66-
" (('Zm',), ('Y',)): {'0': 2064, '1': 1936},\n",
67-
" (('Zm',), ('Z',)): {'0': 2018, '1': 1982},\n",
68-
" (('Xp',), ('X',)): {'0': 1982, '1': 2018},\n",
69-
" (('Xp',), ('Y',)): {'0': 2023, '1': 1977},\n",
66+
" (('Zm',), ('Y',)): {'0': 1959, '1': 2041},\n",
67+
" (('Zm',), ('Z',)): {'0': 2026, '1': 1974},\n",
68+
" (('Xp',), ('X',)): {'0': 2030, '1': 1970},\n",
69+
" (('Xp',), ('Y',)): {'0': 1993, '1': 2007},\n",
7070
" (('Xp',), ('Z',)): {'0': 4000},\n",
71-
" (('Yp',), ('X',)): {'0': 1944, '1': 2056},\n",
71+
" (('Yp',), ('X',)): {'0': 2040, '1': 1960},\n",
7272
" (('Yp',), ('Y',)): {'1': 4000},\n",
73-
" (('Yp',), ('Z',)): {'0': 1986, '1': 2014}}"
73+
" (('Yp',), ('Z',)): {'0': 1979, '1': 2021}}"
7474
]
7575
},
7676
"execution_count": 2,
@@ -109,12 +109,14 @@
109109
"output_type": "stream",
110110
"text": [
111111
"Least-Sq Fitter\n",
112-
"fit time: 0.025106191635131836\n",
113-
"fit fidelity: 0.9935435801308409\n",
112+
"fit time: 0.009121894836425781\n",
113+
"fit fidelity (state): 0.9976767994222256\n",
114+
"fit fidelity (process): 0.995358994837865\n",
114115
"\n",
115116
"CVXOPT Fitter\n",
116-
"fit time: 0.14531993865966797\n",
117-
"fit fidelity: 0.9999047428166897\n"
117+
"fit time: 0.05771899223327637\n",
118+
"fit fidelity (state): 0.9999108703920029\n",
119+
"fit fidelity (process): 0.9998217487227923\n"
118120
]
119121
}
120122
],
@@ -124,14 +126,17 @@
124126
"choi_lstsq = qpt_tomo.fit(method='lstsq')\n",
125127
"print('Least-Sq Fitter')\n",
126128
"print('fit time:', time.time() - t)\n",
127-
"print('fit fidelity:', state_fidelity(choi_ideal / 2, choi_lstsq.data / 2))\n",
129+
"print('fit fidelity (state):', state_fidelity(choi_ideal / 2, choi_lstsq.data / 2))\n",
130+
"print('fit fidelity (process):', np.real(process_fidelity(choi_ideal, choi_lstsq.data, require_cptp=False)))\n",
131+
"\n",
128132
"\n",
129133
"# CVXOPT Semidefinite-Program tomographic reconstruction\n",
130134
"t = time.time()\n",
131135
"choi_cvx = qpt_tomo.fit(method='cvx')\n",
132136
"print('\\nCVXOPT Fitter')\n",
133137
"print('fit time:', time.time() - t)\n",
134-
"print('fit fidelity:', state_fidelity(choi_ideal / 2, choi_cvx.data / 2))"
138+
"print('fit fidelity (state):', state_fidelity(choi_ideal / 2, choi_cvx.data / 2))\n",
139+
"print('fit fidelity (process):', np.real(process_fidelity(choi_ideal, choi_cvx.data, require_cptp=False)))\n"
135140
]
136141
},
137142
{
@@ -151,18 +156,18 @@
151156
{
152157
"data": {
153158
"text/plain": [
154-
"{(('Zp',), ('X',)): {'0': 985, '1': 1015},\n",
155-
" (('Zp',), ('Y',)): {'0': 1029, '1': 971},\n",
159+
"{(('Zp',), ('X',)): {'0': 1007, '1': 993},\n",
160+
" (('Zp',), ('Y',)): {'0': 962, '1': 1038},\n",
156161
" (('Zp',), ('Z',)): {'0': 2000},\n",
157-
" (('Zm',), ('X',)): {'0': 981, '1': 1019},\n",
158-
" (('Zm',), ('Y',)): {'0': 1016, '1': 984},\n",
162+
" (('Zm',), ('X',)): {'0': 1059, '1': 941},\n",
163+
" (('Zm',), ('Y',)): {'0': 1000, '1': 1000},\n",
159164
" (('Zm',), ('Z',)): {'1': 2000},\n",
160165
" (('Xp',), ('X',)): {'0': 2000},\n",
161-
" (('Xp',), ('Y',)): {'0': 955, '1': 1045},\n",
162-
" (('Xp',), ('Z',)): {'0': 958, '1': 1042},\n",
163-
" (('Yp',), ('X',)): {'0': 989, '1': 1011},\n",
166+
" (('Xp',), ('Y',)): {'0': 1010, '1': 990},\n",
167+
" (('Xp',), ('Z',)): {'0': 995, '1': 1005},\n",
168+
" (('Yp',), ('X',)): {'0': 1003, '1': 997},\n",
164169
" (('Yp',), ('Y',)): {'0': 2000},\n",
165-
" (('Yp',), ('Z',)): {'0': 1003, '1': 997}}"
170+
" (('Yp',), ('Z',)): {'0': 978, '1': 1022}}"
166171
]
167172
},
168173
"execution_count": 4,
@@ -200,12 +205,14 @@
200205
"output_type": "stream",
201206
"text": [
202207
"Least-Sq Fitter\n",
203-
"fit time: 0.009311914443969727\n",
204-
"fit fidelity: 0.9874012369433787\n",
208+
"fit time: 0.006497859954833984\n",
209+
"fit fidelity (state): 0.9866920175150853\n",
210+
"fit fidelity (process): 0.9735611374279911\n",
205211
"\n",
206212
"CVXOPT Fitter\n",
207-
"fit time: 0.06017184257507324\n",
208-
"fit fidelity: 0.9998944136683781\n"
213+
"fit time: 0.04198098182678223\n",
214+
"fit fidelity (state): 0.999940174723841\n",
215+
"fit fidelity (process): 0.9998803530267468\n"
209216
]
210217
}
211218
],
@@ -215,14 +222,16 @@
215222
"choi_lstsq = qpt_tomo.fit(method='lstsq')\n",
216223
"print('Least-Sq Fitter')\n",
217224
"print('fit time:', time.time() - t)\n",
218-
"print('fit fidelity:', state_fidelity(choi_ideal / 2, choi_lstsq.data / 2))\n",
225+
"print('fit fidelity (state):', state_fidelity(choi_ideal / 2, choi_lstsq.data / 2))\n",
226+
"print('fit fidelity (process):', np.real(process_fidelity(choi_ideal, choi_lstsq.data, require_cptp=False)))\n",
219227
"\n",
220228
"# CVXOPT Semidefinite-Program tomographic reconstruction\n",
221229
"t = time.time()\n",
222230
"choi_cvx = qpt_tomo.fit(method='cvx')\n",
223231
"print('\\nCVXOPT Fitter')\n",
224232
"print('fit time:', time.time() - t)\n",
225-
"print('fit fidelity:', state_fidelity(choi_ideal / 2, choi_cvx.data / 2))"
233+
"print('fit fidelity (state):', state_fidelity(choi_ideal / 2, choi_cvx.data / 2))\n",
234+
"print('fit fidelity (process):', np.real(process_fidelity(choi_ideal, choi_cvx.data, require_cptp=False)))"
226235
]
227236
},
228237
{
@@ -242,12 +251,14 @@
242251
"output_type": "stream",
243252
"text": [
244253
"Least-Sq Fitter\n",
245-
"fit time: 0.14422106742858887\n",
246-
"fit fidelity: 0.984365187084024\n",
254+
"fit time: 0.1802959442138672\n",
255+
"fit fidelity (state): 0.9842194915019892\n",
256+
"fit fidelity (process): 0.9686880063880137\n",
247257
"\n",
248258
"CVXOPT Fitter\n",
249-
"fit time: 1.1474080085754395\n",
250-
"fit fidelity: 0.9998986962593072\n"
259+
"fit time: 1.1846849918365479\n",
260+
"fit fidelity (state): 0.9999324749848556\n",
261+
"fit fidelity (process): 0.9998649545043932\n"
251262
]
252263
}
253264
],
@@ -275,13 +286,15 @@
275286
"choi_lstsq = qpt_tomo.fit(method='lstsq')\n",
276287
"print('Least-Sq Fitter')\n",
277288
"print('fit time:', time.time() - t)\n",
278-
"print('fit fidelity:', state_fidelity(choi_ideal / 4, choi_lstsq.data / 4))\n",
289+
"print('fit fidelity (state):', state_fidelity(choi_ideal / 4, choi_lstsq.data / 4))\n",
290+
"print('fit fidelity (process):', np.real(process_fidelity(choi_ideal, choi_lstsq.data, require_cptp=False)))\n",
279291
"\n",
280292
"t = time.time()\n",
281293
"choi_cvx = qpt_tomo.fit(method='cvx')\n",
282294
"print('\\nCVXOPT Fitter')\n",
283295
"print('fit time:', time.time() - t)\n",
284-
"print('fit fidelity:', state_fidelity(choi_ideal / 4, choi_cvx.data / 4))"
296+
"print('fit fidelity (state):', state_fidelity(choi_ideal / 4, choi_cvx.data / 4))\n",
297+
"print('fit fidelity (process):', np.real(process_fidelity(choi_ideal, choi_cvx.data, require_cptp=False)))"
285298
]
286299
},
287300
{
@@ -300,17 +313,17 @@
300313
"data": {
301314
"text/plain": [
302315
"{(('S0',), ('X',)): {'0': 2000},\n",
303-
" (('S0',), ('Y',)): {'0': 995, '1': 1005},\n",
304-
" (('S0',), ('Z',)): {'0': 1027, '1': 973},\n",
305-
" (('S1',), ('X',)): {'0': 682, '1': 1318},\n",
306-
" (('S1',), ('Y',)): {'0': 1049, '1': 951},\n",
307-
" (('S1',), ('Z',)): {'0': 1952, '1': 48},\n",
308-
" (('S2',), ('X',)): {'0': 674, '1': 1326},\n",
309-
" (('S2',), ('Y',)): {'0': 1832, '1': 168},\n",
310-
" (('S2',), ('Z',)): {'0': 504, '1': 1496},\n",
311-
" (('S3',), ('X',)): {'0': 683, '1': 1317},\n",
312-
" (('S3',), ('Y',)): {'0': 182, '1': 1818},\n",
313-
" (('S3',), ('Z',)): {'0': 512, '1': 1488}}"
316+
" (('S0',), ('Y',)): {'0': 999, '1': 1001},\n",
317+
" (('S0',), ('Z',)): {'0': 1013, '1': 987},\n",
318+
" (('S1',), ('X',)): {'0': 713, '1': 1287},\n",
319+
" (('S1',), ('Y',)): {'0': 977, '1': 1023},\n",
320+
" (('S1',), ('Z',)): {'0': 1938, '1': 62},\n",
321+
" (('S2',), ('X',)): {'0': 665, '1': 1335},\n",
322+
" (('S2',), ('Y',)): {'0': 1828, '1': 172},\n",
323+
" (('S2',), ('Z',)): {'0': 543, '1': 1457},\n",
324+
" (('S3',), ('X',)): {'0': 645, '1': 1355},\n",
325+
" (('S3',), ('Y',)): {'0': 206, '1': 1794},\n",
326+
" (('S3',), ('Z',)): {'0': 507, '1': 1493}}"
314327
]
315328
},
316329
"execution_count": 7,
@@ -349,12 +362,14 @@
349362
"output_type": "stream",
350363
"text": [
351364
"Least-Sq Fitter\n",
352-
"fit time: 0.008871316909790039\n",
353-
"fit fidelity: 0.9969739538161556\n",
365+
"fit time: 0.007508039474487305\n",
366+
"fit fidelity (state): 0.9906085840000641\n",
367+
"fit fidelity (process): 0.9813053636480525\n",
354368
"\n",
355369
"CVXOPT Fitter\n",
356-
"fit time: 0.0575709342956543\n",
357-
"fit fidelity: 0.9995559180011946\n"
370+
"fit time: 0.04143118858337402\n",
371+
"fit fidelity (state): 0.9958380801102131\n",
372+
"fit fidelity (process): 0.9916934801256183\n"
358373
]
359374
}
360375
],
@@ -364,23 +379,25 @@
364379
"choi_lstsq = qpt_tomo.fit(method='lstsq')\n",
365380
"print('Least-Sq Fitter')\n",
366381
"print('fit time:', time.time() - t)\n",
367-
"print('fit fidelity:', state_fidelity(choi_ideal / 2, choi_lstsq.data / 2))\n",
382+
"print('fit fidelity (state):', state_fidelity(choi_ideal / 2, choi_lstsq.data / 2))\n",
383+
"print('fit fidelity (process):', np.real(process_fidelity(choi_ideal, choi_lstsq.data, require_cptp=False)))\n",
368384
"\n",
369385
"# CVXOPT Semidefinite-Program tomographic reconstruction\n",
370386
"t = time.time()\n",
371387
"choi_cvx = qpt_tomo.fit(method='cvx')\n",
372388
"\n",
373389
"print('\\nCVXOPT Fitter')\n",
374390
"print('fit time:', time.time() - t)\n",
375-
"print('fit fidelity:', state_fidelity(choi_ideal / 2, choi_cvx.data / 2))"
391+
"print('fit fidelity (state):', state_fidelity(choi_ideal / 2, choi_cvx.data / 2))\n",
392+
"print('fit fidelity (process):', np.real(process_fidelity(choi_ideal, choi_cvx.data, require_cptp=False)))"
376393
]
377394
}
378395
],
379396
"metadata": {
380397
"kernelspec": {
381-
"display_name": "Python 3",
398+
"display_name": "stable",
382399
"language": "python",
383-
"name": "python3"
400+
"name": "stable"
384401
},
385402
"language_info": {
386403
"codemirror_mode": {
@@ -392,7 +409,7 @@
392409
"name": "python",
393410
"nbconvert_exporter": "python",
394411
"pygments_lexer": "ipython3",
395-
"version": "3.6.8"
412+
"version": "3.7.0"
396413
}
397414
},
398415
"nbformat": 4,

0 commit comments

Comments
 (0)