strangeworks_hybrid_optimize package

Submodules

strangeworks_hybrid_optimize.sdk module

class HybridParams(Nf: int, Ns: int, Ng: int, problem_size: int, maxiter: int, shotsin: int, type_subsystem: str | None = None, theta0: List[float] | None = None, optimizer: str | None = None, ansatz: str | None = None, optimization_level: int | None = 1, resilience_level: int | None = 1)

Bases: object

class OptimizationParams(solver: dict, bqm: BinaryQuadraticModel | None = None, options: dict | None = None)

Bases: object

class QAOAParams(maxiter: int, shotsin: int, theta0: List[float] | None = None, p: int | None = None, alpha: float | None = None, optimizer: str | None = None, ansatz: str | None = None, ising: bool | None = None, warm_start: bool | None = None, problem_type: str | None = 'Classical', optimization_level: int | None = 1, resilience_level: int | None = 1)

Bases: object

class StrangeworksHybrid(resource_slug: str | None = ' ')

Bases: object

Strangeworks client object.

backends()
get_job(sw_job)
get_results(sw_job, calculate_exact_sol=False, display_results=False)
job_list()
run(backend, problem, hybrid_params, problem_params: QAOAParams | OptimizationParams, backend_sub: str | None = None)

Method to submit QAOA problem to backend.

Parameters:
  • backend (str) – Backend name for the final QAOA optimization step. Must be a

  • device. (gate based)

  • problem – Hamiltonian whose ground state we want to find. Can be either a networkx graph, a qiskit PauliSumOp operator, a QUBO Matrix or a Dwave BinaryQuadraticModel.

  • hybrid_params (Dict) –

    Dictionary of hybrid parameters for the problem: Nf (int): Size of final vqe Ns (int): Number of sub-systems: Upper bound = np.pow(2, Nf) Ng (int): Size of sub-systems problem_size (int): Number of qubits in the problem type_subsystem (str): Type of subsystems to use. Options are:

    ’random’, ‘weighted_random’, ‘kernighan_lin_bisection’

    maxiter (int): max number of iteration loops in minimisation shotsin (int): number of shots. Number of times quantum circuit is

    run and measured

  • problem_params (Dict) – Dictionary of sub problem parameters for the problem

  • job (or 2) the parameters for a StrangeworksOptimization)

  • job

    1. StrangeworksQAOA job parameters:

      shotsin (int): number of shots. Number of times quantum circuit is run and measured maxiter (int): max number of iteration loops in minimisation p (int): Optional. Number of repetitions in qaoa ansatz alpha (float): Optional. Parameter between 0 and 1, which controls the CVar expectation value,

      alpha = 1, usual expectation value alpha < 1, modified expectation value for quantum simulation with classical outputs

      theta0 (array): Optional, initial vector of parameters. optimizer (str): Optional, string specifying classical optimizer,

      default=’COBLYA’.

      ansatz (str or QuantumCircuit): Optional, Variational circuit

      parametrized with coefficients to optimise for the energy

      ising (bool): Optional, If True then the input problem is treated as

      an Ising problem. If False or unspecified, then the input problem is treated as a QUBO problem.

      problem_type (str): Optional, If the problem is a quantum encoding

      of a classical problem (i.e. the solution is one of the basis states) then we can make some simplifications and employ some tricks to make the algorithm potentially more optimal.

      optimization_level: IBM only. How much optimization to perform on

      the circuits. Higher levels generate more optimized circuits, at the expense of longer transpilation times. This is based on the optimization_level parameter in qiskit-terra but may include backend-specific optimization. Default: 1.

      • 0: no optimization

      • 1: light optimization

      • 2: heavy optimization

      • 3: even heavier optimization

      resilience_level: IBM only. How much resilience to build against

      errors. Higher levels generate more accurate results, at the expense of longer processing times. Default: 1.

      • 0: No mitigation.

      • 1: Minimal mitigation costs. Mitigate error

      associated with readout errors. * 2: Medium mitigation costs. Typically reduces bias in estimators but is not guaranteed to be zero bias. Only applies to estimator. * 3: Heavy mitigation with layer sampling. Theoretically expected to deliver zero bias estimators. Only applies to estimator.

    2. StrangeworksOptimization job parameters:

      var_type (str): Variable type of the problem. Either ‘BINARY’ or lagrange_multiplier (float): Lagrange multiplier for the problem. solver (Dict): Dictionary of solver parameters:

      solver (str): Name of the solver to use. Must be one of the

      available solvers for the backend.

      solver_options (Dict): Dictionary of solver options.

Returns:

Strangeworks Job object

update_status(sw_job)

strangeworks_hybrid_optimize.utils module

convert_QUBO_to_Ising(QUBO_mat)
get_Ham_from_PauliSumOp(H_pauliSum)
get_Ham_from_QUBO(QUBO_mat)
get_Ham_from_graph(G)
get_Ising(G)
get_PauliSumOp(G)
get_QUBO(G)
get_QUBO_from_Ham(H, nodes)
get_cost_bitstring(bitstring, problem, ising=False)
get_energy(x, H, ising=False)

Get the energy of the quantum state

Parameters:
  • x (str) – bitstring of ones and zeros

  • H (List) – Hamiltonian which we are to find the minimum value

Returns:

energy of the state x.

Return type:

En (float)

get_exact_en(G, nodes, ising=False)
get_graph(nodes, seedin)

Generate networkX graph where each node is connected to all other nodes. The weights of the connections are random and uniformly distributed between -1 to 1

get_graph_from_Ham(H, nqubits)
get_nReg_MaxCut_PauliSumOp(n, nodes, seedin)

Generate PauliSumOp where each node has n connections to a random slection of the other nodes. The weights of the connections are random and uniformly distributed between -1 to 1

get_nReg_MaxCut_QUBO(n, nodes, seedin)

Generate QUBO matrix where each node has n connections to a random slection of the other nodes. The weights of the connections are random and uniformly distributed between -1 to 1

get_nReg_MaxCut_graph(n, nodes, seedin)

Generate networkX graph where each node has n connections to a random slection of the other nodes. The weights of the connections are random and uniformly distributed between -1 to 1

get_rand_PauliSumOp(nodes, seedin)

Generate random PauliSumOp The weights of the connections are random and uniformly distributed between -1 to 1

get_rand_QUBO(nodes, seedin)

Generate random QUBO matrix The weights of the connections are random and uniformly distributed between -1 to 1

Module contents

Strangeworks QAOA SDK Extension.