Strangeworks SDK for Python
strangeworks-python
Strangeworks SDK for Python is responsible for handling authentication, fetching jobs and backends, transferring files, and calling product endpoints.
pip install -U pip && pip install strangeworks
Authentication
You'll need your API key, which is found on the Strangeworks Portal home page.
import strangeworks as sw
sw.authenticate(api_key)
If you belong to multiple Workspaces, please be aware your API keys are different for each.
Managing Jobs
Tagging Jobs
To enhance organization and searchability, you can assign a list of tags to a job.
import strangeworks as sw
sw.add_tags(job_slug, ["tag1", "tag2"])
Retrieve Jobs
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 a job fails, view the job page in the portal or retrieve the errors in Python
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
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'))
Select Resource
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_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.