Quickstart: Submit a circuit with a provider-specific format to Azure Quantum
Learn how to use the azure-quantum Python package to submit provider-specific formatted quantum circuits, (for example, OpenQASM 2.0 or IonQ JSON), to an IonQ or Quantinuum quantum computing target via the Azure Quantum service. For more information, see Quantum circuits.
Prerequisites
An Azure account with an active subscription. Create an account for free.
Create an Azure Quantum workspace and enable your preferred provider, Quantinuum or IonQ (or both), for this scenario. For more information, see Create an Azure Quantum workspace.
Install the latest
azure-quantumPython package.Tip
If you are using Miniconda or Anaconda, you can optionally create a new environment by downloading environment.yml and running the following:
conda env create -f environment.ymlThis creates a new conda environment that you can activate with the following:
conda activate azurequantumStart your favorite code editor or interactive Python tool, such as VS Code, Jupyter or iPython.
Load the required imports
First, run the following cell to load the required imports:
from azure.quantum import Workspace
Connect to the Azure Quantum service
To connect to the Azure Quantum service, your program will need the resource ID and the location of your Azure Quantum workspace. Log in to your Azure account, https://portal.azure.com, navigate to your Azure Quantum workspace, and copy the values from the header.

Paste the values into the following Workspace constructor to
create a workspace object that connects to your Azure Quantum workspace.
workspace = Workspace(
resource_id="",
location=""
)
Submit a quantum circuit to IonQ
Create a quantum circuit using the the language-agnostic JSON format supported by the IonQ targets, as described in the IonQ API documentation. For example, the following sample creates a superposition between three qubits:
circuit = { "qubits": 3, "circuit": [ { "gate": "h", "target": 0 }, { "gate": "cnot", "control": 0, "target": 1 }, { "gate": "cnot", "control": 0, "target": 2 }, ] }Submit the circuit to the IonQ target. The following example uses the IonQ simulator, which returns a
Jobobject. For more information, see Azure Quantum Job.target = workspace.get_targets(name="ionq.simulator") job = target.submit(circuit)Wait until the job is complete and then fetch the results.
results = job.get_results() print(results)..... {'duration': 8240356, 'histogram': {'0': 0.5, '7': 0.5}}You can then visualize the results using Matplotlib.
import pylab as pl pl.rcParams["font.size"] = 16 hist = {format(n, "03b"): 0 for n in range(8)} hist.update({format(int(k), "03b"): v for k, v in results["histogram"].items()}) pl.bar(hist.keys(), hist.values()) pl.ylabel("Probabilities")

Estimate job cost
Before running a job on the QPU, you can estimate how much it will cost to run. To estimate the cost of running a job on the QPU,you can use the estimate_cost method:
target = workspace.get_targets(name="ionq.qpu")
cost = target.estimate_cost(circuit, num_shots=500)
print(f"Estimated cost: {cost.estimated_total}")
This prints the estimated cost in USD.
For the most current pricing details, see IonQ Pricing, or find your workspace and view pricing options in the "Provider" tab of your workspace via: aka.ms/aq/myworkspaces.
Load the required imports
First, run the following cell to load the required imports:
from azure.quantum import Workspace
Connect to the Azure Quantum service
To connect to the Azure Quantum service, your program will need the resource ID and the location of your Azure Quantum workspace. Log in to your Azure account, https://portal.azure.com, navigate to your Azure Quantum workspace, and copy the values from the header.

Paste the values into the following Workspace constructor to
create a workspace object that connects to your Azure Quantum workspace.
workspace = Workspace(
resource_id="",
location=""
)
Submit a quantum circuit to the Quantinuum API validator
Note
The Quantinuum API validator target will always return 0 on measurement.
Create a quantum circuit in the OpenQASM representation. For example, the following example creates a Teleportation circuit:
circuit = """OPENQASM 2.0; include "qelib1.inc"; qreg q[3]; creg c0[3]; h q[0]; cx q[0], q[1]; cx q[1], q[2]; measure q[0] -> c0[0]; measure q[1] -> c0[1]; measure q[2] -> c0[2]; """Optionally, you can load the circuit from a file:
with open("my_teleport.qasm", "r") as f: circuit = f.read()Submit the circuit to the Quantinuum target. The following example uses the Quantinuum API validator, which returns a
Jobobject. For more information, see Azure Quantum Job.target = workspace.get_targets(name="quantinuum.hqs-lt-s1-apival") job = target.submit(circuit, num_shots=500)Wait until the job is complete and then fetch the results.
results = job.get_results() print(results)........ {'c0': ['000', '000', '000', '000', '000', '000', '000', ... ]}You can then visualize the results using Matplotlib.
import pylab as pl pl.hist(results["c0"]) pl.ylabel("Counts") pl.xlabel("Bitstring")

Estimate job cost
Before running a job on the QPU, you can estimate how much it will cost to run. To estimate the cost of running a job on the QPU, you can use the estimate_cost method:
target = workspace.get_targets(name="quantinuum.hqs-lt-s1")
cost = target.estimate_cost(circuit, num_shots=500)
print(f"Estimated cost: {cost.estimated_total}")
This prints the estimated cost in H-System Quantum Credits (HQCs).
For the most current pricing details, see System Model H1, Powered by Honeywell, or find your workspace and view pricing options in the "Provider" tab of your workspace via: aka.ms/aq/myworkspaces.
Povratne informacije
Pošalјite i prikažite povratne informacije za