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

Commit 7f5f3d5

Browse files
committed
Fix statevector snapshot access in MPS tutorial
The statevector snapshot tutorial access done in the MPS tutorials was relying on internal implementation details (inherited from marshmallow) for how it was accessing the statevector for printing. This causes an issue when qiskit 0.20.0 is used because there is no marshmallow anymore. Instead of relying on the nested internal object attr access that was used before this uses the supported data() method to return a dict of snapshots and pull the statevector from there. This should be support for all versions of qiskit-terra, not just <0.15.0 and is the documented method for retrieving snapshots. This is the last thing needed to unblock Qiskit/qiskit#998 and finally relaese qiskit 0.20.0.
1 parent 1115ef9 commit 7f5f3d5

1 file changed

Lines changed: 10 additions & 12 deletions

File tree

tutorials/simulators/7_matrix_product_state_method.ipynb

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
{
6666
"data": {
6767
"text/plain": [
68-
"{'00': 520, '11': 504}"
68+
"{'11': 532, '00': 492}"
6969
]
7070
},
7171
"execution_count": 1,
@@ -134,7 +134,7 @@
134134
{
135135
"data": {
136136
"text/plain": [
137-
"[[(0.7071067811865475+0j), 0j, 0j, (0.7071067811865475+0j)]]"
137+
"[(0.7071067811865475+0j), 0j, 0j, (0.7071067811865475+0j)]"
138138
]
139139
},
140140
"execution_count": 3,
@@ -154,11 +154,9 @@
154154
"# Execute\n",
155155
"job_sim = execute([circ], QasmSimulator(), backend_options=backend_opts_mps)\n",
156156
"result = job_sim.result()\n",
157-
"res = result.results\n",
158157
"\n",
159158
"#print the state vector\n",
160-
"statevector = res[0].data.snapshots.statevector\n",
161-
"statevector['my_sv']"
159+
"result.data()['snapshots']['statevector']['my_sv'][0]"
162160
]
163161
},
164162
{
@@ -174,7 +172,7 @@
174172
{
175173
"data": {
176174
"text/plain": [
177-
"{'00': 517, '11': 507}"
175+
"{'11': 516, '00': 508}"
178176
]
179177
},
180178
"execution_count": 4,
@@ -210,14 +208,14 @@
210208
"name": "stdout",
211209
"output_type": "stream",
212210
"text": [
213-
"Time taken: 2.162709951400757 sec\n"
211+
"Time taken: 0.677933931350708 sec\n"
214212
]
215213
},
216214
{
217215
"data": {
218216
"text/plain": [
219-
"{'11111111111111111111111111111111111111111111111111': 486,\n",
220-
" '00000000000000000000000000000000000000000000000000': 538}"
217+
"{'11111111111111111111111111111111111111111111111111': 543,\n",
218+
" '00000000000000000000000000000000000000000000000000': 481}"
221219
]
222220
},
223221
"execution_count": 5,
@@ -258,8 +256,8 @@
258256
{
259257
"data": {
260258
"text/html": [
261-
"<h3>Version Information</h3><table><tr><th>Qiskit Software</th><th>Version</th></tr><tr><td>Qiskit</td><td>None</td></tr><tr><td>Terra</td><td>0.14.0</td></tr><tr><td>Aer</td><td>0.6.0</td></tr><tr><td>Ignis</td><td>None</td></tr><tr><td>Aqua</td><td>None</td></tr><tr><td>IBM Q Provider</td><td>0.6.1</td></tr><tr><th>System information</th></tr><tr><td>Python</td><td>3.7.7 (default, Mar 26 2020, 10:32:53) \n",
262-
"[Clang 4.0.1 (tags/RELEASE_401/final)]</td></tr><tr><td>OS</td><td>Darwin</td></tr><tr><td>CPUs</td><td>4</td></tr><tr><td>Memory (Gb)</td><td>16.0</td></tr><tr><td colspan='2'>Tue Apr 28 13:43:42 2020 EDT</td></tr></table>"
259+
"<h3>Version Information</h3><table><tr><th>Qiskit Software</th><th>Version</th></tr><tr><td>Qiskit</td><td>0.19.6</td></tr><tr><td>Terra</td><td>0.14.2</td></tr><tr><td>Aer</td><td>0.5.2</td></tr><tr><td>Ignis</td><td>0.3.3</td></tr><tr><td>Aqua</td><td>0.7.3</td></tr><tr><td>IBM Q Provider</td><td>0.7.2</td></tr><tr><th>System information</th></tr><tr><td>Python</td><td>3.8.5 (default, Jul 27 2020, 08:42:51) \n",
260+
"[GCC 10.1.0]</td></tr><tr><td>OS</td><td>Linux</td></tr><tr><td>CPUs</td><td>32</td></tr><tr><td>Memory (Gb)</td><td>125.72603988647461</td></tr><tr><td colspan='2'>Mon Aug 10 13:36:15 2020 EDT</td></tr></table>"
263261
],
264262
"text/plain": [
265263
"<IPython.core.display.HTML object>"
@@ -311,7 +309,7 @@
311309
"name": "python",
312310
"nbconvert_exporter": "python",
313311
"pygments_lexer": "ipython3",
314-
"version": "3.7.7"
312+
"version": "3.8.5"
315313
},
316314
"varInspector": {
317315
"cols": {

0 commit comments

Comments
 (0)