Skip to content

Commit

Permalink
Provider: remove deprecated ProviderV1 inheritance (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
airwoodix authored May 21, 2024
1 parent 263a522 commit cd2dce8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

* Docs: add examples on setting run options in primitives (#156)
* Provider: remove `ProviderV1` inheritance (#160)

## qiskit-aqt-provider v1.4.0

Expand Down
4 changes: 2 additions & 2 deletions docs/guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ AQT backends only natively implement a limited but complete set of quantum gates

print(list(backend.target.operation_names))

.. warning:: For implementation reasons, the transpilation target declares :class:`RXGate <qiskit.circuit.library.RXGate>` as basis gate. The AQT API, however, only accepts the more general :class:`RGate <qiskit.circuit.library.RGate>`, in addition to :class:`RZGate <qiskit.circuit.library.RZGate>`, the entangling :class:`RXXGate <qiskit.circuit.library.RXXGate>`, and the :class:`Measure <qiskit.circuit.library.Measure>` operation.
.. warning:: For implementation reasons, the transpilation target declares :class:`RXGate <qiskit.circuit.library.RXGate>` as basis gate. The AQT API, however, only accepts the more general :class:`RGate <qiskit.circuit.library.RGate>`, in addition to :class:`RZGate <qiskit.circuit.library.RZGate>`, the entangling :class:`RXXGate <qiskit.circuit.library.RXXGate>`, and the :class:`Measure <qiskit.circuit.measure.Measure>` operation.

The transpiler's entry point is the :func:`qiskit.transpile <qiskit.compiler.transpile>` function. The optimization level can be tuned using the ``optimization_level=0,1,2,3`` argument. One can inspect how the circuit is converted from the original one:

Expand Down Expand Up @@ -299,7 +299,7 @@ Common limitations
Reset operations are not supported
----------------------------------

Because AQT backends do not support in-circuit state reinitialization of specific qubits, the :class:`Reset <qiskit.circuit.library.Reset>` operation is not supported. The Qiskit transpiler will fail synthesis for circuits using it (e.g. through :meth:`QuantumCircuit.initialize <qiskit.circuit.QuantumCircuit.initialize>`) when targeting AQT backends.
Because AQT backends do not support in-circuit state reinitialization of specific qubits, the :class:`Reset <qiskit.circuit.reset.Reset>` operation is not supported. The Qiskit transpiler will fail synthesis for circuits using it (e.g. through :meth:`QuantumCircuit.initialize <qiskit.circuit.QuantumCircuit.initialize>`) when targeting AQT backends.

AQT backends always prepare the quantum register in the :math:`|0\rangle\otimes\cdots\otimes|0\rangle` state. Thus, :meth:`QuantumCircuit.prepare_state <qiskit.circuit.QuantumCircuit.prepare_state>` is an alternative to :meth:`QuantumCircuit.initialize <qiskit.circuit.QuantumCircuit.initialize>` as first instruction in the circuit:

Expand Down
36 changes: 34 additions & 2 deletions qiskit_aqt_provider/aqt_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

import dotenv
import httpx
from qiskit.providers import ProviderV1
from qiskit.providers.exceptions import QiskitBackendNotFoundError
from tabulate import tabulate
from typing_extensions import TypeAlias, override

Expand Down Expand Up @@ -139,7 +139,7 @@ def table(self) -> list[list[str]]:
return table


class AQTProvider(ProviderV1):
class AQTProvider:
"""Provider for backends from Alpine Quantum Technologies (AQT)."""

# Set AQT_PORTAL_URL environment variable to override
Expand Down Expand Up @@ -282,3 +282,35 @@ def backends(
)

return BackendsTable(backends)

def get_backend(
self,
name: Optional[Union[str, Pattern[str]]] = None,
*,
backend_type: Optional[Literal["device", "simulator", "offline_simulator"]] = None,
workspace: Optional[Union[str, Pattern[str]]] = None,
) -> AQTResource:
"""Return a single backend matching the specified filtering.
Args:
name: filter for the backend name.
backend_type: if given, restrict the search to the given backend type.
workspace: if given, restrict to matching workspace IDs.
Returns:
Backend: backend matching the filtering.
Raises:
QiskitBackendNotFoundError: if no backend could be found or
more than one backend matches the filtering criteria.
"""
# From: https://github.com/Qiskit/qiskit/blob/8e3218bc0798b0612edf446db130e95ac9404968/qiskit/providers/provider.py#L53
# after ProviderV1 deprecation.
# See: https://github.com/Qiskit/qiskit/pull/12145.
backends = self.backends(name, backend_type=backend_type, workspace=workspace)
if len(backends) > 1:
raise QiskitBackendNotFoundError("More than one backend matches the criteria")
if not backends:
raise QiskitBackendNotFoundError("No backend matches the criteria")

return backends[0]

0 comments on commit cd2dce8

Please sign in to comment.