Skip to content

Commit

Permalink
Removed unnecessary GST imports in __init__.py file (#29)
Browse files Browse the repository at this point in the history
* Removed unnecessary imports in __init__.py file

* Added GST imports to __init__ with try-except to avoid errors when the optional mgst dependency is not installed.

* Improved optional dependency behaviour for GST

* Linting

* Linting #2

* Improved optional dependency setup and included changelog.
  • Loading branch information
rabrie authored Jan 10, 2025
1 parent 8d94b42 commit 320f7c7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
Changelog
=========


Version 2.8
===========
* Fixed a bug where optional dependencies related to gst were imported with other benchmarks, leading to a ModuleNotFoundError.

Version 2.7
===========
* Fixed bugs in Qscore and enabled benchmark execution for pyrite.
Expand Down
6 changes: 2 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,9 @@ examples = [
]

mgst = [
"numpy < 2.0",
"cvxpy == 1.5.3",
"pygsti == 0.9.12.3",
"tqdm == 4.66.5",
"numba == 0.60.0",
"pygsti[diamond_norm] == 0.9.12.3",
"tqdm == 4.66.5",
]

test = [
Expand Down
10 changes: 9 additions & 1 deletion src/iqm/benchmarks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
BenchmarkRunResult,
)
from .circuit_containers import BenchmarkCircuit, CircuitGroup, Circuits
from .compressive_gst.compressive_gst import CompressiveGST, GSTConfiguration
from .entanglement.ghz import GHZBenchmark, GHZConfiguration
from .quantum_volume.clops import CLOPSBenchmark, CLOPSConfiguration
from .quantum_volume.quantum_volume import QuantumVolumeBenchmark, QuantumVolumeConfiguration
Expand All @@ -47,6 +46,15 @@
MirrorRandomizedBenchmarking.name: MirrorRandomizedBenchmarking,
}

try:
# Requires dependencies from "project.optional-dependencies.mgst" section to be installed. See "pyproject.toml"
# file
from .compressive_gst.compressive_gst import CompressiveGST, GSTConfiguration

AVAILABLE_BENCHMARKS.update({CompressiveGST.name: CompressiveGST})
except ModuleNotFoundError:
pass

try:
# Change here if project is renamed and does not equal the package name
dist_name = "iqm-benchmarks"
Expand Down
8 changes: 3 additions & 5 deletions src/iqm/benchmarks/compressive_gst/compressive_gst.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class CompressiveGST(Benchmark):

analysis_function = staticmethod(mgst_analysis)

name: str = "compressive_gst"

def __init__(self, backend: IQMBackendBase, configuration: "GSTConfiguration"):
"""Construct the compressive_gst class.
Expand Down Expand Up @@ -102,10 +104,6 @@ def __init__(self, backend: IQMBackendBase, configuration: "GSTConfiguration"):
self.J = np.empty((self.configuration.num_circuits, self.num_povm))
self.bootstrap_results = List[Tuple[np.ndarray]] # List of GST outcomes from bootstrapping

@staticmethod
def name() -> str:
return "compressive_GST"

@timeit
def generate_meas_circuits(self) -> None:
"""Generate random circuits from the gate set
Expand Down Expand Up @@ -172,7 +170,7 @@ def add_configuration_to_dataset(self, dataset): # CHECK
# Adding configuration entries and class variables, prioritizing the latter in case of conflicts
for key, value in (self.configuration.__dict__ | self.__dict__).items():
if key == "benchmark": # Avoid saving the class objects
dataset.attrs[key] = value.name()
dataset.attrs[key] = value.name
elif key == "backend":
dataset.attrs[key] = value.name
else:
Expand Down

0 comments on commit 320f7c7

Please sign in to comment.