QUBOQAOA#
- class iqm.qaoa.qubo_qaoa.QUBOQAOA(problem, num_layers, *, betas=None, gammas=None, initial_angles=None)[source]#
Bases:
QAOAThe class for QAOA with quadratic unconstrained binary (QUBO) cost function.
The class inherits a lot of functionality from its parent
iqm.qaoa.generic_qaoa.QAOA. One new addition is the attributebqmwhich stores the coefficient of the problem Hamiltonian. The same data in the form ofGraphishamiltonian_graph.- Parameters:
problem (QUBOInstance | ConstrainedQuadraticInstance) – A
QUBOInstanceobject describing the QUBO problem to be solved.num_layers (int) – The number of QAOA layers, commonly referred to as p in the literature.
betas (Sequence[float] | ndarray | None) – An optional list of the initial beta angles of QAOA. Has to be provided together with
gammas.gammas (Sequence[float] | ndarray | None) – An optional list of the initial gamma angles of QAOA. Has to be provided together with
betas.initial_angles (Sequence[float] | ndarray | None) – An optional list of the initial QAOA angles as one variable. Shouldn’t be provided together with either
betasorgammas. The gamma and beta angles are interleaved, so that the first pair of entries corresponds to \(\gamma_1\) and \(\beta_1\) (the angles of the first QAOA layer). The second pair of entries corresponds to \(\gamma_2\) and \(\beta_2\), etc. …
Attributes
The BQM representation of the problem, taken from the input
QUBOInstance.The graph whose edges / nodes have weights
biasequal to the coefficients in the problem Hamiltonian.Returns an upper-triangular matrix of the ZZ interactions between the variables.
Returns a
ndarrayof the local fields of the model (Z coefficients).Methods
estimate(estimator, **kwargs)The method for taking estimates of the expected value of the Hamiltonian from the QAOA circuit.
sample(sampler[, shots])The method for taking samples (i.e., measurement results) from the QAOA circuit.
train([estimator, min_method])The function that performs the training of the angles.
- property hamiltonian_bqm: BinaryQuadraticModel#
The BQM representation of the problem, taken from the input
QUBOInstance.
- property hamiltonian_graph: Graph#
The graph whose edges / nodes have weights
biasequal to the coefficients in the problem Hamiltonian.
- property interactions: ndarray#
Returns an upper-triangular matrix of the ZZ interactions between the variables.
If the Hamiltonian representing the problem is
\[H = \sum_{i<j} J_{ij} Z_i Z_j + \sum_i h_i Z_i\]then this method outputs \(J_{ij}\) as upper-triangular square matrix
ndarray. Note that these are different from the off-diagonal elements ofqubo_matrixof the inputproblembecause the QUBO cost function has different coefficients than the Hamiltonian.
- property local_fields: ndarray#
Returns a
ndarrayof the local fields of the model (Z coefficients).If the Hamiltonian representing the problem is
\[H = \sum_{i<j} J_{ij} Z_i Z_j + \sum_i h_i Z_i\]then this method outputs \(h_{i}\) as 1-dimensional
ndarray. Note that these are different from the diagonal elements ofqubo_matrixof the inputproblembecause the QUBO cost function has different coefficients than the Hamiltonian.
- train(estimator=None, min_method='COBYLA', **kwargs)[source]#
The function that performs the training of the angles.
The training modifies
anglesin-place using theminimize()function fromscipy. The training uses the providedestimator.- Parameters:
estimator (EstimatorBackend | None) – An estimator
EstimatorBackendto be used to calculating expectation values for the minimization.min_method (Literal['Nelder-Mead', 'nelder-mead', 'Powell', 'powell', 'CG', 'cg', 'BFGS', 'bfgs', 'Newton-CG', 'newton-cg', 'L-BFGS-B', 'l-bfgs-b', 'TNC', 'tnc', 'COBYLA', 'cobyla', 'COBYQA', 'cobyqa', 'SLSQP', 'slsqp', 'Trust-Constr', 'trust-constr', 'Dogleg', 'dogleg', 'Trust-NCG', 'trust-ncg', 'Trust-Exact', 'trust-exact', 'Trust-Krylov', 'trust-krylov']) – The minimization method passed to the
minimize()function.**kwargs (Any) – The keyword arguments to pass to the
estimator’sestimate().
- Return type:
None
- sample(sampler, shots=20000, **kwargs)[source]#
The method for taking samples (i.e., measurement results) from the QAOA circuit.
Takes a
SamplerBackendand uses it to getshotssamples. The backend is responsible for building the quantum circuit and taking the measurements (or obtaining the samples some other way), using information from theQAOAobject that is passed to its methodsample().- Parameters:
sampler (SamplerBackend) – The sampler to use to generate samples. The sampler is an instance of a subclass of
SamplerBackendwith asample()method of the appropriate signature.shots (int) – The number of shots to be taken.
**kwargs (Any) – Extra arguments to pass to the sampler. Mostly intended for
seed_transpilerfor samplers that includeqiskittranspilation.
- Returns:
A dictionary whose keys are bitstrings representing the samples and whose values are their respective frequencies, so that the sum of the values of the dictionary equals to
shots.- Return type:
- estimate(estimator, **kwargs)[source]#
The method for taking estimates of the expected value of the Hamiltonian from the QAOA circuit.
Takes a
EstimatorBackendand uses it to get estimates of the expected value. The backend takes all the necessary information from theQAOAobject that is passed to its methodestimate().- Parameters:
estimator (EstimatorBackend) – The estimator used to get the expected value. The estimator is an instance of a subclass of
EstimatorBackendwith a methodestimate()of the appropriate signature.**kwargs (Any) – Optional keyword arguments to be passed to the
estimator. Mostly relevant for when the estimators isEstimatorFromSampler, the sampler isSamplerResonanceand we want to specify parameters of the transpilation on the Resonance QPU.
- Returns:
An estimate of the expectation value fo the Hamiltonian. Not normalized in any way.
- Return type: