Source code for qiskit_metal.toolbox_metal.about
# This code is part of Qiskit.
#
# (C) Copyright IBM 2017, 2021.
#
# 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.
"""Reports a summary of information on Qiskit Metal and dependencies.
Contain functions to report more detailed information to orient a user,
used for debug purposes.
"""
import inspect
import os
import platform
import sys
import webbrowser
from pathlib import Path
from typing import Union
import numpy
import qutip
from qiskit_metal.toolbox_python.display import Color, style_colon_list
__all__ = ["about", "open_docs", "get_platform_info", "get_module_doc_page"]
[docs]
def about():
"""Reports a summary of information on Qiskit Metal and dependencies.
Returns:
str: About message
"""
import qiskit_metal
# PySide6 is an optional extra (``quantum-metal[gui]``) — the lite
# install path omits it, so about() must not require it.
try:
from PySide6 import __version__ as PYSIDE_VERSION_STR
from PySide6.QtCore import __version__ as QT_VERSION_STR
except ImportError:
QT_VERSION_STR = "Not installed"
PYSIDE_VERSION_STR = "Not installed"
import matplotlib
try:
from sip import SIP_VERSION_STR
except ImportError:
SIP_VERSION_STR = "Not installed"
# Riverbank: SIP is a tool for quickly writing Python modules that interface with
# C++ and C libraries.
text = f"""
Qiskit Metal {qiskit_metal.__version__}
Basic
____________________________________
Python {sys.version}
Platform {platform.system()} {platform.machine()}
Installation path {os.path.dirname(inspect.getsourcefile(qiskit_metal))}
Packages
____________________________________
Numpy {numpy.__version__}
Qutip {qutip.__version__}
Rendering
____________________________________
Matplotlib {matplotlib.__version__}
GUI
____________________________________
PySide6 version {PYSIDE_VERSION_STR}
Qt version {QT_VERSION_STR}
SIP version {SIP_VERSION_STR}
IBM Quantum Team"""
print(text)
return text
######################################################################################
# DOCS
[docs]
def get_module_doc_page(module, folder=r"../docs/build/html", page="index.html"):
"""Get the file path to a module doc folder assumed to be inside the
package."""
return Path(os.path.dirname(module.__file__)) / folder / page
[docs]
def open_docs(page="https://qiskit-community.github.io/qiskit-metal/"):
"""Open the qiskit_metal documentation in HTML.
Open the URL in new window, raising the window if possible.
"""
webbrowser.open(page, new=1)
######################################################################################
# More detailed information to orient a user.
# For debug purposes.
# Main function: ``orient_me```
# def orient_me(do_print: bool = True) -> Union[None, str]:
"""Full system, python, user, and environemnt information.
Args:
do_print(bool): Return the string if True, else format and print.
"""
# text = get_platform_info()
# text += \
# f" User and directories:\n\n"\
# f" User : {getpass.getuser()}\n"\
# f" User home dirctry : {Path.home()}\n"\
# f" Current directory : {Path.cwd()}\n\n"\
# f" Conda default env : {os.environ.get('CONDA_DEFAULT_ENV', 'N/A')}\n"\
# f" Conda current env : {os.environ.get('CONDA_PREFIX', 'N/A')}\n"\
# f" Python executable : {sys.executable}\n"\
# if do_print:
# text = style_colon_list(text, Color.BOLD, Color.END)
# print(text)
# return None
# return text