qat.opt.MWIS

class qat.opt.MWIS(graph, weights=None)

The class allows for the representation of a Maximum Weighted Independent Set (MWIS) problem in the Rydberg framework, by providing a systematic way to embed any graph into a unit disk graph and realizing a one-to-one matching with a Rydberg atom system. The embedding procedure is called the crossing lattice. The Rydberg Hamiltonian writes,

\[H = \sum_v \frac{\Omega_v}{2}\sigma_v^x - \sum_v \Delta_v n_v + \sum_{v, w}U_{vw}n_v n_w\]

where \(\Omega_v\) is the rabi frequency, \(\Delta_v\) the detuning and \(U_{vw}\) the elements of the coupling matrix between atoms. It is quite close to the energy minimization representation of a MWIS problem.

\[H = -\sum_{v \in V} \delta_v n_v + \sum_{(u, v) \in E} U_{uv} n_u n_v\]

where \(V\) is the set of vertices of the graph, \(E\) the set of edges and \(\delta_v\) the node weights. In such a form, we can derive an Ising formulation of any MWIS problem, which is why this class inherits from the Ising object. It can also be translated to a QUBO object via to_qubo().

This class generates a new type of job different from the classes Ising and QUBO called 'ryd' jobs.

Parameters
  • graph (nx.Graph) – input graph from which we will find the MWIS.

  • weights (dict) – dictionary of the weights of each note. No weights by default.

graph

weighted graph attribute

Type

nx.Graph

aqo_job(tmax=None, mixing=None, **kwargs)

Generates an Adiabatic Quantum Optimization (AQO) job performing a linear interpolation between an initial mixing Hamiltonian and the problem’s Hamiltonian.

classmethod decode_rydberg(job, result)

Returns the MWIS simulation result of the input graph.

Parameters
  • job (Job) – generated job

  • result (Result) – result of the simulation of the crossing lattice graph.

Returns

MWIS simulation result of the input graph.

Return type

Result

static decode_rydberg_meta_data(meta_data: dict, result)

Returns the MWIS simulation result of the input graph.

Parameters
  • meta_data (dict[str, str]) – generated job meta_data

  • result (Result) – result of the simulation of the crossing lattice graph

Returns

MWIS simulation result of the input graph

Return type

Result

dump(fname)

Dumps the ising in a binary file (.circ)

Parameters

fname (str) – the file name

classmethod from_thrift(tobject)

Builds an Ising object out of a thrift Ising object. Does so in place.

get_best_parameters()

A method returning a dictionary with the best annealing parameters found thus far after benchmarking for the respective Ising problem. If the method is called directly from the parent Ising class and not from one of the child problem classes (e.g. MaxCut, NumberPartitioning, etc.), it will raise an exception.

get_j_h_and_offset()

This method returns the \(J\) coupling matrix, the magnetic field \(h\) and Ising energy offset, which define the Ising object.

Returns

3-element tuple containing

  • J (2D numpy array) - a symmetric array with zero diagonal elements for the

    coupling between each two spins - it represents the \(J\) matrix from the Hamiltonian of the problem

  • h (1D numpy array) - an array with the magnetic field acting on each of the

    spins, coming from the Hamiltonian of the problem

  • offset_i (double) - the value of the Ising offset energy in the respective

    Hamiltonian

get_observable(obs_type)

Returns an ising- or a terms-type of Observable from the Ising problem. If a ‘terms’ Observable is chosen, the Ising problem will first be translated to a CombinatorialProblem.

Parameters

obs_type (string) –

The type of Observable to be returned: 'ising' or 'terms'.

  • 'ising' observables can be used to create a Schedule (by also proving gamma_t if SQAQPU will be used) and consecutively produce a Job to be sent for Simulated Quantum Annealing.

  • 'terms' observables can be used for gate-based quantum computations with a Circuit or analog quantum computations, also with a Schedule.

Returns

an Ising Observable or an Observable with terms representing the problem

Return type

Observable

property j_coupling_matrix

The J-coupling of the Ising Hamiltonian as a symmetric numpy 2D array with zero diagonal elements.

classmethod load(fname)

Loads an ising from a binary file.

Parameters

fname (str) – the file name

Returns

an ising object

Return type

Ising

property magnetic_field_h

The magnetic field h of the Ising Hamiltonian as a numpy 1D array

qaoa_job(depth, cnots=True, strategy='coloring', to_circ_args=None, **kwargs)

Generates a QAOA Ansatz Job for gate-based computations using the cost observable returned by the abstract method get_observable.

Warning

When setting the cnots option to False, the circuit might make use of generalized many-qubits Z rotations. In that case, you might want to instantiate your variational plugins using a gate set that contains definition of these gates. If not, some matrices in the circuit structure will be missing and some QPUs may not be able to handle the circuit.

The following piece of code should allow you to link the correct gate set to a variational plugin:

from qat.plugins import ScipyMinimizePlugin
from qat.vsolve.ansatz import get_qaoa_gate_set

# This plugin will no be able to bind variables inside a
# job generated with cnot set to False!
my_plugin = ScipyMinimizePlugin()

# This plugin can now be used with job generated with the
# cnots option sets to False!
my_plugin = ScipyMinimizePlugin(gate_set=get_qaoa_gate_set())
Parameters
  • depth (int) – the depth of the Ansatz

  • strategy (str) – the strategy to adopt to generate the circuit. Possible strategies are “default” or “coloring”. The “coloring” strategy uses a greedy coloring heuristics to try to optimize the overall depth of the Ansatz. Default is “default” which synthesize the circuit without optimizing the term ordering.

  • cnots (optional, bool) – If set to True the Ansatz will only use CNOT gates. If set to False, some abstract gates will be used to generate collective pauli rotations, resulting in a lower gate count. Defaults to True.

  • **kwargs – optional arguments that will be transfered to the job’s constructor (e.g nbshots, etc).

Returns

a Qaptiva job, ready to run

Return type

Job

ryd_job(optimize=True, time_budget_sec=3, tmax=10, **kwargs)

Returns a ryd-type job for the MWIS problem - ready to run with the AnalogQPU

Parameters
  • optimize (bool) – if True, the node overhead will be reduced.

  • time_budget_sec (float) – time budget allocated for the core part of the optimization function.

  • tmax (float) – time duration of the adiabatic simulation.

Returns

a ryd-type job

Return type

Job

sqa_job(gamma_t=None, tmax=1.0, **kwargs)

Returns a sqa-type of Job for the problem - ready to run with SQAQPU.

Parameters
  • tmax (float, optional) – time duration of the annealing. Default is 1.

  • gamma_t (ArithExpression, optional) – a function specifying the time dependence of Gamma. It should be produced using the variable ‘t’ created by the class Variable.

Returns

a ready to run sqa-type of Job for the problem

Return type

Job

Note

For the supported NP problems, some well performing max and min Gamma (for a linearly decreasing gamma_t) have been found and could be accessed via the method get_best_parameters of the respective problem class.

to_bqm()

Transforms an Ising problem to DWave’s Binary Quadratic Model from the library dimod.

Returns

a BinaryQuadraticModel object

Return type

BinaryQuadraticModel

to_combinatorial_problem()

Translates the Ising problem into a CombinatorialProblem.

Returns

a combinatorial problem instance

Return type

CombinatorialProblem

to_job(job_type, *args, **kwargs)

A general method allowing the creation of an aqo-, qaoa- or sqa-type of Job from a problem description - ready to run on the respective QPU.

  • 'aqo' is for Adiabatic Quantum Optimization (with analog QPUs). Internally, method aqo_job() is used to generate the job.

  • 'qaoa' is for using the Quantum Approximate Optimization Algorithm (with gate-based QPUs). Internally, method qaoa_job() is used to generate the job.

  • 'sqa' is for Simulated Quantum Annealing (with SQAQPU). Internally, method sqa_job() is used to generate the job.

  • 'ryd' is for Rydberg (with AnalogQPU). Internally, method ryd_job() is used to generate the job.

Parameters
Returns

a ready to run Job for the respective type of problem

Return type

Job

to_qubo()

Translates the Ising problem into a QUBO problem.

Returns

a QUBO object

Return type

QUBO