Skip to content

Commit

Permalink
Require 100% docstring coverage. Ignore magic methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
airwoodix committed May 6, 2024
1 parent a69c881 commit 2e6a10c
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 12 deletions.
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,9 @@ fail_under = 99
[tool.interrogate]
ignore-module = true
ignore-nested-functions = true
ignore-magic = true
exclude = ["qiskit_aqt_provider/api_models_generated.py"]
fail-under = 88
fail-under = 100

[tool.typos.files]
ignore-hidden = false
Expand Down
5 changes: 5 additions & 0 deletions qiskit_aqt_provider/aqt_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ class BackendsTable(Sequence[AQTResource]):
"""

def __init__(self, backends: list[AQTResource]):
"""Initialize the table.
Args:
backends: list of available backends.
"""
self.backends = backends
self.headers = ["Workspace ID", "Resource ID", "Description", "Resource type"]

Expand Down
25 changes: 15 additions & 10 deletions qiskit_aqt_provider/aqt_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ def result(self, job_id: UUID) -> api_models.JobResponse:
return api_models.Response.model_validate(resp.json())

def configuration(self) -> BackendConfiguration:
"""Legacy Qiskit backend configuration."""
warnings.warn(
"The configuration() method is deprecated and will be removed in a "
"future release. Instead you should access these attributes directly "
Expand All @@ -171,36 +172,32 @@ def configuration(self) -> BackendConfiguration:
)
return self._configuration

def properties(self) -> None:
warnings.warn( # pragma: no cover
"The properties() method is deprecated and will be removed in a "
"future release. Instead you should access these attributes directly "
"off the object or via the .target attribute. You can refer to qiskit "
"backend interface transition guide for the exact changes: "
"https://docs.quantum.ibm.com/api/qiskit/providers#migrating-between-backend-api-versions",
DeprecationWarning,
)

@property
def max_circuits(self) -> int:
"""Maximum number of circuits per batch."""
return 2000

@property
def target(self) -> Target:
"""Transpilation target for this backend."""
return self._target

@classmethod
def _default_options(cls) -> QiskitOptions:
"""Default backend options, in Qiskit format."""
return QiskitOptions()

@property
def options(self) -> AQTOptions:
"""Configured backend options."""
return self._options

def get_scheduling_stage_plugin(self) -> str:
"""Name of the custom scheduling stage plugin for the Qiskit transpiler."""
return "aqt"

def get_translation_stage_plugin(self) -> str:
"""Name of the custom translation stage plugin for the Qiskit transpiler."""
return "aqt"

def run(self, circuits: Union[QuantumCircuit, list[QuantumCircuit]], **options: Any) -> AQTJob:
Expand Down Expand Up @@ -279,12 +276,20 @@ def qubit_states_from_int(state: int, num_qubits: int) -> list[int]:

@dataclass(frozen=True)
class SimulatorJob:
"""Data for a job running on a local simulator."""

job: AerJob
"""Simulation backend job handle."""

circuits: list[QuantumCircuit]
"""Quantum circuits to evaluate."""

shots: int
"""Number of repetitions of each circuit."""

@property
def job_id(self) -> UUID:
"""The job's unique identifier."""
return UUID(hex=self.job.job_id())


Expand Down
1 change: 1 addition & 0 deletions qiskit_aqt_provider/persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Circuits:
"""

def __init__(self, circuits: list[QuantumCircuit]) -> None:
"""Initialize a container filled with the given circuits."""
self.circuits = circuits

@classmethod
Expand Down
1 change: 1 addition & 0 deletions qiskit_aqt_provider/test/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class MockSimulator(OfflineSimulatorResource):
"""Offline simulator that keeps track of the submitted circuits."""

def __init__(self, *, noisy: bool) -> None:
"""Initialize the mocked simulator backend."""
super().__init__(
AQTProvider(""),
resource_id=api_models.ResourceId(
Expand Down
14 changes: 14 additions & 0 deletions qiskit_aqt_provider/test/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ def __init__(

@override
def submit(self, job: AQTJob) -> uuid.UUID:
"""Handle an execution request for a given job.
If the backend always cancels job, the job is immediately cancelled.
Otherwise, register the passed job as the active one on the backend.
"""
test_job = TestJob(job.circuits, job.options.shots, error_message=self.error_message)

if self.always_cancel:
Expand All @@ -179,6 +184,14 @@ def submit(self, job: AQTJob) -> uuid.UUID:

@override
def result(self, job_id: uuid.UUID) -> api_models.JobResponse:
"""Handle a results request for a given job.
Apply the logic configured when initializing the backend to
build an API result payload.
Raises:
UnknownJobError: the given job ID doesn't correspond to the active job's ID.
"""
if self.job is None or self.job.job_id != job_id: # pragma: no cover
raise api_models.UnknownJobError(str(job_id))

Expand Down Expand Up @@ -206,6 +219,7 @@ class DummyResource(AQTResource):
"""A non-functional resource, for testing purposes."""

def __init__(self, token: str) -> None:
"""Initialize the dummy backend."""
super().__init__(
AQTProvider(token),
resource_id=api_models.ResourceId(
Expand Down
4 changes: 4 additions & 0 deletions qiskit_aqt_provider/transpiler_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class RewriteRxAsR(TransformationPass):

@map_exceptions(TranspilerError)
def run(self, dag: DAGCircuit) -> DAGCircuit:
"""Apply the transformation pass."""
for node in dag.gate_nodes():
if node.name == "rx":
(theta,) = node.op.params
Expand All @@ -91,6 +92,7 @@ def pass_manager(
pass_manager_config: PassManagerConfig,
optimization_level: Optional[int] = None, # noqa: ARG002
) -> PassManager:
"""Pass manager for the scheduling phase."""
if isinstance(pass_manager_config.target, UnboundParametersTarget):
return PassManager([])

Expand Down Expand Up @@ -174,6 +176,7 @@ class WrapRxxAngles(TransformationPass):

@map_exceptions(TranspilerError)
def run(self, dag: DAGCircuit) -> DAGCircuit:
"""Apply the transformation pass."""
for node in dag.gate_nodes():
if node.name == "rxx":
(theta,) = node.op.params
Expand All @@ -200,6 +203,7 @@ def pass_manager(
pass_manager_config: PassManagerConfig,
optimization_level: Optional[int] = None,
) -> PassManager:
"""Pass manager for the translation stage."""
translation_pm = common.generate_translation_passmanager(
target=pass_manager_config.target,
basis_gates=pass_manager_config.basis_gates,
Expand Down
3 changes: 2 additions & 1 deletion test/test_job_persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ def test_job_persistence_transaction_online_backend(httpx_mock: HTTPXMock, tmp_p
)
backend = AQTResource(provider, resource_id)

# Mocked portal state: holds details of the submitted jobs
class PortalJob(NamedTuple):
"""Mocked portal state: holds details of the submitted jobs."""

circuits: list[api_models_generated.QuantumCircuit]
workspace_id: str
resource_id: str
Expand Down
2 changes: 2 additions & 0 deletions test/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@


class OptionsFactory(ModelFactory[AQTOptions]):
"""Factory of random but well-formed options data."""

__model__ = AQTOptions

query_timeout_seconds = 10.0
Expand Down
2 changes: 2 additions & 0 deletions test/test_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@


class OptionsFactory(ModelFactory[AQTOptions]):
"""Factory of random but well-formed options data."""

__model__ = AQTOptions

query_timeout_seconds = 10.0
Expand Down

0 comments on commit 2e6a10c

Please sign in to comment.