Skip to content

Commit

Permalink
correct for sims
Browse files Browse the repository at this point in the history
  • Loading branch information
nonhermitian committed Sep 21, 2024
1 parent 80eefb7 commit 1593eb1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 22 deletions.
31 changes: 10 additions & 21 deletions mthree/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"""
Helper functions
"""
from qiskit.providers import BackendV1, BackendV2
from qiskit.providers import BackendV2
from qiskit_ibm_runtime import IBMBackend
from mthree.exceptions import M3Error


Expand All @@ -28,28 +29,16 @@ def system_info(backend):
"""
info_dict = {}
info_dict["inoperable_qubits"] = []
if isinstance(backend, BackendV1):
config = backend.configuration()
info_dict["name"] = backend.name()
info_dict["num_qubits"] = config.num_qubits
info_dict["max_shots"] = config.max_shots
info_dict["simulator"] = config.simulator
# A hack for Qiskit/Terra #9572
if "fake" in info_dict["name"]:
info_dict["simulator"] = True
config = backend.target
info_dict["name"] = backend.name
info_dict["num_qubits"] = config.num_qubits
_max_shots = backend.options.validator.get("shots", (None, None))[1]
info_dict["max_shots"] = _max_shots if _max_shots else int(1e9)

if isinstance(backend, IBMBackend):
info_dict["simulator"] = False
elif isinstance(backend, BackendV2):
info_dict["name"] = backend.name
info_dict["num_qubits"] = backend.num_qubits
_max_shots = backend.options.validator.get("shots", (None, None))[1]
info_dict["max_shots"] = _max_shots if _max_shots else int(1e9)
# Default to simulator is True for safety
info_dict["simulator"] = True
# This is a V2 coming from IBM provider
# No other way to tell outside of configuration
# E.g. how to tell that ibmq_qasm_simulator is sim, but real devices not
# outside of configuration?
if hasattr(backend, "configuration"):
info_dict["simulator"] = backend.configuration().simulator
else:
raise M3Error("Invalid backend passed.")
# Look for faulty qubits. Renaming to 'inoperable' here
Expand Down
5 changes: 4 additions & 1 deletion mthree/mitigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,10 @@ def _job_thread(jobs, mit, qubits, num_cal_qubits, cal_strings):
else:
counts.append(_counts)
# attach timestamp
timestamp = job.metrics()["timestamps"]["running"]
if hasattr(job, 'metrics'):
timestamp = job.metrics()["timestamps"]["running"]
else:
timestamp = None
logger.info("All jobs are done.")
# Timestamp can be None
if timestamp is None:
Expand Down

0 comments on commit 1593eb1

Please sign in to comment.