Run your first job
SDK Authentication
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
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 clientsdk = 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, Sequencefrom pulser.devices import DigitalAnalogDevice
# Define a register for your sequenceregister = Register.square(2, spacing=5, prefix="q")# Create a sequence for that registersequence = Sequence(register, DigitalAnalogDevice)# Add a channel to your sequencesequence.declare_channel("rydberg", "rydberg_global")# Declare a variableomega_max = sequence.declare_variable("omega_max")# Add a pulse to that channel with the amplitude omega_maxgeneric_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 stringserialized_sequence = sequence.to_abstract_repr()
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.
We are now ready to create our first batch with the SDK:
from pasqal_cloud import SDKfrom 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 passwordsdk = 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 sequencejob1 = {"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}")
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 (external) .
Congrats! You just ran your first job on one of our backends (Emulators) through Pasqal’s Cloud platform 😃.