Strangeworks for Python
Whether using Optimization or Quantum backends, Strangeworks SDK for Python is responsible for handling authentication, fetching jobs and backends, transferring files, and calling product endpoints.
pip install -U pip strangeworks
Authenticate
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.
Resources
Product Catalog
Resources are the computational assets or applications associated by a product in our catalog.
If you have not yet activated a resource, take a look at the 📖 Product Catalog to find one you would like to activate.
Look at the 🔮 Resources Portal to see available resources.
resources()This method retrieves a list of all resources available within the current workspace. Typically, a workspace will have only one resource per product.
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 Resources
While the platform supports the management of multiple resources, they are disabled by default.
Enabling and managing multiple resources may be useful in scenarios where different users require different controls over the allocation of resources.
To enable and manage multiple resources, users can specify the resource_slug when associating a resource with a product.
set_resource_for_product(product_slug, resource_slug)This method allows you to associate a specific resource with a product.
get_resource_for_product(product_slug)Fetch the resource currently associated with a product.
To enable multiple resources, please contact support.
Jobs
Jobs can be managed through the Jobs Portal.
Tagging
When a job is created, it will automatically be given a tag for the resource it was run on.
To enhance organization and analysis, additional tags can be added to a job.
This can be useful for filtering jobs by resource, project, or other criteria.
add_tags(job_slug, tags)
import strangeworks as sw
sw.add_tags(job_slug, ["tag1", "tag2"])
Fetch AND
To retrieve a job by slug, use the jobs method.
jobs = sw.jobs("slug")
To retrieve jobs with multiple tags using AND logic (all tags must match), use the tags argument with tag_operator="AND" (this is the default behavior).
# All tags must match
job_list = sw.jobs(tags=["tag", "another-tag", "athird-tag"], tag_operator="AND")
Fetch OR
To retrieve jobs that match any of the specified tags, use the tags argument with tag_operator="OR".
# Any tag can match
job_list = sw.jobs(tags=["tag", "another-tag", "athird-tag"], tag_operator="OR")
Debugging
If a job fails, view the job page in the portal or retrieve the errors using the get_error_messages method.
import strangeworks as sw
sw.get_error_messages(sw_job.slug)