Run your first job
SDK Authentification
As mentioned in the “Pasqal Tools overview” you will use Pasqal’s cloud SDK to send a job to Pasqal’s hardware.
The SDK can be installed using pip with
pip install pasqal-cloud
Notes: To access the source code and for more details on all the features of the SDK, please refer to the github repository.
The package main component is a Python object called SDK
which can be used to submit jobs for execution.
You can send one or several jobs for execution to Pasqal’s cloud using:
- the email and password combination you used to sign-up
- the ID of the project you are a member of
Import the SDK and create an instance of the SDK with your credentials as follows. You will be automatically prompted to enter your password.
from pasqal_cloud import SDK
project_id = "your_project_id"# Replace this value by your project_id on the PASQAL platform.
username = "your_username"# Replace this value by your username or email on the PASQAL platform.
# Initialize the cloud client
sdk = SDK(username=username, project_id=project_id)
Create a Batch of Jobs
Create a Sequence
A batch is a group of jobs with the same sequence that will run on the same backend. See the Advanced Usage section to learn more about how to use batches to optimize the scheduling of your jobs.
A sequence is the central object in Pulser and it consists essentially of a series of pulses. A sequence can be "parametrized" if you define variables inside it.
See the page Understand your sequence for more information on the sequence object.
Let’s see an example of the creation of a simple sequence with a single variable and its serialization to a string:
from pulser import Pulse, Register, Sequence
from pulser.devices import DigitalAnalogDevice
# Define a register for your sequence
register = Register.square(2, spacing=5, prefix="q")
# Create a sequence for that register
sequence = Sequence(register, DigitalAnalogDevice)
# Add a channel to your sequence
sequence.declare_channel("rydberg", "rydberg_global")
# Declare a variable
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")
# When you are done building your sequence, serialize it into a string
serialized_sequence = sequence.to_abstract_repr()
Note: See the Pulser documentation, for more information on how to install the library and create your own sequence.
Send your first batch with the SDK through the Cloud
Now that we are authenticated to the Cloud SDK and we have created a sequence, let’s send a batch of jobs for execution on one of our emulators.
To create a job, you need to define:
- a number of runs. This sets the number of time the sequence will be run on the backend and the final state measured.
- a value for each variable of the sequence, if any.
Note: A "run" is also sometimes called "shot" or "repetition".
We are now ready to create our first batch with the SDK:
from pasqal_cloud import SDK
from pasqal_cloud.device import EmulatorType
project_id = "your_project_id"# Replace this value by your project_id on the PASQAL platform.
username = "your_username"# Replace this value by your username or email on the PASQAL platform.
# Initialize the cloud client
# This will open a prompt to enter your password
sdk = SDK(username=username, project_id=project_id)
# When creating a job, select a number of runs and set the desired values for the variables
# defined in the sequence
job1 = {"runs": 20, "variables": {"omega_max": 6}}
job2 = {"runs": 50, "variables": {"omega_max": 10.5}}
# Send your batch on an emulator using the optional argument 'emulator'
# For a basic single-threaded QPU emulator that can go up to 10 qubits, you can specify the "EMU_FREE" emulator.
batch = sdk.create_batch(
serialized_sequence, [job1, job2], emulator=EmulatorType.EMU_FREE
)
# Once the backend has returned the results, you can access them with the following:
for job in batch.ordered_jobs:
print(f"job-id: {job.id}, status: {job.status}, result: {job.result}")
Note: If your Pulser sequence is not parametrized, you only need to specify the number of runs (repetitions) for each job, e.g. job1 = {"runs": 20}
.
Once your script exits successfully, you can follow the status of your batch and its jobs during their life-cycle, cancel them or download their results directly in the User portal.
Congrats! You just ran your first job on one of our backends (Emulators) through Pasqal’s Cloud platform 😃.