Skip to main content

Software development kit for Pasqal cloud platform.

Project description

PASQAL Cloud

SDK to be used to access Pasqal Cloud Services.

Installation

To install the latest release of the pasqal-cloud (formerly pasqal-sdk), have Python 3.8.0 or higher installed, then use pip:

pip install pasqal-cloud

If you wish to install the development version of the pasqal_cloud from source instead, do the following from within this repository after cloning it:

git checkout develop
pip install -e .

Bear in mind that this installation will track the contents of your local pasqal-cloud repository folder, so if you checkout a different branch (e.g. master), your installation will change accordingly.

Development Requirements (Optional)

To run the tutorials or the test suite locally, run the following to install the development requirements:

pip install -e .[dev]

Instanciation and Authentication

There are several ways to provide a correct authentication using the SDK.

from pasqal_cloud import SDK

group_id="your_group_id" # Replace this value by your group_id on the PASQAL platform.
username="your_username" # Replace this value by your username or email on the PASQAL platform.
password="your_password" # Replace this value by your password on the PASQAL platform.
# Ideally, do not write this password in a script but provide in through the command-line or as a secret environment variable.

""" Method 1: Username + Password
    If you know your credentials, you can pass them to the SDK instance on creation.
"""
sdk = SDK(username=username, password=password, group_id=group_id)

""" Method 2: Username only
    If you only want to insert your username, but want a solution to have your password being secret
    you can run the SDK without password. A prompt will then ask for your password
"""
sdk = SDK(username=username, group_id=group_id)
> Please, enter your password:

""" Method 3: Use a token
    If you already know your token, you can directly pass it as an argument
    using the following method.
"""
class NewTokenProvider(TokenProvider):
    def _query_token(self):
        # Custom token query that will be validated by the API Calls later.
        return {
            "access_token": "some_token",
            "id_token": "id_token",
            "scope": "openid profile email",
            "expires_in": 86400,
            "token_type": "Bearer"
        }

sdk = SDK(token_provider=NewTokenProvider, group_id=group_id)

/!\ For developers /!\

If you want to redefine the APIs used by the SDK, please, do the following.

from pasqal_cloud import SDK, Endpoints, Auth0COnf

endpoints = Endpoints(core = "my_new_core_endpoint")
auth0 = Auth0Conf(
    domain="new_domain",
    public_client_id="public_id",
    audience="new_audience"
)
sdk = SDK(..., endpoints=endpoints, auth0=auth0)

This enables you to target backend services running locally on your machine, or other environment like preprod or dev.

Basic usage

The package main component is a python object called SDK which can be used to create a Batch and send it automatically to Pasqal APIs using an API token generated in the user portal.

A Batch is a group of jobs with the same sequence that will run on the same QPU. For each job of a given batch you must set a value for each variable, if any, defined in your sequence.
The batch sequence can be generated using Pulser. See their documentation, for more information on how to install the library and create your own sequence.

Below is an example of the creation of a simple sequence with a single variable and its serialization to a string.

from pulser import devices, Pulse, Register, Sequence
from pulser.register.special_layouts import SquareLatticeLayout

# Define a register for your sequence
register = Register.square(2, spacing=5, prefix="q")
# Create a sequence for that register
sequence = Sequence(register, devices.IroiseMVP)
# 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.serialize()

Once you have serialized your sequence, you can send it with the SDK with the following code

from pasqal_cloud import SDK
from pulser import devices, Register, Sequence

group_id="your_group_id" # Replace this value by your group_id on the PASQAL platform.
username="your_username" # Replace this value by your username or email on the PASQAL platform.
password="your_password" # Replace this value by your password on the PASQAL platform.

sdk = SDK(username=username, password=password, group_id=group_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 the batch of jobs to the QPU and wait for the results
batch = sdk.create_batch(serialized_sequence, [job1,job2], wait=True)

# You can also choose to run your batch on an emulator using the optional argument 'emulator'
# For using a basic single-threaded QPU emulator that can go up to 10 qubits, you can specify the "EMU_FREE" emulator.
from pasqal_cloud.device import EmulatorType
batch = sdk.create_batch(serialized_sequence, [job1,job2], emulator=EmulatorType.EMU_FREE)

# Once the QPU has returned the results, you can access them with the following:
for job in batch.jobs.values():
    print(job.result)

Extra emulator configuration (Soon publicly available)

Some emulators, such as EMU_TN and EMU_FREE, accept further configuration to control the emulation. This is because these emulators are more advanced numerical simulation of the quantum system.

For EMU_TN you may add the integrator timestep in nanoseconds, the numerical accuracy desired in the tensor network compression, and the maximal bond dimension of tensor network state.

# replace the corresponding section in the above code example with this to
# add further configuration
from pasqal_cloud.device import EmulatorType, EmuTNConfig

configuration = EmuTNConfig(dt = 10.0, precision = "normal", max_bond_dim = 100)
batch = sdk.create_batch(serialized_sequence, [job1,job2], emulator=EmulatorType.EMU_TN, configuration=configuration)

For EMU_FREE you may add some default SPAM noise. Beware this makes your job take much longer.

# replace the corresponding section in the above code example with this to
# add further configuration
from pasqal_cloud.device import EmulatorType, EmuFreeConfig

configuration = EmuFreeConfig(with_noise=True)
batch = sdk.create_batch(serialized_sequence, [job1,job2], emulator=EmulatorType.EMU_FREE, configuration=configuration)

List of supported device specifications

The SDK provides a method to retrieve the devices specs currently defined on PASQAL's cloud platform. They define the physical constraints of our QPUs and these constraints enforce some rules on the pulser sequence that can be run on QPUs (e.g. max amount of atoms, available pulse channels, ...)

sdk.get_device_specs_list()

The method returns a dict object mapping a device type to a serialized device specs. These specs can be used to instantiate a Device instance in the Pulser library.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pasqal-cloud-0.0.1.tar.gz (24.4 kB view details)

Uploaded Source

Built Distribution

pasqal_cloud-0.0.1-py3-none-any.whl (30.8 kB view details)

Uploaded Python 3

File details

Details for the file pasqal-cloud-0.0.1.tar.gz.

File metadata

  • Download URL: pasqal-cloud-0.0.1.tar.gz
  • Upload date:
  • Size: 24.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.3

File hashes

Hashes for pasqal-cloud-0.0.1.tar.gz
Algorithm Hash digest
SHA256 a64601a9e16cff49d63f6b6a948c9a7a3d44331aea8c564148b96350bbc73c4e
MD5 ab5210b993b0f5e78f7cf91a3447b5fd
BLAKE2b-256 f58c006812ef2f0746432fb92303aa383ec2ffea0500cbe586811cd8ada71b39

See more details on using hashes here.

File details

Details for the file pasqal_cloud-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: pasqal_cloud-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 30.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.3

File hashes

Hashes for pasqal_cloud-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 86e2d15652cc98a374d3a7e0d526eb68b7598a47bf4e19bc8386628160f7047e
MD5 1b4c2a546df20931833653a0c2fb092a
BLAKE2b-256 1940ae7a00a670f6a3ce72ae5735ea9832dfd8a1bb2a5d3ad08d8e139576cd07

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page