-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Add 'about' function giving information on local installation. #1840
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,11 +10,19 @@ | |
| import platform | ||
| import re | ||
| import socket | ||
| import os | ||
| import sys | ||
| import warnings | ||
|
|
||
| import inspect | ||
| import pkgutil | ||
| import importlib | ||
| from math import log2 | ||
| import psutil | ||
| import numpy | ||
| import scipy | ||
| import networkx as nx | ||
| from marshmallow.warnings import ChangedInMarshmallow3Warning | ||
| import qiskit.providers | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
@@ -97,3 +105,57 @@ def _has_connection(hostname, port): | |
| return True | ||
| except Exception: # pylint: disable=broad-except | ||
| return False | ||
|
|
||
|
|
||
| def about(): | ||
| """ Returns information about the Qiskit installation. | ||
| """ | ||
| hardware_info = local_hardware_info() | ||
| n_qubits = int(log2(local_hardware_info()['memory']*(1024**3)/16)) | ||
|
|
||
| print("") | ||
| print("Qiskit Details") | ||
| print("==============") | ||
| print("Package Version Number") | ||
| print("------------------------------") | ||
| print("Qiskit-terra: %s" % qiskit.__version__) | ||
| print("Numpy: %s" % numpy.__version__) | ||
| print("Scipy: %s" % scipy.__version__) | ||
| print("Networkx: %s" % nx.__version__) | ||
| print("Python: %d.%d.%d" % sys.version_info[0:3]) | ||
| print("") | ||
| print("Available Providers") | ||
| print("-------------------") | ||
| offset = 20 | ||
| for pro in get_available_providers(): | ||
| print(pro[0]+' '*(offset-len(pro[0]))+(pro[1] if pro[1] else '')) | ||
|
|
||
| print("") | ||
| print("Additional Information") | ||
| print("----------------------") | ||
| print("Memory: %s GB [%s qubits]" % (hardware_info['memory'], n_qubits)) | ||
| print("Number of CPUs: %s" % hardware_info['cpus']) | ||
| print("Platform Info: %s (%s)" % (platform.system(), | ||
| platform.machine())) | ||
| qiskit_install_path = os.path.dirname(inspect.getsourcefile(qiskit)) | ||
| print("Install path: %s" % qiskit_install_path) | ||
|
|
||
|
|
||
| def get_available_providers(): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would only return providers that are within the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This actually is a good match up with #1465 which will add a discovery mechanism for this and populate the providers off of
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, I am not sure how to handle providers that do not inject themselves into qiskit, but rather must be imported. One could imagine that you could look for all packages with instances of |
||
| """Returns a list of available providers and their | ||
| versioning (if any). | ||
|
|
||
| Returns: | ||
| list: List of (provider_name, version) tuples. | ||
| """ | ||
| package = qiskit.providers | ||
| providers = [] | ||
| for _, modname, ispkg in pkgutil.iter_modules(package.__path__): | ||
| if ispkg and modname != 'models': | ||
| mod = importlib.import_module("qiskit.providers."+modname) | ||
| try: | ||
| version = mod.__version__ | ||
| except AttributeError: | ||
| version = None | ||
| providers.append((modname, version)) | ||
| return providers | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rather than hardcoding these, why not get them from requirements.txt?
because say we remove networkx in the future, someone then has to remember to update this.
Also, do the versions of dependencies make a difference to the user experience (assuming they meet the minimum requirement)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are not hardcoded but grabbed from the modules. These numbers are likely not the minimum values given in the requirements.txt.
If people remove packages, then of course you need to update stuff. That would be a one-line change. If I include a test, then in your situation, the test would fail telling people to remove the code in question.
So they could. What it does help is with bug reporting. It could be that new versions cause trouble, or version mismatches, and this info can be included in a bug report. Basically the "Information" section that the top of our bug reports could be replace with just the return from this function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see what your saying. Because I do not want to list all the requirements.
psutil,plyare probably not as important as the more 'core' packages above.