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

qiskit qir by default #630

Merged
merged 30 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
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
54 changes: 54 additions & 0 deletions azure-quantum/azure/quantum/qiskit/backends/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,25 @@
To install run: pip install azure-quantum[qiskit]"
)

QIR_BASIS_GATES = [
"x",
"y",
"z",
"rx",
"ry",
"rz",
"h",
"swap",
"cx",
"cz",
"reset",
"s",
"sdg",
"t",
"tdg",
"measure",
]


class AzureBackendBase(Backend, SessionHost):

Expand Down Expand Up @@ -280,7 +299,11 @@ def _azure_config(self) -> Dict[str, str]:
"content_type": "qir.v1",
"input_data_format": "qir.v1",
"output_data_format": "microsoft.quantum-results.v2",
"is_default": True,
}

def _basis_gates(self) -> List[str]:
return QIR_BASIS_GATES

def run(
self,
Expand Down Expand Up @@ -429,6 +452,37 @@ def _translate_input(

return module.bitcode

def _estimate_cost_qir(self, circuits, shots, options={}):
"""Estimate the cost for the given circuit."""
config = self.configuration()
input_params = self._get_input_params(options, shots=shots)

if not (isinstance(circuits, list)):
circuits = [circuits]

to_qir_kwargs = input_params.pop(
"to_qir_kwargs", config.azure.get("to_qir_kwargs", {"record_output": True})
)
targetCapability = input_params.pop(
"targetCapability",
self.options.get("targetCapability", "AdaptiveExecution"),
)

if not input_params.pop("skipTranspile", False):
# Set of gates supported by QIR targets.
circuits = transpile(
circuits, basis_gates=config.basis_gates, optimization_level=0
)


(module, _) = self._generate_qir(
circuits, targetCapability, **to_qir_kwargs
)

workspace = self.provider().get_workspace()
target = workspace.get_targets(self.name())
return target.estimate_cost(module, shots=shots)


class AzureBackend(AzureBackendBase):
"""Base class for interfacing with a backend in Azure Quantum"""
Expand Down
43 changes: 8 additions & 35 deletions azure-quantum/azure/quantum/qiskit/backends/ionq.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from qiskit.providers import Options, Provider

from qiskit_ionq.helpers import (
ionq_basis_gates,
GATESET_MAP,
qiskit_circ_to_ionq_circ,
)
Expand Down Expand Up @@ -77,6 +76,10 @@ def _azure_config(self) -> Dict[str, str]:
}
)
return config

def estimate_cost(self, circuits, shots, options={}):
"""Estimate the cost for the given circuit."""
return self._estimate_cost_qir(circuits, shots, options)

def run(
self,
Expand All @@ -103,7 +106,6 @@ class IonQSimulatorQirBackend(IonQQirBackendBase):

def __init__(self, name: str, provider: "AzureQuantumProvider", **kwargs):
"""Base class for interfacing with an IonQ QIR Simulator backend"""

default_config = BackendConfiguration.from_dict(
{
"backend_name": name,
Expand All @@ -112,7 +114,7 @@ def __init__(self, name: str, provider: "AzureQuantumProvider", **kwargs):
"local": False,
"coupling_map": None,
"description": "IonQ simulator on Azure Quantum",
"basis_gates": ionq_basis_gates,
"basis_gates": self._basis_gates(),
"memory": False,
"n_qubits": 29,
"conditional": False,
Expand All @@ -135,7 +137,6 @@ class IonQAriaQirBackend(IonQQirBackendBase):

def __init__(self, name: str, provider: "AzureQuantumProvider", **kwargs):
"""Base class for interfacing with an IonQ Aria QPU backend"""

default_config = BackendConfiguration.from_dict(
{
"backend_name": name,
Expand All @@ -144,7 +145,7 @@ def __init__(self, name: str, provider: "AzureQuantumProvider", **kwargs):
"local": False,
"coupling_map": None,
"description": "IonQ Aria QPU on Azure Quantum",
"basis_gates": ionq_basis_gates,
"basis_gates": self._basis_gates(),
"memory": False,
"n_qubits": 23,
"conditional": False,
Expand All @@ -167,7 +168,6 @@ class IonQForteQirBackend(IonQQirBackendBase):

def __init__(self, name: str, provider: "AzureQuantumProvider", **kwargs):
"""Base class for interfacing with an IonQ Forte QPU backend"""

default_config = BackendConfiguration.from_dict(
{
"backend_name": name,
Expand All @@ -176,7 +176,7 @@ def __init__(self, name: str, provider: "AzureQuantumProvider", **kwargs):
"local": False,
"coupling_map": None,
"description": "IonQ Forte QPU on Azure Quantum",
"basis_gates": ionq_basis_gates,
"basis_gates": self._basis_gates(),
"memory": False,
"n_qubits": 35,
"conditional": False,
Expand Down Expand Up @@ -241,7 +241,7 @@ def _azure_config(self) -> Dict[str, str]:
"provider_id": "ionq",
"input_data_format": "ionq.circuit.v1",
"output_data_format": "ionq.quantum-results.v1",
"is_default": True,
"is_default": False,
}

def _prepare_job_metadata(self, circuit, **kwargs):
Expand Down Expand Up @@ -316,15 +316,6 @@ def __init__(self, name: str, provider: "AzureQuantumProvider", **kwargs):
kwargs["gateset"] = "native"
super().__init__(name, provider, **kwargs)

def _azure_config(self) -> Dict[str, str]:
config = super()._azure_config()
config.update(
{
"is_default": False,
}
)
return config


class IonQAriaBackend(IonQBackend):
backend_names = ("ionq.qpu.aria-1", "ionq.qpu.aria-2")
Expand Down Expand Up @@ -398,27 +389,9 @@ def __init__(self, name: str, provider: "AzureQuantumProvider", **kwargs):
kwargs["gateset"] = "native"
super().__init__(name, provider, **kwargs)

def _azure_config(self) -> Dict[str, str]:
config = super()._azure_config()
config.update(
{
"is_default": False,
}
)
return config


class IonQForteNativeBackend(IonQForteBackend):
def __init__(self, name: str, provider: "AzureQuantumProvider", **kwargs):
if "gateset" not in kwargs:
kwargs["gateset"] = "native"
super().__init__(name, provider, **kwargs)

def _azure_config(self) -> Dict[str, str]:
config = super()._azure_config()
config.update(
{
"is_default": False,
}
)
return config
26 changes: 2 additions & 24 deletions azure-quantum/azure/quantum/qiskit/backends/qci.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,6 @@
from qiskit.providers.models import BackendConfiguration
from qiskit.providers import Options, Provider

QIR_BASIS_GATES = [
"measure",
"m",
"barrier",
"cx",
"cz",
"h",
"reset",
"rx",
"ry",
"rz",
"s",
"sdg",
"swap",
"t",
"tdg",
"x",
"y",
"z",
"id",
]

if TYPE_CHECKING:
from azure.quantum.qiskit import AzureQuantumProvider

Expand Down Expand Up @@ -110,7 +88,7 @@ def __init__(self, name: str, provider: "AzureQuantumProvider", **kwargs):
"local": False,
"coupling_map": None,
"description": "QCI simulator on Azure Quantum",
"basis_gates": QIR_BASIS_GATES,
"basis_gates": self._basis_gates(),
"memory": False,
"n_qubits": 29,
"conditional": True,
Expand Down Expand Up @@ -142,7 +120,7 @@ def __init__(self, name: str, provider: "AzureQuantumProvider", **kwargs):
"local": False,
"coupling_map": None,
"description": "QCI QPU on Azure Quantum",
"basis_gates": QIR_BASIS_GATES,
"basis_gates": self._basis_gates(),
"memory": False,
"n_qubits": 11,
"conditional": True,
Expand Down
33 changes: 29 additions & 4 deletions azure-quantum/azure/quantum/qiskit/backends/quantinuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,24 @@
"reset",
]

QUANTINUUM_QIR_BASIS_GATES = [
"x",
"y",
"z",
"rx",
"ry",
"rz",
"h",
"cx",
"cz",
"reset",
"s",
"sdg",
"t",
"tdg",
"measure",
]

QUANTINUUM_PROVIDER_ID = "quantinuum"
QUANTINUUM_PROVIDER_NAME = "Quantinuum"

Expand Down Expand Up @@ -94,9 +112,16 @@ def _azure_config(self) -> Dict[str, str]:
}
)
return config

def _basis_gates(self) -> List[str]:
return QUANTINUUM_QIR_BASIS_GATES

def _get_n_qubits(self, name):
return _get_n_qubits(name)

def estimate_cost(self, circuits, shots, options={}):
"""Estimate the cost for the given circuit."""
return self._estimate_cost_qir(circuits, shots, options)


class QuantinuumSyntaxCheckerQirBackend(QuantinuumQirBackendBase):
Expand All @@ -118,7 +143,7 @@ def __init__(self, name: str, provider: "AzureQuantumProvider", **kwargs):
"local": False,
"coupling_map": None,
"description": f"Quantinuum Syntax Checker on Azure Quantum",
"basis_gates": QUANTINUUM_BASIS_GATES,
"basis_gates": self._basis_gates(),
"memory": True,
"n_qubits": self._get_n_qubits(name),
"conditional": False,
Expand Down Expand Up @@ -155,7 +180,7 @@ def __init__(self, name: str, provider: "AzureQuantumProvider", **kwargs):
"local": False,
"coupling_map": None,
"description": f"Quantinuum emulator on Azure Quantum",
"basis_gates": QUANTINUUM_BASIS_GATES,
"basis_gates": self._basis_gates(),
"memory": True,
"n_qubits": self._get_n_qubits(name),
"conditional": False,
Expand Down Expand Up @@ -192,7 +217,7 @@ def __init__(self, name: str, provider: "AzureQuantumProvider", **kwargs):
"local": False,
"coupling_map": None,
"description": f"Quantinuum QPU on Azure Quantum",
"basis_gates": QUANTINUUM_BASIS_GATES,
"basis_gates": self._basis_gates(),
"memory": True,
"n_qubits": self._get_n_qubits(name),
"conditional": False,
Expand Down Expand Up @@ -236,7 +261,7 @@ def _azure_config(self) -> Dict[str, str]:
"provider_id": self._provider_id,
"input_data_format": "honeywell.openqasm.v1",
"output_data_format": "honeywell.quantum-results.v1",
"is_default": True,
"is_default": False,
}

def _translate_input(self, circuit):
Expand Down
24 changes: 2 additions & 22 deletions azure-quantum/azure/quantum/qiskit/backends/rigetti.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,6 @@
from qiskit.providers.models import BackendConfiguration
from qiskit.providers import Options, Provider

QIR_BASIS_GATES = [
"measure",
"m",
"cx",
"cz",
"h",
"reset",
"rx",
"ry",
"rz",
"s",
"sdg,"
"t",
"tdg",
"x",
"y",
"z",
"id",
]

if TYPE_CHECKING:
from azure.quantum.qiskit import AzureQuantumProvider

Expand Down Expand Up @@ -85,7 +65,7 @@ def __init__(self, name: str, provider: "AzureQuantumProvider", **kwargs):
"local": False,
"coupling_map": None,
"description": "Rigetti simulator on Azure Quantum",
"basis_gates": QIR_BASIS_GATES,
"basis_gates": self._basis_gates(),
"memory": True,
"n_qubits": RigettiTarget.num_qubits(name),
"conditional": False,
Expand Down Expand Up @@ -117,7 +97,7 @@ def __init__(self, name: str, provider: "AzureQuantumProvider", **kwargs):
"local": False,
"coupling_map": None,
"description": "Rigetti QPU on Azure Quantum",
"basis_gates": QIR_BASIS_GATES,
"basis_gates": self._basis_gates(),
"memory": True,
"n_qubits": RigettiTarget.num_qubits(name),
"conditional": False,
Expand Down
Loading
Loading