pytket-azure example usage¶
This notebook shows how to use the pytket-azure extension to submit pytket circuits to quantinuum devices using the azure credentials.
First you need to install the extension. The best way to do this is pip install pytket-azure
This also installs pytket if not installed already.
First import the Backend, it offers the needed functionality to login, send circuits and get results.
from pytket.extensions.azure import AzureBackend
The next steps is to select the device you want to use. You can find all supported devices here There are three groups: Syntax Checker, Emulator and devices.
Syntax Checker h1-1sc¶
backend_sc = AzureBackend("quantinuum.sim.h1-1sc")
print(backend_sc.is_available())
True
You can use the backend to compile your pytket circuit to the right gateset and send it to the device.
from pytket import Circuit
circ = Circuit(2, 2)
circ.H(0)
circ.CX(0,1)
circ.Measure(0, 0)
circ.Measure(1, 1)
compiled_circuit = backend_sc.get_compiled_circuit(circ, 3)
from pytket.circuit.display import render_circuit_jupyter
render_circuit_jupyter(compiled_circuit)
handle = backend_sc.process_circuit(compiled_circuit, n_shots=1000)
result = backend_sc.get_result(handle, timeout=120)
The result of the Syntax checker will always be 0 for all measured bits. If there are any issues with the circuit it will return an error.
print(result.get_counts())
Counter({(0, 0): 1000})
Submitting the circuit to the emulator or device works in the same way, which will also give the results of the run:
Emulator h1-1e¶
backend_e = AzureBackend("quantinuum.sim.h1-1e")
print(backend_e.is_available())
True
from pytket import Circuit
circ = Circuit(2, 2)
circ.H(0)
circ.CX(0,1)
circ.Measure(0, 0)
circ.Measure(1, 1)
compiled_circuit = backend_e.get_compiled_circuit(circ, 0)
handle = backend_e.process_circuit(compiled_circuit, n_shots=1000)
result = backend_e.get_result(handle, timeout=120)
............
print(result.get_counts())
Counter({(0, 0): 497, (1, 1): 497, (1, 0): 4, (0, 1): 2})