Strangeworks SDK Hybrid Optimize Extension#

PyPI

The service uses the Strangeworks API accessed through the Strangeworks python SDK. For more information on the general python sdk see our docs.

To get started you will need to install the SDK and authenticate using your API key. Your API key can be found on the dashboard page of the Strangeworks platform at https://portal.strangeworks.com.

Installation#

The Peptide design SDK is installed from a private git repo using pip

pip install strangeworks-hybrid-optimize

Test your installation by running the following

$ python
>>> import strangeworks_hybrid_optimize
>>> print(strangeworks_hybrid_optimize.__version__)

Authentication#

Authenticate using the strangeworks.authenticate() method

$ python
>>> import strangeworks
>>> strangeworks.authenticate(api_key="<your-api-key>")

Basic Usage#

from strangeworks_hybrid_optimize import StrangeworksHybrid
import strangeworks_hybrid_optimize.utils as utils

strangeworks.authenticate(api_key=" ", store_credentials=False)
sw_qaoa = StrangeworksHybrid(resource_slug=" ")

################################
######## Create problem from QUBO
nodes = 10
seed = 0
n = 3
problem = utils.get_nReg_MaxCut_QUBO(n, nodes, seed)
################################

################################
######## Define algorithm parameters for sub-jobs
problem_params = {
    "maxiter": 50,  # Maximum number of iterations in algorithm
    "shotsin": 1000,  # Number of times quantum circuit is measured at each iteration
    "p": 1,              # Optional Input: Controls the depth of the Quantum Circuit ansatz. Default p=1
    "theta0": [1.0, 1.0],  # Optional Input: Starting point for variational parameters. If specified must be equal to 2p
    "alpha": 0.1,  # Optional Input: Cvar parameter, float between 0 and 1 - https://arxiv.org/pdf/1907.04769.pdf. Default alpha=1.0
    "optimizer": "COBYLA",  # Optional Input: Classical optimizer to use:
                            # Possible Values:
                            # 'COBYLA' (Default), 'Nelder-Mead', 'Powell', 'CG', 'BFGS', 'Newton-CG', 'L-BFGS-B', 'TNC',
                            # 'SLSQP', 'trust-constr', 'dogleg', 'trust-ncg', 'trust-exact', 'trust-krylov'
                            # Additionals for IBM backends: 'SPSA', 'NFT'
    "ising": False,  # Optional Input: is the problem an Ising problem or a QUBO problem, i.e. are the values of the variables {-1/2,+1/2} (Ising) or {0,1} (QUBO, Default)
    "warm_start": False,  # Optional Input: Run warm start qaoa or not - https://arxiv.org/abs/2009.10095. Default False: Standard QAOA ansatz
    }

################################
######## Define parameters for creating sub-problems and running final optimization
Nf = 2  # Size of final vqe
Ns = pow(2, Nf)  # Number of sub-systems, upper bound, Ns = pow(2, Nf)
Ng = 4  # Size of sub-systems

# Options for final vqe/qaoa, below are the additional options for this hybrid qaoa and the mandatory ones.
# Other optional arguments may be specifed: https://docs.strangeworks.com/apps/qaoa
hybrid_params = {
    "Nf": Nf,  # Size of final vqe
    "Ns": Ns,  # Number of sub-systems
    "Ng": Ng,  # Size of sub-systems
    "problem_size": nodes,  # Total problem size
    "type_subsystem": "weighted_random",  # How to break up problem into sub-problems
    "maxiter": 50,  # Maximum number of iterations in algorithm
    "shotsin": 1000,  # Number of times quantum circuit is measured at each iteration
}

# Currently need to specify the resource slug of the child-jobs
# Can either be and StrangeworksQAOA resource of a StrangeworksOptimize resource
sw_hybrid.add_sub_resource_credentials(resource_slug="your-child-job-resource-slug")

backend = "SV1" # Change this to another ibm backend name or an aws device name
sw_job = sw_hybrid.run(backend,
                    backend_sub=backend,
                    problem=problem,
                    hybrid_params=hybrid_params,
                    problem_params=sub_problem_params)

result = sw_qaoa.get_results(sw_job,calculate_exact_sol=True, display_results=True)

Python SDK Module Reference#