Skip to content

Commit

Permalink
Fix tutorials to work with Qiskit 1.0 (#1336) (#1337)
Browse files Browse the repository at this point in the history
* Fix tutorials to work with Qiskit 1.0

* Fix tutorials to work with Qiskit 1.0

* Fix import that was removed

* Fix method that was removed

(cherry picked from commit ae834de)

Co-authored-by: Steve Wood <[email protected]>
  • Loading branch information
mergify[bot] and woodsp-ibm authored Feb 19, 2024
1 parent a648b71 commit 5608a29
Show file tree
Hide file tree
Showing 14 changed files with 116 additions and 528 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/deploy-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ jobs:
QISKIT_DOCS_BUILD_TUTORIALS: 'always'
run: |
echo "earliest_version: 0.1.0" >> releasenotes/config.yaml
# disable a PySCF UserWarning w.r.t. a change in the B3LYP DFT functional
echo "B3LYP_WITH_VWN5 = True" >> ~/.pyscf_conf.py
tools/ignore_untagged_notes.sh
make html
shell: bash
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/01_electronic_structure.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@
}
],
"source": [
"import qiskit.tools.jupyter\n",
"import tutorial_magics\n",
"\n",
"%qiskit_version_table\n",
"%qiskit_copyright"
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/02_vibrational_structure.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@
}
],
"source": [
"import qiskit.tools.jupyter\n",
"import tutorial_magics\n",
"\n",
"%qiskit_version_table\n",
"%qiskit_copyright"
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/03_ground_state_solvers.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@
}
],
"source": [
"import qiskit.tools.jupyter\n",
"import tutorial_magics\n",
"\n",
"%qiskit_version_table\n",
"%qiskit_copyright"
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/04_excited_states_solvers.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@
}
],
"source": [
"import qiskit.tools.jupyter\n",
"import tutorial_magics\n",
"\n",
"%qiskit_version_table\n",
"%qiskit_copyright"
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/05_problem_transformers.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@
}
],
"source": [
"import qiskit.tools.jupyter\n",
"import tutorial_magics\n",
"\n",
"%qiskit_version_table\n",
"%qiskit_copyright"
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/06_qubit_mappers.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@
}
],
"source": [
"import qiskit.tools.jupyter\n",
"import tutorial_magics\n",
"\n",
"%qiskit_version_table\n",
"%qiskit_copyright"
Expand Down
510 changes: 0 additions & 510 deletions docs/tutorials/07_leveraging_qiskit_runtime.ipynb

This file was deleted.

2 changes: 1 addition & 1 deletion docs/tutorials/08_qcschema.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@
}
],
"source": [
"import qiskit.tools.jupyter\n",
"import tutorial_magics\n",
"\n",
"%qiskit_version_table\n",
"%qiskit_copyright"
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/09_properties.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@
}
],
"source": [
"import qiskit.tools.jupyter\n",
"import tutorial_magics\n",
"\n",
"%qiskit_version_table\n",
"%qiskit_copyright"
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/10_lattice_models.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,7 @@
}
],
"source": [
"import qiskit.tools.jupyter\n",
"import tutorial_magics\n",
"\n",
"%qiskit_version_table\n",
"%qiskit_copyright"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@
}
],
"source": [
"import qiskit.tools.jupyter\n",
"import tutorial_magics\n",
"\n",
"%qiskit_version_table\n",
"%qiskit_copyright"
Expand Down
16 changes: 8 additions & 8 deletions docs/tutorials/12_deuteron_binding_energy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
"from qiskit_algorithms import VQE\n",
"from qiskit_algorithms.observables_evaluator import estimate_observables\n",
"from qiskit_algorithms.optimizers import COBYLA, SLSQP\n",
"from qiskit_algorithms.utils import algorithm_globals\n",
"from qiskit.circuit import QuantumCircuit, Parameter\n",
"from qiskit.circuit.library import TwoLocal\n",
"from qiskit.quantum_info import Pauli, SparsePauliOp\n",
"from qiskit.utils import algorithm_globals\n",
"from qiskit_nature.second_q.operators import FermionicOp\n",
"from qiskit_nature.second_q.mappers import JordanWignerMapper"
]
Expand Down Expand Up @@ -781,7 +781,7 @@
" to know the expectation values.\n",
"\n",
" angles (list): A list with the values that will be used in the\n",
" 'bind_parameters' method.\n",
" 'assign_parameters' method.\n",
"\n",
" Returns:\n",
" list_exp_values (list): A list containing the expectation values\n",
Expand All @@ -791,7 +791,7 @@
" for observable in observables:\n",
" exp_values = []\n",
" for angle in angles:\n",
" qc = quantum_circuit.bind_parameters({theta: angle})\n",
" qc = quantum_circuit.assign_parameters({theta: angle})\n",
" result = estimate_observables(\n",
" Estimator(),\n",
" quantum_state=qc,\n",
Expand Down Expand Up @@ -909,7 +909,7 @@
"id": "738bb6e0",
"metadata": {},
"source": [
"# Acknowledgment\n",
"## Acknowledgment\n",
"\n",
"I would like to thank Steve Wood, Soham Pal and Siddhartha Morales for the debates in our meetings during the Qiskit Advocate Mentorship Program 2021 - Fall, they were very important for the construction of this tutorial. "
]
Expand All @@ -919,7 +919,7 @@
"id": "711a7f4c",
"metadata": {},
"source": [
"# References\n",
"## References\n",
"\n",
"[1] Dumitrescu, Eugene F., et al. \"Cloud quantum computing of an atomic nucleus.\" Physical review letters 120.21 (2018): 210501. Arxiv version: https://arxiv.org/pdf/1801.03897.pdf\n",
"\n",
Expand Down Expand Up @@ -962,7 +962,7 @@
}
],
"source": [
"import qiskit.tools.jupyter\n",
"import tutorial_magics\n",
"\n",
"%qiskit_version_table\n",
"%qiskit_copyright"
Expand All @@ -971,7 +971,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -985,7 +985,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.16"
"version": "3.9.7"
},
"vscode": {
"interpreter": {
Expand Down
96 changes: 96 additions & 0 deletions docs/tutorials/tutorial_magics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# This code is part of a Qiskit project
#
# (C) Copyright IBM 2017, 2024
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.
# pylint: disable=unused-argument

"""A module for version and copyright magics."""

import datetime
import platform
import time
from sys import modules

from IPython import get_ipython
from IPython.core.magic import line_magic, Magics, magics_class
from IPython.display import HTML, display

import qiskit


@magics_class
class Copyright(Magics):
"""A class of status magic functions."""

@line_magic
def qiskit_copyright(self, line="", cell=None):
"""A Jupyter magic function return qiskit copyright"""
now = datetime.datetime.now()

html = "<div style='width: 100%; background-color:#d5d9e0;"
html += "padding-left: 10px; padding-bottom: 10px; padding-right: 10px; padding-top: 5px'>"
html += "<h3>This code is a part of a Qiskit project</h3>"
html += "<p>&copy; Copyright IBM 2017, %s.</p>" % now.year
html += "<p>This code is licensed under the Apache License, Version 2.0. You may<br>"
html += "obtain a copy of this license in the LICENSE.txt file in the root directory<br> "
html += "of this source tree or at http://www.apache.org/licenses/LICENSE-2.0."

html += "<p>Any modifications or derivative works of this code must retain this<br>"
html += "copyright notice, and modified files need to carry a notice indicating<br>"
html += "that they have been altered from the originals.</p>"
html += "</div>"
return display(HTML(html))


@magics_class
class VersionTable(Magics):
"""A class of status magic functions."""

@line_magic
def qiskit_version_table(self, line="", cell=None):
"""
Print an HTML-formatted table with version numbers for Qiskit and its
dependencies. This should make it possible to reproduce the environment
and the calculation later on.
"""
html = "<h3>Version Information</h3>"
html += "<table>"
html += "<tr><th>Software</th><th>Version</th></tr>"

packages = {"qiskit": qiskit.__version__}
qiskit_modules = {module.split(".")[0] for module in modules.keys() if "qiskit" in module}

for qiskit_module in qiskit_modules:
packages[qiskit_module] = getattr(modules[qiskit_module], "__version__", None)

for name, version in packages.items():
if version:
html += f"<tr><td><code>{name}</code></td><td>{version}</td></tr>"

html += "<tr><th colspan='2'>System information</th></tr>"

sys_info = [
("Python version", platform.python_version()),
("OS", "%s" % platform.system()),
]

for name, version in sys_info:
html += f"<tr><td>{name}</td><td>{version}</td></tr>"

html += "<tr><td colspan='2'>%s</td></tr>" % time.strftime("%a %b %d %H:%M:%S %Y %Z")
html += "</table>"

return display(HTML(html))


_IP = get_ipython()
if _IP is not None:
_IP.register_magics(VersionTable)
_IP.register_magics(Copyright)

0 comments on commit 5608a29

Please sign in to comment.