Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provider: remove deprecated ProviderV1 inheritance #160

Merged
merged 3 commits into from
May 21, 2024
Merged
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
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]