Skip to content
Closed
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
2 changes: 1 addition & 1 deletion qiskit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@
from qiskit.providers.ibmq import IBMQ
except ImportError:
pass

from ._util import about
from .version import __version__
64 changes: 63 additions & 1 deletion qiskit/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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__)
Copy link
Copy Markdown
Member

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)?

Copy link
Copy Markdown
Contributor Author

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.

Copy link
Copy Markdown
Contributor Author

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, ply are probably not as important as the more 'core' packages above.

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():
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would only return providers that are within the qiskit.providers namespace, which currently is only BasicAer, Aer, and IBMQ i think.
For example, this 3rd party provider will not be returned?
https://github.com/Qiskit/qiskit-jku-provider

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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 qiskit.providers

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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 BaseProvider in them. But that seems less than ideal. There is a PR on provider registration #1465, and this could easily be modified to deal with that case when it comes.

"""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