Skip to content

Results are limited to the current section : Cloud Services

Product news

pasqal_cloud.pasqal_cloud_connection

Allows to connect to PASQAL's cloud platform to run sequences.

PasqalCloudConnection(username='', password='', project_id='', region='fr', **kwargs)

Bases: RemoteConnection

Manager of the connection to PASQAL's cloud platform.

The cloud connection enables to run sequences on simulators or on real QPUs.

PARAMETER DESCRIPTION
username

Your username in the PASQAL cloud platform.

TYPE: str DEFAULT: ''

password

The password for your PASQAL cloud platform account.

TYPE: str DEFAULT: ''

project_id

The project ID associated to the account.

TYPE: str DEFAULT: ''

kwargs

Additional arguments to provide to the PasqalCloudClient()

TYPE: Any DEFAULT: {}

Initializes a connection to the Pasqal cloud platform.

Source code in pasqal_cloud/pasqal_cloud_connection.py
def __init__(
    self,
    username: str = "",
    password: str = "",
    project_id: str = "",
    region: Region = "fr",
    **kwargs: Any,
):
    """Initializes a connection to the Pasqal cloud platform."""
    self.cloud_client = PasqalCloudClient(
        username=username,
        password=password,
        project_id=project_id,
        region=region,
        **kwargs,
    )

submit(sequence, wait=False, open=False, batch_id=None, device_type=None, backend_configuration=None, **kwargs)

Submits the sequence for execution on a remote Pasqal backend.

Source code in pasqal_cloud/pasqal_cloud_connection.py
def submit(
    self,
    sequence: Sequence,
    wait: bool = False,
    open: bool = False,
    batch_id: str | None = None,
    device_type: DeviceTypeName | None = None,
    backend_configuration: EmulationConfig | None = None,
    **kwargs: Any,
) -> RemoteResults:
    """Submits the sequence for execution on a remote Pasqal backend."""
    sequence = self._add_measurement_to_sequence(sequence)

    job_params: list[CreateJob] = make_json_compatible(kwargs.get("job_params", []))

    if sequence.is_parametrized() or sequence.is_register_mappable():
        for params in job_params:
            vars = params.get("variables", {}) or {}
            sequence.build(**vars)

    backend_configuration_str = (
        backend_configuration.to_abstract_repr() if backend_configuration else None
    )
    # If batch_id is not empty, then we can submit new jobs to a
    # batch we just created otherwise, create a new one with
    #  cloud_client.create_batch()
    if batch_id:
        submit_jobs_fn = retry(self.cloud_client.add_jobs)
        old_job_ids = self._get_job_ids(batch_id)
        batch = submit_jobs_fn(
            batch_id,
            jobs=job_params,
            wait=wait,
        )
        new_job_ids = [
            job_id
            for job_id in self._get_job_ids(batch_id)
            if job_id not in old_job_ids
        ]
    else:
        create_batch_fn = retry(self.cloud_client.create_batch)
        batch = create_batch_fn(
            serialized_sequence=sequence.to_abstract_repr(),
            jobs=job_params,
            device_type=device_type,
            backend_configuration=backend_configuration_str,
            wait=wait,
            open=open,
        )
        new_job_ids = self._get_job_ids(batch.id)
    return self.get_results(batch_id=batch.id, job_ids=new_job_ids)

fetch_available_devices()

Fetches the devices available through this connection.

Source code in pasqal_cloud/pasqal_cloud_connection.py
@retry
def fetch_available_devices(self) -> dict[str, Device]:
    """Fetches the devices available through this connection."""
    abstract_devices = self.cloud_client.get_device_specs_dict()
    return {
        name: cast(Device, deserialize_device(dev_str))
        for name, dev_str in abstract_devices.items()
    }

get_results(batch_id, job_ids=None)

Gets the results for a specific batch.

PARAMETER DESCRIPTION
batch_id

The ID that identifies the batch linked to the results.

TYPE: str

job_ids

If given, specifies which jobs within the batch should be included in the results and in what order. If left undefined, all jobs are included and ordered by date of creation.

TYPE: list[str] | None DEFAULT: None

RETURNS DESCRIPTION
RemoteResults

The requested results.

TYPE: RemoteResults

Source code in pasqal_cloud/pasqal_cloud_connection.py
def get_results(
    self,
    batch_id: str,
    job_ids: list[str] | None = None,
) -> RemoteResults:
    """Gets the results for a specific batch.

    Args:
        batch_id: The ID that identifies the batch linked to the results.
        job_ids: If given, specifies which jobs within the batch should
            be included in the results and in what order. If left undefined,
            all jobs are included and ordered by date of creation.

    Returns:
        RemoteResults: The requested results.
    """
    return RemoteResults(batch_id=batch_id, connection=self, job_ids=job_ids)

supports_open_batch()

Flag to confirm this class can support creating an open batch.

Source code in pasqal_cloud/pasqal_cloud_connection.py
def supports_open_batch(self) -> bool:
    """Flag to confirm this class can support creating an open batch."""
    return True