Getting started¶
Authenticating¶
To instantiate the AzureConnection,
you need to provide a resource_id:
from pulser_azure import AzureConnection
connection = AzureConnection(
resource_id="/subscriptions/<your-subscription-id>/resourceGroups/<your-resource-group-name>/providers/Microsoft.Quantum/Workspaces/<your-workspace-name>",
)
Alternatively, the AzureConnection can discover your resource from environment
variables:
export PULSER_AZURE_RESOURCE_ID="/subscriptions/<id>/resourceGroups/<rg>/providers/Microsoft.Quantum/Workspaces/<ws>"
Then you can instantiate the provider without any arguments:
from pulser_azure import AzureConnection
connection = AzureConnection()
Running a sequence on a QPU¶
See the Pulser sequence documentation for the full sequence-writing reference.
from pulser.pulse import Pulse
from pulser import QPUBackend, Sequence, Register
from pulser_azure import AzureConnection
connection = AzureConnection()
# Retrieve all QPU devices
devices = connection.fetch_available_devices()
device = devices["pasqal.qpu.fresnel-can1"]
# Create a register of trapped atoms before performing operation on them
register = Register.square(5, 5).with_automatic_layout(device)
# Declare the sequence of pulses to perform on the register
sequence = Sequence(register, device)
sequence.declare_channel("rydberg", "rydberg_global")
omega_max = sequence.declare_variable("omega_max")
# Add a pulse to that channel with the amplitude omega_max
generic_pulse = Pulse.ConstantPulse(100, omega_max, 2, 0.0)
sequence.add(generic_pulse, "rydberg")
# Declare a backend based on the sequence and remote connection
backend = QPUBackend(sequence=sequence, connection=connection)
# Run jobs with different arguments over the same sequence and register
results = backend.run(
job_params=[
{"runs": 5, "variables": {"omega_max": 12}},
{"runs": 10, "variables": {"omega_max": 6}},
],
wait=True,
)
print(results.results)
Running on emulators¶
Pulser Azure can be used with several remote emulator backends:
RemoteSVBackend— state vector emulatorRemoteMPSBackend— matrix product states emulatorRemoteEmuFreeBackend— qutip emulator
Use them in place of QPUBackend to run the same sequences without consuming
real QPU time:
from pasqal_cloud import RemoteMPSBackend
from pulser import Sequence, Register
from pulser.pulse import Pulse
from pulser_azure import AzureConnection
connection = AzureConnection()
# Retrieve all QPU devices
devices = connection.fetch_available_devices()
device = devices["pasqal.qpu.fresnel-can1"]
# Create a register of trapped atoms before performing operation on them
register = Register.square(5, 5).with_automatic_layout(device)
# Declare the sequence of pulses to perform on the register
sequence = Sequence(register, device)
sequence.declare_channel("rydberg", "rydberg_global")
omega_max = sequence.declare_variable("omega_max")
# Add a pulse to that channel with the amplitude omega_max
generic_pulse = Pulse.ConstantPulse(100, omega_max, 2, 0.0)
sequence.add(generic_pulse, "rydberg")
# Declare a backend based on the sequence and remote connection
backend = RemoteMPSBackend(sequence=sequence, connection=connection)
# Run jobs with different arguments over the same sequence and register
results = backend.run(
job_params=[
{"runs": 5, "variables": {"omega_max": 12}},
{"runs": 10, "variables": {"omega_max": 6}},
],
wait=True,
)
print(results.results)