Skip to content

Commit

Permalink
Fix tutorials to work with Qiskit 1.0 (#156)
Browse files Browse the repository at this point in the history
Co-authored-by: Elena Peña Tapia <[email protected]>
  • Loading branch information
woodsp-ibm and ElePT authored Feb 19, 2024
1 parent 0ec3805 commit e0c050c
Show file tree
Hide file tree
Showing 13 changed files with 664 additions and 601 deletions.
1 change: 1 addition & 0 deletions .pylintdict
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ veeravalli
vec
vectorized
vicentini
vigo
ville
voilà
vqd
Expand Down
82 changes: 41 additions & 41 deletions docs/tutorials/01_algorithms_introduction.ipynb

Large diffs are not rendered by default.

91 changes: 49 additions & 42 deletions docs/tutorials/02_vqe_advanced_options.ipynb

Large diffs are not rendered by default.

56 changes: 24 additions & 32 deletions docs/tutorials/03_vqe_simulation_with_noise.ipynb

Large diffs are not rendered by default.

26 changes: 12 additions & 14 deletions docs/tutorials/04_vqd.ipynb

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions docs/tutorials/05_qaoa.ipynb

Large diffs are not rendered by default.

38 changes: 19 additions & 19 deletions docs/tutorials/06_grover.ipynb

Large diffs are not rendered by default.

60 changes: 23 additions & 37 deletions docs/tutorials/07_grover_examples.ipynb

Large diffs are not rendered by default.

656 changes: 324 additions & 332 deletions docs/tutorials/10_pvqd.ipynb

Large diffs are not rendered by default.

68 changes: 28 additions & 40 deletions docs/tutorials/11_VarQTE.ipynb

Large diffs are not rendered by default.

33 changes: 18 additions & 15 deletions docs/tutorials/12_gradients_framework.ipynb

Large diffs are not rendered by default.

38 changes: 19 additions & 19 deletions docs/tutorials/13_trotterQRTE.ipynb

Large diffs are not rendered by default.

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 e0c050c

Please sign in to comment.