Strangeworks Python SDK
strangeworks-python
Strangeworks SDK is responsible for handling authentication, fetching jobs and backends, transferring files, and calling product endpoints. It's a dependency of most Strangeworks product-specific Python packages, including Qiskit, Rigetti pyQuil, Amazon Braket, and more.
Installation
To get started, make sure you have Python 3.10 or 3.11 (installation) and are familiar with setting up and using virtual environments. You can easily install the Strangeworks SDK from PyPI with pip:
pip install -U pip && pip install strangeworks
Authentication
To access the Strangeworks API, you'll need your API key, which you can find in the Strangeworks Portal on the home page. Once you have it, simply authenticate like so:
import strangeworks as sw
sw.authenticate(api_key)
If you belong to multiple Workspaces, please be aware your API keys are different for each.
Usage
While you can use this package directly, it's most commonly used as a dependency of task-specific packages like Qiskit, Rigetti pyQuil, and Amazon Braket. You can find documentation for each of these packages on their product pages.
Jobs
Tagging
To enhance organization and searchability, you can assign tags to jobs a list of strings.
import strangeworks as sw
sw.add_tags(job_slug, ["tag1", "tag2"])
Retrieving
To retrieve a job by slug, use the jobs
method.
jobs = sw.jobs("slug")
To retrieve jobs by tag, use the tags
argument to pass a list of tags.
You can filter by multiple tags and specify whether to use AND
(default) or OR
for the search.
# andor = "AND"
job_list = sw.jobs(tags=["tag", "another-tag", "athird-tag"], tag_operator="AND")
# andor = "OR"
job_list = sw.jobs(tags=["tag", "another-tag", "athird-tag"], tag_operator="OR")
Errors
If the job status comes back as failed you can view the job page in the portal or use the Strangeworks SDK to retrieve the errors:
import strangeworks as sw
sw.get_error_messages(sw_job.slug)
Resources
The Strangeworks platform allows for the management of multiple resources within your current workspace. Resources are essentially computational assets that can be associated with different quantum computing products. Managing resources effectively enables you to optimize your quantum computing tasks by selecting the most suitable computational backend for each job.
List
resources()
This method retrieves a list of all resources available within the current workspace. Each resource is uniquely identified and can be associated with different products for quantum computing tasks.
Example of a resource:
Resource(slug='resource_slug', resource_id=None, status='ACTIVE', name=None, is_deleted=False, product=Product(slug='product_slug', product_id=None, name='Product Name'))
Multiple
While the platform supports the management of multiple resources, they are disabled by default to streamline the user experience and manage computational costs effectively. However, enabling and managing multiple resources can be particularly useful in scenarios where different tasks require different computational backends or when tasks are optimized for specific hardware.
To enable and manage multiple resources, users can specify the resource_slug
when associating a resource with a product, allowing for more granular control over the computational resources used for quantum computing tasks.
Set
set_resource_for_product(product_slug, resource_slug)
This method allows you to associate a specific resource with a product. Associating the right resource with a product is crucial for optimizing performance and resource utilization.
get_resource_for_product(product_slug)
Fetch the resource currently associated with a product. This is useful for verifying which resources are being utilized by different products.