Skip to content

Commit 4a93f7d

Browse files
authored
Fix tutorials to work with Qiskit 1.0 (#331)
1 parent 5ca51fa commit 4a93f7d

13 files changed

+112
-16
lines changed

docs/tutorials/00_amplitude_estimation.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@
323323
"source": [
324324
"ae_circuit = ae.construct_circuit(problem)\n",
325325
"ae_circuit.decompose().draw(\n",
326-
" \"mpl\", style=\"iqx\"\n",
326+
" \"mpl\", style=\"clifford\"\n",
327327
") # decompose 1 level: exposes the Phase estimation circuit!"
328328
]
329329
},
@@ -349,7 +349,7 @@
349349
"\n",
350350
"\n",
351351
"basis_gates = [\"h\", \"ry\", \"cry\", \"cx\", \"ccx\", \"p\", \"cp\", \"x\", \"s\", \"sdg\", \"y\", \"t\", \"cz\"]\n",
352-
"transpile(ae_circuit, basis_gates=basis_gates, optimization_level=2).draw(\"mpl\", style=\"iqx\")"
352+
"transpile(ae_circuit, basis_gates=basis_gates, optimization_level=2).draw(\"mpl\", style=\"clifford\")"
353353
]
354354
},
355355
{
@@ -413,7 +413,7 @@
413413
],
414414
"source": [
415415
"iae_circuit = iae.construct_circuit(problem, k=3)\n",
416-
"iae_circuit.draw(\"mpl\", style=\"iqx\")"
416+
"iae_circuit.draw(\"mpl\", style=\"clifford\")"
417417
]
418418
},
419419
{
@@ -531,7 +531,7 @@
531531
}
532532
],
533533
"source": [
534-
"import qiskit.tools.jupyter\n",
534+
"import tutorial_magics\n",
535535
"\n",
536536
"%qiskit_version_table\n",
537537
"%qiskit_copyright"
@@ -547,7 +547,7 @@
547547
],
548548
"metadata": {
549549
"kernelspec": {
550-
"display_name": "Python 3",
550+
"display_name": "Python 3 (ipykernel)",
551551
"language": "python",
552552
"name": "python3"
553553
},

docs/tutorials/01_portfolio_optimization.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@
400400
}
401401
],
402402
"source": [
403-
"import qiskit.tools.jupyter\n",
403+
"import tutorial_magics\n",
404404
"\n",
405405
"%qiskit_version_table\n",
406406
"%qiskit_copyright"

docs/tutorials/02_portfolio_diversification.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@
787787
}
788788
],
789789
"source": [
790-
"import qiskit.tools.jupyter\n",
790+
"import tutorial_magics\n",
791791
"\n",
792792
"%qiskit_version_table\n",
793793
"%qiskit_copyright"

docs/tutorials/03_european_call_option_pricing.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@
739739
}
740740
],
741741
"source": [
742-
"import qiskit.tools.jupyter\n",
742+
"import tutorial_magics\n",
743743
"\n",
744744
"%qiskit_version_table\n",
745745
"%qiskit_copyright"

docs/tutorials/04_european_put_option_pricing.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@
497497
}
498498
],
499499
"source": [
500-
"import qiskit.tools.jupyter\n",
500+
"import tutorial_magics\n",
501501
"\n",
502502
"%qiskit_version_table\n",
503503
"%qiskit_copyright"

docs/tutorials/05_bull_spread_pricing.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@
447447
}
448448
],
449449
"source": [
450-
"import qiskit.tools.jupyter\n",
450+
"import tutorial_magics\n",
451451
"\n",
452452
"%qiskit_version_table\n",
453453
"%qiskit_copyright"

docs/tutorials/06_basket_option_pricing.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@
583583
}
584584
],
585585
"source": [
586-
"import qiskit.tools.jupyter\n",
586+
"import tutorial_magics\n",
587587
"\n",
588588
"%qiskit_version_table\n",
589589
"%qiskit_copyright"

docs/tutorials/07_asian_barrier_spread_pricing.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@
688688
}
689689
],
690690
"source": [
691-
"import qiskit.tools.jupyter\n",
691+
"import tutorial_magics\n",
692692
"\n",
693693
"%qiskit_version_table\n",
694694
"%qiskit_copyright"

docs/tutorials/08_fixed_income_pricing.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@
439439
}
440440
],
441441
"source": [
442-
"import qiskit.tools.jupyter\n",
442+
"import tutorial_magics\n",
443443
"\n",
444444
"%qiskit_version_table\n",
445445
"%qiskit_copyright"

docs/tutorials/09_credit_risk_analysis.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1272,7 +1272,7 @@
12721272
}
12731273
],
12741274
"source": [
1275-
"import qiskit.tools.jupyter\n",
1275+
"import tutorial_magics\n",
12761276
"\n",
12771277
"%qiskit_version_table\n",
12781278
"%qiskit_copyright"

docs/tutorials/10_qgan_option_pricing.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@
344344
}
345345
],
346346
"source": [
347-
"import qiskit.tools.jupyter\n",
347+
"import tutorial_magics\n",
348348
"\n",
349349
"%qiskit_version_table\n",
350350
"%qiskit_copyright"

docs/tutorials/11_time_series.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@
536536
}
537537
],
538538
"source": [
539-
"import qiskit.tools.jupyter\n",
539+
"import tutorial_magics\n",
540540
"\n",
541541
"%qiskit_version_table\n",
542542
"%qiskit_copyright"

docs/tutorials/tutorial_magics.py

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# This code is part of a Qiskit project
2+
#
3+
# (C) Copyright IBM 2017, 2024
4+
#
5+
# This code is licensed under the Apache License, Version 2.0. You may
6+
# obtain a copy of this license in the LICENSE.txt file in the root directory
7+
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
8+
#
9+
# Any modifications or derivative works of this code must retain this
10+
# copyright notice, and modified files need to carry a notice indicating
11+
# that they have been altered from the originals.
12+
# pylint: disable=unused-argument
13+
14+
"""A module for version and copyright magics."""
15+
16+
import datetime
17+
import platform
18+
import time
19+
from sys import modules
20+
21+
from IPython import get_ipython
22+
from IPython.core.magic import line_magic, Magics, magics_class
23+
from IPython.display import HTML, display
24+
25+
import qiskit
26+
27+
28+
@magics_class
29+
class Copyright(Magics):
30+
"""A class of status magic functions."""
31+
32+
@line_magic
33+
def qiskit_copyright(self, line="", cell=None):
34+
"""A Jupyter magic function return qiskit copyright"""
35+
now = datetime.datetime.now()
36+
37+
html = "<div style='width: 100%; background-color:#d5d9e0;"
38+
html += "padding-left: 10px; padding-bottom: 10px; padding-right: 10px; padding-top: 5px'>"
39+
html += "<h3>This code is a part of a Qiskit project</h3>"
40+
html += "<p>&copy; Copyright IBM 2017, %s.</p>" % now.year
41+
html += "<p>This code is licensed under the Apache License, Version 2.0. You may<br>"
42+
html += "obtain a copy of this license in the LICENSE.txt file in the root directory<br> "
43+
html += "of this source tree or at http://www.apache.org/licenses/LICENSE-2.0."
44+
45+
html += "<p>Any modifications or derivative works of this code must retain this<br>"
46+
html += "copyright notice, and modified files need to carry a notice indicating<br>"
47+
html += "that they have been altered from the originals.</p>"
48+
html += "</div>"
49+
return display(HTML(html))
50+
51+
52+
@magics_class
53+
class VersionTable(Magics):
54+
"""A class of status magic functions."""
55+
56+
@line_magic
57+
def qiskit_version_table(self, line="", cell=None):
58+
"""
59+
Print an HTML-formatted table with version numbers for Qiskit and its
60+
dependencies. This should make it possible to reproduce the environment
61+
and the calculation later on.
62+
"""
63+
html = "<h3>Version Information</h3>"
64+
html += "<table>"
65+
html += "<tr><th>Software</th><th>Version</th></tr>"
66+
67+
packages = {"qiskit": qiskit.__version__}
68+
qiskit_modules = {module.split(".")[0] for module in modules.keys() if "qiskit" in module}
69+
70+
for qiskit_module in qiskit_modules:
71+
packages[qiskit_module] = getattr(modules[qiskit_module], "__version__", None)
72+
73+
for name, version in packages.items():
74+
if version:
75+
html += f"<tr><td><code>{name}</code></td><td>{version}</td></tr>"
76+
77+
html += "<tr><th colspan='2'>System information</th></tr>"
78+
79+
sys_info = [
80+
("Python version", platform.python_version()),
81+
("OS", "%s" % platform.system()),
82+
]
83+
84+
for name, version in sys_info:
85+
html += f"<tr><td>{name}</td><td>{version}</td></tr>"
86+
87+
html += "<tr><td colspan='2'>%s</td></tr>" % time.strftime("%a %b %d %H:%M:%S %Y %Z")
88+
html += "</table>"
89+
90+
return display(HTML(html))
91+
92+
93+
_IP = get_ipython()
94+
if _IP is not None:
95+
_IP.register_magics(VersionTable)
96+
_IP.register_magics(Copyright)

0 commit comments

Comments
 (0)