Scaleway

Scaleway Quantum as a Service provides access to physical and emulated quantum processing units. Perceval connects to a Scaleway platform through a ScalewayCommunicationLayer inserted into a RemoteComputer.

Authentication

Using Scaleway QaaS requires a Scaleway account, project ID, and API secret key:

  1. Create a Scaleway account.

  2. Create a Scaleway project.

  3. Create a Scaleway API key.

The secret key can be passed directly to the communication layer, stored in the SCALEWAY_CLOUD_TOKEN environment variable, or managed with ScalewayConfig. The project ID is always passed explicitly.

ScalewayCommunicationLayer

Choose a platform listed by Scaleway, then create the communication layer and remote computer:

>>> import perceval as pcvl
>>> import perceval.providers.scaleway as scw
>>>
>>> PROJECT_ID = "your-scaleway-project-id"
>>> TOKEN = "your-scaleway-api-secret-key"
>>> PLATFORM_NAME = "EMU-SAMPLING-L4" # For emulated QPU
>>> # PLATFORM_NAME = "QPU-BELENOS-12PQ" # For real QPU
>>>
>>> communication_layer = scw.ScalewayCommunicationLayer(
...     platform_name=PLATFORM_NAME,
...     project_id=PROJECT_ID,
...     token=TOKEN,
... )
>>> computer = pcvl.RemoteComputer(communication_layer)

Scaleway requires a QaaS session. The computer lifecycle creates and terminates it, so use Computer.acquire around all executions sharing the session. Try to start and stop the session only once to avoid overhead:

>>> experiment = pcvl.Experiment(pcvl.BS())
>>> experiment.with_input(pcvl.BasicState("|0,1>"))
>>> experiment.min_detected_photons_filter(1)
>>> factory = pcvl.ExecutionFactory(computer, experiment, max_shots_per_call=10_000)
>>>
>>> with computer.acquire():
...     results = factory.samples(max_samples=100)
...     # All computation goes here

The session can instead be managed explicitly with computer.start() and computer.stop(). Calling computer.delete() deletes the attached session and its jobs.

Using an existing Scaleway QPU session

If you created your session from the Scaleway console, you can retrieve it from Perceval.

For this, you only have to go to your session’s settings on the console, copy the deduplication identifier and put it to the session creation on your Perceval code.

>>> DEDUPLICATION_ID = "my-quantum-workshop-identifier"
>>> communicationLayer = scw.ScalewayCommunicationLayer(
...     platform=PLATFORM_NAME,
...     project_id=PROJECT_ID,
...     token=TOKEN,
...     deduplication_id=DEDUPLICATION_ID)

A session can be fetched until termination or timeout. If there is no alive session matching the deduplication_id, a new one will be created and returned. It is highly convenient if you wish to keep a specific amount of session alive at a time.

class perceval.providers.scaleway.scaleway_communication_layer.ScalewayCommunicationLayer(platform_name, project_id, token=None, max_idle_duration_s=1200, max_duration_s=3600, deduplication_id=None, url=None, proxies=None, provider_name=None)

Communication layer for platforms exposed through Scaleway QaaS.

Scaleway uses explicit sessions. Starting and stopping RemoteComputer is mandatory for Scaleway.

Parameters:
  • platform_name (str) – Name of the target Scaleway QaaS platform.

  • project_id (str) – UUID of the Scaleway project that owns jobs and sessions.

  • token (Optional[str]) – Scaleway API secret key. When omitted, use ScalewayConfig token.

  • max_idle_duration_s (int) – Maximum session inactivity in seconds before termination.

  • max_duration_s (int) – Maximum total session duration in seconds.

  • deduplication_id (Optional[str]) – Optional identifier used to reuse a matching active session.

  • url (Optional[str]) – Scaleway API URL. When omitted, use ScalewayConfig url.

  • proxies (Optional[dict[str, str]]) – Mapping of protocols to proxy URLs.

  • provider_name (Optional[str]) – Platform provider name. When omitted, use ScalewayConfig provider.

delete_session()

Delete the attached session and its jobs from Scaleway QaaS.

Return type:

None

start_session()

Create or reuse the configured Scaleway QaaS session.

Return type:

None

stop_session()

Terminate the attached session while leaving its jobs accessible.

Return type:

None

ScalewayConfig

Note

Execution serialization does not store credentials. To be able to deserialize an execution made through a Scaleway computer, the ScalewayConfig needs to be configured.

ScalewayConfig manages the API secret key, API URL, proxies, and default platform provider. Values set on the class are cached for the current Python process. Call save() only on a personal machine when they should also be written to Perceval’s persistent configuration:

Note

Execution serialization does not store credentials. To be able to deserialize an execution made through a Quandela computer, the RemoteConfig needs to be configured.

>>> config = scw.ScalewayConfig()
>>> config.set_token(TOKEN)
>>> config.set_provider("quandela")
>>> config.save()

After configuration, the token and provider name may be omitted from the communication layer:

>>> communication_layer = scw.ScalewayCommunicationLayer(
...     platform_name=PLATFORM_NAME,
...     project_id=PROJECT_ID,
... )

Note

Do not persist authentication tokens on shared or public computers. Using an environment variable or the in-memory configuration cache avoids writing the token to disk.

class perceval.providers.scaleway.scaleway_config.ScalewayConfig(persistent_data=<perceval.utils.persistent_data.PersistentData object>)

Handle the remote configuration for the Scaleway API.

Tokens are read from the in-memory cache, the SCALEWAY_CLOUD_TOKEN environment variable, or persistent Perceval configuration. The API URL, proxies, and default platform provider can also be stored.

The secret_key argument used by the Scaleway API is stored under the name token for consistency with the other provider configurations.

classmethod clear_cache()

Delete the RemoteConfig cache.

get_provider()

Find the configured default platform provider, cache it, and return it.

The priority for the provider search is as follows: * A provider already in cache (e.g. set by the user or already found in a previous call) * The value in Perceval persistent configuration

Return type:

str

Returns:

The stored provider

get_proxies()

Get the proxy configuration as a mapping of protocols to URLs.

Return type:

dict[str, str]

get_token()

Search a valid token from the environment, put it in cache and return it.

The priority for the token search is as follows: * A token already in cache (e.g. set by the user or already found in a previous call) * The value of the environment variable given by self.get_token_env_var() * The value in Perceval persistent configuration

Return type:

str

Returns:

The token

classmethod get_token_env_var()

Get the name of the environment variable storing a token.

Return type:

str

get_url()

Search a valid cloud URL from the environment, put it in cache and return it.

The priority for the URL search is as follows: * A URL already in cache (e.g. set by the user or already found in a previous call) * The value in Perceval persistent configuration

Return type:

str

Returns:

The cloud URL

save()

Save the current remote configuration on disk. After this, the configuration is persistent and can be found in other Perceval sessions (even in different virtual envs).

Return type:

None

classmethod set_provider(provider_name)

Set a provider name in the configuration cache. It is not saved on disk before the save method is called.

Parameters:

provider_name (str) – The provider to use by default

Return type:

None

static set_proxies(proxies)

Set the proxy configuration. The proxy configuration is shared between all configurations.

Usage example:

>>> rc = RemoteConfig()
>>> rc.set_proxies({"http": "http://user:pass@192.168.0.1",
...                 "https": "http://user:pass@192.168.0.1:8080"
...                })
Parameters:

proxies (dict[str, str]) – proxy configuration in the form of a dictionary which maps protocols to URLs

Return type:

None

classmethod set_token(token)

Set a user authentication token in the configuration cache. It is not saved on disk before the save method is called.

Parameters:

token (str) – The token

Return type:

None

classmethod set_token_env_var(env_var)

Change the name of the environment variable storing a token.

Parameters:

env_var (str) – name of the new environment variable to search for

Return type:

None

classmethod set_url(url)

Set a cloud URL in the configuration cache. It is not saved on disk before the save method is called.

Parameters:

url (str) – The cloud URL

Return type:

None

Legacy Session

Warning

Session belongs to the legacy processor workflow. New code should use ScalewayCommunicationLayer with RemoteComputer.

class perceval.providers.scaleway.scaleway_session.Session(platform_name, project_id, token=None, max_idle_duration_s=1200, max_duration_s=3600, deduplication_id=None, url=None, proxies=None, provider_name=None)

Scaleway session used to keep a connexion opened with Scaleway Cloud for the duration of a Python scope.

Parameters:
  • platform_name (str) – platform on which circuits will be executed

  • project_id (str) – UUID of the Scaleway Project the session is attached to

  • token (Optional[str]) – authentication token required to access the Scaleway API

  • deduplication_id (Optional[str]) – optional value, name mapping to a unique running session, allowing to share an alive session among multiple users

  • max_idle_duration_s (int) – optional value, duration in seconds that can elapsed without activity before the session terminates

  • max_duration_s (int) – optional value, duration in seconds for a session before it automatically terminates

  • url (Optional[str]) – optional value, endpoint URL of the API

  • proxies (Optional[dict[str, str]]) – optional value, dictionary mapping protocol to the URL of the proxy

build_remote_processor()

Build a RemoteProcessor object given the session data

Return type:

RemoteProcessor

start()

Start session

Return type:

None

stop()

Stop session

Return type:

None