Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tutorials to work with Qiskit 1.0 #156

Merged
merged 7 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)