Skip to main content

No project description provided

Project description

Entropica Labs Loom API Client

A frontend API for generating QEC Loom Experiments. Use of this client requires a valid API token and API URL.

If you would like access to the Loom APIs, get in touch with us at Entropica Labs.

Configuration

The client reads the configuration required to establish successful connections from (in order of precedence): inline constructor arguments, environment variables, environment variables from an .env file, the configuration file located in the user's home folder at ~/.loom/config.json. There are no default values for the configuration options, so you must provide them in one of the ways described below.

We don't recommend passing the configuration options directly to the client constructor, unless you know what you are doing and understand the security implications of exposing your API token in code that may be committed to a repository or shared.

Example:

from el_loom_api_client import LoomClient

# Will read from environment variables or configuration file, if they exist, in that order
client = LoomClient()

# Will use the provided values, overriding any environment variables or configuration file
client = LoomClient(api_url="https://api.example.com", api_token="**********")

# Override only the API token if `api_url` is already set in environment variables or configuration file
client = LoomClient(api_token="********")

Using a configuration file [RECOMMENDED]

File location: ~/.loom/config.json

{
    "api_url": "https://api.example.com",
    "api_token": "**********"
}

You can create the configuration file in your user's home folder with the following commands:

MacOS/Linux:

mkdir -p ~/.loom && echo '{"api_url": "https://api.example.com", "api_token": "**********"}' > ~/.loom/config.json

Windows:

New-Item -Path "$HOME\.loom" -ItemType Directory -Force
Set-Content -Path "$HOME\.loom\config.json" -Value '{"api_url": "https://api.example.com", "api_token": "**********"}'

Edit the files to replace the example values with your actual API URL and API token.

Create the client without passing any arguments to the constructor:

from el_loom_api_client import LoomClient

client = LoomClient()

From environment variables or .env file

export LOOM_API_URL="https://api.example.com"
export LOOM_API_TOKEN="**********"

These variables can also be set in a .env file in the current working directory, which will be automatically loaded by the client, without the export statement.

NOTE: if only one of the two variables is set, the client will try reading the missing variable from the configuration file.

Create the client without passing any arguments to the constructor:

from el_loom_api_client import LoomClient

client = LoomClient()

Using the client

In order to use the client, you should have already obtained a valid API token and the API URL and configured the client as described before.

To create a client to interact with the Loom APIs, you can use the LoomClient or the AsyncLoomClient classes.

The client implements the context-manager protocol. Use with (or async with for the async client) to automatically close connections when the block exits. Alternatively, close it explicitly with close() (sync) or aclose() (async).

Once closed, the client instance cannot be used again and a new instance must be created.

Synchronous client example:

from el_loom_api_client import LoomClient

# Recommended: use the client as a context manager
with LoomClient() as client:
    # Use the client here
    pass
# Connection is automatically closed here

# Alternative: manually close the client
client = LoomClient()
try:
    # Use the client here
    pass
finally:
    # Manually close the client when done
    client.close()

Asynchronous client example:

from el_loom_api_client import AsyncLoomClient

# Recommended: use the client as a context manager
async with AsyncLoomClient() as client:
    # Use the client here
    pass
# Connection is automatically closed here

# Alternative: manually close the client
client = AsyncLoomClient()
try:
    # Use the client here, with the `await` keyword as needed
    pass
finally:
    # Manually close the client when done (note: this is an async `aclose` method)
    await client.aclose()

Run a QEC experiment

Using the provided models and the client, you can build and run a QEC experiment.

The following example shows how to create a simple QEC memory experiment using the MemoryExperiment model and submit it to the Loom API.

from el_loom_api_client import LoomClient
from el_loom_api_client.models import (
    Code,
    Decoder,
    MemoryExperiment,
    NoiseParameters,
)

# Create client using context manager (recommended)
with LoomClient() as client:
    # Build the experiment model
    experiment = MemoryExperiment(
        qec_code=Code.ROTATEDSURFACECODE,
        distance=3,
        num_rounds=[3, 5, 7],
        memory_type="Z",
        decoder=Decoder.PYMATCHING,
        noise_parameters=[
            NoiseParameters(depolarizing=0.01, measurement=0.01, reset=0.01),
            NoiseParameters(depolarizing=0.05, measurement=0.05, reset=0.05),
        ],
        gate_durations={"x": 3e-8, "cx": 2e-7},
    )

    # Submit the experiment to the Loom API
    run_id = client.experiment_run(experiment)

    # Check the status of the experiment
    status = client.get_experiment_run_status(run_id)

    # Wait for the result
    # Will poll the API for the status until the experiment is complete and fetch the result
    result = client.wait_for_experiment_run_result(run_id)

    # Print the result
    print(result)

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

el_loom_api_client-0.3.0.tar.gz (21.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

el_loom_api_client-0.3.0-py3-none-any.whl (24.3 kB view details)

Uploaded Python 3

File details

Details for the file el_loom_api_client-0.3.0.tar.gz.

File metadata

  • Download URL: el_loom_api_client-0.3.0.tar.gz
  • Upload date:
  • Size: 21.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.3

File hashes

Hashes for el_loom_api_client-0.3.0.tar.gz
Algorithm Hash digest
SHA256 277d8dc2722a427a0e0270511375bb4363c4b5fea966091f0a0ad184363debc4
MD5 c26cc219b735682858bc6d57059004c2
BLAKE2b-256 b834197cdbab8bce188212c160bff81b93a83b8654374f995d59429c34d4ad58

See more details on using hashes here.

File details

Details for the file el_loom_api_client-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for el_loom_api_client-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b73ce3e92dc4d157650d7d7678e7ce7e351aa7ea37226db526c8bea1426175e9
MD5 1899befc3a72137585557e4b371ebb9b
BLAKE2b-256 33417575fe26a5687753f388f88b9ed60cf83093fe6c9009f5162ae7df983e4d

See more details on using hashes here.

Supported by

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