QAOA Parametrisations

We currently offer 7 different parametrisations for QAOA, which can be found in the openqaoa.qaoa_components.variational_parameters module. They fall broadly into three categories:

Except for the Annealing parameters, each class also comes in three levels of detail:

  • StandardParams and FourierParams offer the \(\gamma\) ‘s and \(\beta\)’s as proposed in above papers.

  • StandardWithBiasParams and FourierWithBiasParams allow for extra \(\gamma\)’s for possible single-qubit bias terms, resp. their discrete sine transform.

  • ExtendedParams and FourierExtendedParams offer full control by having a seperate set of rotation angles for each term in the cost and mixer Hamiltonians, respective having a seperate set of Fourier coefficients for each term.

   ExtendedParams   <--------- FourierExtendedParams
          ^                         ^
          |                         |
StandardWithBiasParams <------ FourierWithBiasParams
          ^                         ^
          |                         |
    StandardParams  <----------- FourierParams
          ^
          |
    AnnealingParams

Parameters

class openqaoa.qaoa_components.ansatz_constructor.baseparams.AnsatzDescriptor(algorithm)[source]

Parameters class to construct a specific quantum ansatz to attack a problem

Parameters:

algorithm (str) – The algorithm corresponding to the ansatz

algorithm
Type:

str

abstract property n_qubits: int
class openqaoa.qaoa_components.ansatz_constructor.baseparams.QAOADescriptor(cost_hamiltonian, mixer_block, p, mixer_coeffs=[], routing_function=None, device=None)[source]

Create the problem attributes consisting of the Hamiltonian, QAOA ‘p’ value and other specific parameters.

cost_hamiltonian
Type:

Hamiltonian

qureg
Type:

List[int]

cost_block_coeffs
Type:

List[float]

cost_single_qubit_coeffs
Type:

List[float]

cost_qubits_singles
Type:

List[str]

cost_pair_qubit_coeffs
Type:

List[float]

cost_qubits_pairs
Type:

List[str]

mixer_block_coeffs
Type:

List[float]

cost_blocks
Type:

List[RotationGateMap]

mixer_blocks
Type:

List[RotationGateMap]

Properties
----------
n_qubits
Type:

int

abstract_circuit
Type:

List[RotationGateMap]

property abstract_circuit
static block_setter(input_object, block_type)[source]

Converts a Hamiltonian Object into a List of RotationGateMap Objects with the appropriate block_type and sequence assigned to the GateLabel

OR

Remaps a list of RotationGateMap Objects with a block_type and sequence implied from its position in the list.

Parameters:
  • input_object (Union[List[RotationGateMap], Hamiltonian]) – A Hamiltonian Object or a list of RotationGateMap Objects (Ordered according to their application order in the final circuit)

  • block_type (Enum) – The type to be assigned to all the RotationGateMap Objects generated from input_object

Return type:

List[RotationGateMap]

property n_qubits: int
reorder_gates_block(gates_block, layer_number)[source]

Update the qubits that the gates are acting on after application of SWAPs in the cost layer

static route_gates_list(gates_to_route, device, routing_function)[source]

Apply qubit routing to the abstract circuit gate list based on device information

Parameters:
  • gates_to_route (List[GateMap]) – The gates to route

  • device (DeviceBase) – The device on which to run the circuit

  • routing_function (Callable) – The function that accepts as input the device, problem, initial_mapping and outputs the list of gates with swaps

Return type:

List[GateMap]

static set_block_sequence(input_gatemap_list)[source]

This method assigns the sequence attribute to all RotationGateMap objects in the list. The sequence of the GateMaps are implied based on their positions in the list.

Parameters:

input_gatemap_list (List[RotationGateMap]) – A list of RotationGateMap Objects

Return type:

List[RotationGateMap]

Standard Parameters

class openqaoa.qaoa_components.variational_parameters.standardparams.QAOAVariationalStandardParams(qaoa_descriptor, betas, gammas)[source]

QAOA parameters that implement a state preparation circuit with

\[e^{-i \beta_p H_0} e^{-i \gamma_p H_c} \cdots e^{-i \beta_0 H_0} e^{-i \gamma_0 H_c}\]

This corresponds to the parametrization used by Farhi in his original paper [https://arxiv.org/abs/1411.4028]

Parameters:
  • qaoa_descriptor (QAOADescriptor) – QAOADescriptor object containing circuit instructions

  • betas (List[Union[float, int]]) – List of p betas

  • gammas (List[Union[float, int]]) – List of p gammas

betas

1D array with the betas from above

Type:

np.array

gammas

1D array with the gamma from above

Type:

np.array

asdict()

Return the parameters as a dictionary.

Returns:

The parameters as a dictionary. Has the same output format as the expected input of self.update_from_dict.

Return type:

dict

convert_to_ext(args_std)[source]

Method that converts a list of parameters in the standard parametrisation form (args_std) to an equivalent list of parameters in the extended parametrisation form.

Parameters:

args_std – Parameters (a list of float) in the standard parametrisation form.

Returns:

Parameters (a list of float) in the extended parametrisation form.

Return type:

args_ext

property cost_1q_angles

2D array with the Z-rotation angles.

1st index goes over the p and the 2nd index over the qubits, to apply Z-rotations on.

property cost_2q_angles

2D array with ZZ-rotation angles.

1st index goes over the p and the 2nd index over the qubit pairs, to apply ZZ-rotations on.

classmethod empty(qaoa_descriptor)[source]

Initialise Standard Variational params with empty arrays

classmethod from_other_parameters(params)

Alternative to __init__ that takes parameters with less degrees of freedom as the input.

Parameters:

params (QAOAVaritionalBaseParams) – The input parameters object to construct the new parameters object from.

Returns:

The converted paramters s.t. all the rotation angles of the in and output parameters are the same.

Return type:

QAOAVariationalBaseParams

classmethod linear_ramp_from_hamiltonian(qaoa_descriptor, time=None)[source]
Returns:

A StandardParams object with parameters according to a linear ramp schedule for the Hamiltonian specified by register, terms, weights.

Return type:

StandardParams

property mixer_1q_angles

2D array with the X-rotation angles.

1st index goes over p and the 2nd index over the qubits, to apply X-rotations on.

property mixer_2q_angles

2D array with the XX and YY-rotation angles.

1st index goes over p and the 2nd index over the qubit pairs, to apply XX and YY-rotations on.

plot(ax=None, **kwargs)[source]

Plots self in a sensible way to the canvas ax, if provided.

Parameters:
  • ax (matplotlib.axes._subplots.AxesSubplot) – The canvas to plot itself on

  • kwargs – All remaining keyword arguments are passed forward to the plot function

classmethod random(qaoa_descriptor, seed=None)[source]
Returns:

Randomly initialised StandardParams object

Return type:

StandardParams

raw()[source]

Return the parameters in a 1D array.

This 1D array is needed by scipy.optimize.minimize which expects the parameters that need to be optimized to be a 1D array.

Returns:

The parameters in a 1D array. Has the same output format as the expected input of self.update_from_raw. Hence corresponds to the flattened parameters in __init__()

Return type:

np.array

raw_rotation_angles()

Flat array of the rotation angles for the memory map for the parametric circuit.

Returns:

Returns all single rotation angles in the ordering (x_rotation_angles, gamma_singles, zz_rotation_angles) where x_rotation_angles = (beta_q0_t0, beta_q1_t0, ... , beta_qn_tp) and the same for z_rotation_angles and zz_rotation_angles

Return type:

np.array

update_from_dict(new_values)

Update all the parameters from a dictionary.

The input has the same format as the output of self.asdict().

Parameters:

new_values (dict) – A dictionary with the new parameters. Must have the same keys as the output of self.asdict().

update_from_raw(new_values)[source]

Update all the parameters from a 1D array.

The input has the same format as the output of self.raw(). This is useful for scipy.optimize.minimize which expects the parameters that need to be optimized to be a 1D array.

Parameters:

new_values (Union[list, np.array]) – A 1D array with the new parameters. Must have length len(self) and the ordering of the flattend parameters in __init__().

class openqaoa.qaoa_components.variational_parameters.standardparams.QAOAVariationalStandardWithBiasParams(qaoa_descriptor, betas, gammas_singles, gammas_pairs)[source]

QAOA parameters that implement a state preparation circuit with

\[e^{-i \beta_p H_0} e^{-i \gamma_{\textrm{singles}, p} H_{c, \textrm{singles}}} e^{-i \gamma_{\textrm{pairs}, p} H_{c, \textrm{pairs}}} \cdots e^{-i \beta_0 H_0} e^{-i \gamma_{\textrm{singles}, 0} H_{c, \textrm{singles}}} e^{-i \gamma_{\textrm{pairs}, 0} H_{c, \textrm{pairs}}}\]

where the cost hamiltonian is split into \(H_{c, \textrm{singles}}\) the bias terms, that act on only one qubit, and \(H_{c, \textrm{pairs}}\) the coupling terms, that act on two qubits.

Parameters:
  • qaoa_descriptor (QAOADescriptor) – QAOADescriptor object containing circuit instructions

  • betas (List[Union[float, int]]) – List of p betas

  • gammas_singles (List[Union[float, int]]) – List of p gammas_singles

  • gammas_pairs (List[Union[float, int]]) – List of p gammas_pairs

betas

A 1D array containing the betas from above for each timestep

Type:

np.array

gammas_pairs

A 1D array containing the gammas_singles from above for each timestep

Type:

np.array

gammas_singles

A 1D array containing the gammas_pairs from above for each timestep

Type:

np.array

asdict()

Return the parameters as a dictionary.

Returns:

The parameters as a dictionary. Has the same output format as the expected input of self.update_from_dict.

Return type:

dict

property cost_1q_angles

2D array with the Z-rotation angles.

1st index goes over the p and the 2nd index over the qubits, to apply Z-rotations on.

property cost_2q_angles

2D array with ZZ-rotation angles.

1st index goes over the p and the 2nd index over the qubit pairs, to apply ZZ-rotations on.

classmethod empty(qaoa_descriptor)[source]

Initialise Standard Variational params with empty arrays

classmethod from_other_parameters(params)

Alternative to __init__ that takes parameters with less degrees of freedom as the input.

Parameters:

params (QAOAVaritionalBaseParams) – The input parameters object to construct the new parameters object from.

Returns:

The converted paramters s.t. all the rotation angles of the in and output parameters are the same.

Return type:

QAOAVariationalBaseParams

classmethod linear_ramp_from_hamiltonian(qaoa_descriptor, time=None)[source]
Returns:

A StandardParams object with parameters according to a linear ramp schedule for the Hamiltonian specified by register, terms, weights.

Return type:

StandardParams

property mixer_1q_angles

2D array with the X-rotation angles.

1st index goes over p and the 2nd index over the qubits, to apply X-rotations on.

property mixer_2q_angles

2D array with the XX and YY-rotation angles.

1st index goes over p and the 2nd index over the qubit pairs, to apply XX and YY-rotations on.

plot(ax=None, **kwargs)[source]

Plots self in a sensible way to the canvas ax, if provided.

Parameters:
  • ax (matplotlib.axes._subplots.AxesSubplot) – The canvas to plot itself on

  • kwargs – All remaining keyword arguments are passed forward to the plot function

classmethod random(qaoa_descriptor, seed=None)[source]
Returns:

Randomly initialised StandardParams object

Return type:

StandardParams

raw()[source]

Return the parameters in a 1D array.

This 1D array is needed by scipy.optimize.minimize which expects the parameters that need to be optimized to be a 1D array.

Returns:

The parameters in a 1D array. Has the same output format as the expected input of self.update_from_raw. Hence corresponds to the flattened parameters in __init__()

Return type:

np.array

raw_rotation_angles()

Flat array of the rotation angles for the memory map for the parametric circuit.

Returns:

Returns all single rotation angles in the ordering (x_rotation_angles, gamma_singles, zz_rotation_angles) where x_rotation_angles = (beta_q0_t0, beta_q1_t0, ... , beta_qn_tp) and the same for z_rotation_angles and zz_rotation_angles

Return type:

np.array

update_from_dict(new_values)

Update all the parameters from a dictionary.

The input has the same format as the output of self.asdict().

Parameters:

new_values (dict) – A dictionary with the new parameters. Must have the same keys as the output of self.asdict().

update_from_raw(new_values)[source]

Update all the parameters from a 1D array.

The input has the same format as the output of self.raw(). This is useful for scipy.optimize.minimize which expects the parameters that need to be optimized to be a 1D array.

Parameters:

new_values (Union[list, np.array]) – A 1D array with the new parameters. Must have length len(self) and the ordering of the flattend parameters in __init__().

Extended Parameters

class openqaoa.qaoa_components.variational_parameters.extendedparams.QAOAVariationalExtendedParams(qaoa_descriptor, betas_singles, betas_pairs, gammas_singles, gammas_pairs)[source]

QAOA parameters in their most general form with different angles for each operator.

This means, that at the i-th timestep the evolution hamiltonian is given by

\[H(t_i) = \sum_{ extrm{qubits } j} eta_{ij} X_j + \sum_{ extrm{qubits } j} \gamma_{ extrm{single } ij} Z_j + \sum_{ extrm{qubit pairs} (jk)} \gamma_{ extrm{pair } i(jk)} Z_j Z_k\]

and the complete circuit is then

\[U = e^{-i H(t_p)} \cdots e^{-iH(t_1)}.\]
qaoa_descriptor

Specify the circuit parameters to construct circuit angles to be used for training

Type:

QAOADescriptor

betas_singles

2D array with the gammas from above for each timestep and qubit. 1st index goes over the timelayers, 2nd over the qubits.

Type:

list

betas_pairs
Type:

list

gammas_pairs
Type:

list

gammas_singles
Type:

list

asdict()

Return the parameters as a dictionary.

Returns:

The parameters as a dictionary. Has the same output format as the expected input of self.update_from_dict.

Return type:

dict

property cost_1q_angles

2D array with the Z-rotation angles.

1st index goes over the p and the 2nd index over the qubits, to apply Z-rotations on.

property cost_2q_angles

2D array with ZZ-rotation angles.

1st index goes over the p and the 2nd index over the qubit pairs, to apply ZZ-rotations on.

classmethod empty(qaoa_descriptor)[source]

Initialise Extended parameters with empty arrays

classmethod from_other_parameters(params)

Alternative to __init__ that takes parameters with less degrees of freedom as the input.

Parameters:

params (QAOAVaritionalBaseParams) – The input parameters object to construct the new parameters object from.

Returns:

The converted paramters s.t. all the rotation angles of the in and output parameters are the same.

Return type:

QAOAVariationalBaseParams

get_constraints()[source]

Constraints on the parameters for constrained parameters.

Returns:

A list of tuples (0, upper_boundary) of constraints on the parameters s.t. we are exploiting the periodicity of the cost function. Useful for constrained optimizers.

Return type:

List[Tuple]

classmethod linear_ramp_from_hamiltonian(qaoa_descriptor, time=None)[source]
Returns:

The initial parameters according to a linear ramp for the Hamiltonian specified by register, terms, weights.

Return type:

ExtendedParams

property mixer_1q_angles

2D array with the X-rotation angles.

1st index goes over p and the 2nd index over the qubits, to apply X-rotations on.

property mixer_2q_angles

2D array with the XX and YY-rotation angles.

1st index goes over p and the 2nd index over the qubit pairs, to apply XX and YY-rotations on.

plot(ax=None, **kwargs)[source]

Plots self in a sensible way to the canvas ax, if provided.

Parameters:
  • ax (matplotlib.axes._subplots.AxesSubplot) – The canvas to plot itself on

  • kwargs – All remaining keyword arguments are passed forward to the plot function

classmethod random(qaoa_descriptor, seed=None)[source]
Returns:

Randomly initialised ExtendedParams object

Return type:

ExtendedParams

raw()[source]

Return the parameters in a 1D array.

This 1D array is needed by scipy.optimize.minimize which expects the parameters that need to be optimized to be a 1D array.

Returns:

The parameters in a 1D array. Has the same output format as the expected input of self.update_from_raw. Hence corresponds to the flattened parameters in __init__()

Return type:

np.array

raw_rotation_angles()

Flat array of the rotation angles for the memory map for the parametric circuit.

Returns:

Returns all single rotation angles in the ordering (x_rotation_angles, gamma_singles, zz_rotation_angles) where x_rotation_angles = (beta_q0_t0, beta_q1_t0, ... , beta_qn_tp) and the same for z_rotation_angles and zz_rotation_angles

Return type:

np.array

update_from_dict(new_values)

Update all the parameters from a dictionary.

The input has the same format as the output of self.asdict().

Parameters:

new_values (dict) – A dictionary with the new parameters. Must have the same keys as the output of self.asdict().

update_from_raw(new_values)[source]

Update all the parameters from a 1D array.

The input has the same format as the output of self.raw(). This is useful for scipy.optimize.minimize which expects the parameters that need to be optimized to be a 1D array.

Parameters:

new_values (Union[list, np.array]) – A 1D array with the new parameters. Must have length len(self) and the ordering of the flattend parameters in __init__().

Fourier Parameters

class openqaoa.qaoa_components.variational_parameters.fourierparams.QAOAVariationalFourierParams(qaoa_descriptor, q, v, u)[source]

The QAOA parameters as the sine/cosine transform of the original gammas and x_rotation_angles. See “Quantum Approximate Optimization Algorithm: Performance, Mechanism, and Implementation on Near-Term Devices” [https://arxiv.org/abs/1812.01041] for a detailed description.

Parameters:
  • qaoa_descriptor (QAOADescriptor) – QAOADescriptor object with circuit instructions

  • q (int) – The number of coefficients for the discrete sine and cosine transforms below

  • u (np.array) – The discrete sine transform of the gammas in StandardParams

  • v (np.array) – The discrete cosine transform of the betas in StandardParams

q

The number of coefficients for the discrete sine and cosine transforms below

Type:

int

u

The discrete sine transform of the gammas in StandardParams

Type:

np.array

v

The discrete cosine transform of the betas in StandardParams

Type:

np.array

betas

Betas to parameterize the mixer part

Type:

np.array

gammas

Gammas to parameterize the cost part

Type:

np.array

asdict()

Return the parameters as a dictionary.

Returns:

The parameters as a dictionary. Has the same output format as the expected input of self.update_from_dict.

Return type:

dict

property cost_1q_angles

2D array with the Z-rotation angles.

1st index goes over the p and the 2nd index over the qubits, to apply Z-rotations on.

property cost_2q_angles

2D array with ZZ-rotation angles.

1st index goes over the p and the 2nd index over the qubit pairs, to apply ZZ-rotations on.

classmethod empty(qaoa_descriptor, q)[source]

Initialise the Fourier Params u,v with empty arrays

classmethod from_other_parameters(params)

Alternative to __init__ that takes parameters with less degrees of freedom as the input.

Parameters:

params (QAOAVaritionalBaseParams) – The input parameters object to construct the new parameters object from.

Returns:

The converted paramters s.t. all the rotation angles of the in and output parameters are the same.

Return type:

QAOAVariationalBaseParams

classmethod linear_ramp_from_hamiltonian(qaoa_descriptor, q, time=None)[source]

NOTE: rather than implement an exact linear schedule, this instead implements the lowest frequency component, i.e. a sine curve for gammas, and a cosine for betas.

Parameters:
  • qaoa_descriptor (QAOADescriptor) – QAOADescriptor object containing information about terms,weights,register and p

  • time (Optional[float]) – total time. Set to 0.7*p if None is passed.

Returns:

A FourierParams object with initial parameters corresponding to a the 0th order Fourier component (a sine curve for gammas, cosine for betas)

Return type:

FourierParams

property mixer_1q_angles

2D array with the X-rotation angles.

1st index goes over p and the 2nd index over the qubits, to apply X-rotations on.

property mixer_2q_angles

2D array with the XX and YY-rotation angles.

1st index goes over p and the 2nd index over the qubit pairs, to apply XX and YY-rotations on.

plot(ax=None, **kwargs)[source]

Plots self in a sensible way to the canvas ax, if provided.

Parameters:
  • ax (matplotlib.axes._subplots.AxesSubplot) – The canvas to plot itself on

  • kwargs – All remaining keyword arguments are passed forward to the plot function

classmethod random(qaoa_descriptor, q, seed=None)[source]
Returns:

randomly initialised FourierParams object

Return type:

FourierParams

raw()[source]

Return the parameters in a 1D array.

This 1D array is needed by scipy.optimize.minimize which expects the parameters that need to be optimized to be a 1D array.

Returns:

The parameters in a 1D array. Has the same output format as the expected input of self.update_from_raw. Hence corresponds to the flattened parameters in __init__()

Return type:

np.array

raw_rotation_angles()

Flat array of the rotation angles for the memory map for the parametric circuit.

Returns:

Returns all single rotation angles in the ordering (x_rotation_angles, gamma_singles, zz_rotation_angles) where x_rotation_angles = (beta_q0_t0, beta_q1_t0, ... , beta_qn_tp) and the same for z_rotation_angles and zz_rotation_angles

Return type:

np.array

update_from_dict(new_values)

Update all the parameters from a dictionary.

The input has the same format as the output of self.asdict().

Parameters:

new_values (dict) – A dictionary with the new parameters. Must have the same keys as the output of self.asdict().

update_from_raw(new_values)[source]

Update all the parameters from a 1D array.

The input has the same format as the output of self.raw(). This is useful for scipy.optimize.minimize which expects the parameters that need to be optimized to be a 1D array.

Parameters:

new_values (Union[list, np.array]) – A 1D array with the new parameters. Must have length len(self) and the ordering of the flattend parameters in __init__().

class openqaoa.qaoa_components.variational_parameters.fourierparams.QAOAVariationalFourierWithBiasParams(qaoa_descriptor, q, v, u_singles, u_pairs)[source]

The QAOA parameters as the sine/cosine transform of the original gammas and x_rotation_angles. See “Quantum Approximate Optimization Algorithm: Performance, Mechanism, and Implementation on Near-Term Devices” [https://arxiv.org/abs/1812.01041] for a detailed description.

Parameters:
  • qaoa_descriptor (QAOADescriptor) – QAOADescriptor object with circuit instructions

  • q (int) – The number of coefficients for the discrete sine and cosine transforms below

  • u_pairs (np.array) – The discrete sine transform of the gammas_pairs in StandardWithBiasParams

  • u_singles (np.array) – The discrete sine transform of the gammas_singles in StandardWithBiasParams

  • v (np.array) – The discrete cosine transform of the betas in StandardWithBiasParams

q

The number of coefficients for the discrete sine and cosine transforms below

Type:

int

u_pairs

The discrete sine transform of the gammas_pairs in StandardWithBiasParams

Type:

np.array

u_singles

The discrete sine transform of the gammas_singles in StandardWithBiasParams

Type:

np.array

v

The discrete cosine transform of the betas in StandardWithBiasParams

Type:

np.array

betas
Type:

np.array

gammas_singles
Type:

np.array

gammas_pairs
Type:

np.array

asdict()

Return the parameters as a dictionary.

Returns:

The parameters as a dictionary. Has the same output format as the expected input of self.update_from_dict.

Return type:

dict

property cost_1q_angles

2D array with the Z-rotation angles.

1st index goes over the p and the 2nd index over the qubits, to apply Z-rotations on.

property cost_2q_angles

2D array with ZZ-rotation angles.

1st index goes over the p and the 2nd index over the qubit pairs, to apply ZZ-rotations on.

classmethod empty(qaoa_descriptor, q)[source]

Initialise Fourier parameters with bias with an empty array

classmethod from_other_parameters(params)

Alternative to __init__ that takes parameters with less degrees of freedom as the input.

Parameters:

params (QAOAVaritionalBaseParams) – The input parameters object to construct the new parameters object from.

Returns:

The converted paramters s.t. all the rotation angles of the in and output parameters are the same.

Return type:

QAOAVariationalBaseParams

classmethod linear_ramp_from_hamiltonian(qaoa_descriptor, q, time=None)[source]
Parameters:
  • qaoa_descriptor (QAOADescriptor) – Hyper Parameters passed as an object of Type[QAOADescriptor]

  • time (Optional[float]) – Time for creating the linear ramp schedule. Defaults to 0.7*p if None

Returns:

A FourierWithBiasParams object with initial parameters corresponding to a linear ramp annealing schedule

Return type:

FourierWithBiasParams

property mixer_1q_angles

2D array with the X-rotation angles.

1st index goes over p and the 2nd index over the qubits, to apply X-rotations on.

property mixer_2q_angles

2D array with the XX and YY-rotation angles.

1st index goes over p and the 2nd index over the qubit pairs, to apply XX and YY-rotations on.

plot(ax=None, **kwargs)[source]

Plots self in a sensible way to the canvas ax, if provided.

Parameters:
  • ax (matplotlib.axes._subplots.AxesSubplot) – The canvas to plot itself on

  • kwargs – All remaining keyword arguments are passed forward to the plot function

classmethod random(qaoa_descriptor, q, seed=None)[source]
Returns:

randomly initialised FourierWithBiasParams object

Return type:

FourierWithBiasParams

raw()[source]

Return the parameters in a 1D array.

This 1D array is needed by scipy.optimize.minimize which expects the parameters that need to be optimized to be a 1D array.

Returns:

The parameters in a 1D array. Has the same output format as the expected input of self.update_from_raw. Hence corresponds to the flattened parameters in __init__()

Return type:

np.array

raw_rotation_angles()

Flat array of the rotation angles for the memory map for the parametric circuit.

Returns:

Returns all single rotation angles in the ordering (x_rotation_angles, gamma_singles, zz_rotation_angles) where x_rotation_angles = (beta_q0_t0, beta_q1_t0, ... , beta_qn_tp) and the same for z_rotation_angles and zz_rotation_angles

Return type:

np.array

update_from_dict(new_values)

Update all the parameters from a dictionary.

The input has the same format as the output of self.asdict().

Parameters:

new_values (dict) – A dictionary with the new parameters. Must have the same keys as the output of self.asdict().

update_from_raw(new_values)[source]

Update all the parameters from a 1D array.

The input has the same format as the output of self.raw(). This is useful for scipy.optimize.minimize which expects the parameters that need to be optimized to be a 1D array.

Parameters:

new_values (Union[list, np.array]) – A 1D array with the new parameters. Must have length len(self) and the ordering of the flattend parameters in __init__().

class openqaoa.qaoa_components.variational_parameters.fourierparams.QAOAVariationalFourierExtendedParams(qaoa_descriptor, q, v_singles, v_pairs, u_singles, u_pairs)[source]

The Fourier pendant to ExtendedParams.

Parameters:
  • qaoa_descriptor (QAOADescriptor) – object containing information about terms,weights,register and p

  • q (int) – The parameter depth for u and v Fourier params

  • v (np.array) – The discrete cosine transform of the betas in ExtendedParams

  • u_singles (np.array) – The discrete sine transform of the gammas_singles in ExtendedParams

  • u_pairs (np.array) – The discrete sine transform of the gammas_pairs in ExtendedParams

q

The number of coefficients for the discrete sine and cosine transforms below

Type:

int

v

The discrete cosine transform of the betas in ExtendedParams

Type:

np.array

u_singles

The discrete sine transform of the gammas_singles in ExtendedParams

Type:

np.array

u_pairs

The discrete sine transform of the gammas_pairs in ExtendedParams

Type:

np.array

betas_singles
betas_pairs
gammas_singles
gammas_pairs
asdict()

Return the parameters as a dictionary.

Returns:

The parameters as a dictionary. Has the same output format as the expected input of self.update_from_dict.

Return type:

dict

property cost_1q_angles

2D array with the Z-rotation angles.

1st index goes over the p and the 2nd index over the qubits, to apply Z-rotations on.

property cost_2q_angles

2D array with ZZ-rotation angles.

1st index goes over the p and the 2nd index over the qubit pairs, to apply ZZ-rotations on.

classmethod empty(qaoa_descriptor, q)[source]

Initialise Fourier extended parameters with empty arrays

classmethod from_other_parameters(params)

Alternative to __init__ that takes parameters with less degrees of freedom as the input.

Parameters:

params (QAOAVaritionalBaseParams) – The input parameters object to construct the new parameters object from.

Returns:

The converted paramters s.t. all the rotation angles of the in and output parameters are the same.

Return type:

QAOAVariationalBaseParams

classmethod linear_ramp_from_hamiltonian(qaoa_descriptor, q, time=None)[source]
Parameters:
  • qaoa_descriptor (QAOADescriptor) – an object containing information about the QAOA circuit

  • q (int) – The q-depth of the circuit parameters

  • time (float) – Time for creating the linear ramp schedule. Defaults to 0.7*p if None

Returns:

The initial parameters according to a linear ramp for for the Hamiltonian specified by register, terms, weights.

Return type:

FourierExtendedParams

property mixer_1q_angles

2D array with the X-rotation angles.

1st index goes over p and the 2nd index over the qubits, to apply X-rotations on.

property mixer_2q_angles

2D array with the XX and YY-rotation angles.

1st index goes over p and the 2nd index over the qubit pairs, to apply XX and YY-rotations on.

plot(ax=None, **kwargs)[source]

Plots self in a sensible way to the canvas ax, if provided.

Parameters:
  • ax (matplotlib.axes._subplots.AxesSubplot) – The canvas to plot itself on

  • kwargs – All remaining keyword arguments are passed forward to the plot function

classmethod random(qaoa_descriptor, q, seed=None)[source]
Returns:

randomly initialised FourierExtendedParams object

Return type:

FourierExtendedParams

raw()[source]

Return the parameters in a 1D array.

This 1D array is needed by scipy.optimize.minimize which expects the parameters that need to be optimized to be a 1D array.

Returns:

The parameters in a 1D array. Has the same output format as the expected input of self.update_from_raw. Hence corresponds to the flattened parameters in __init__()

Return type:

np.array

raw_rotation_angles()

Flat array of the rotation angles for the memory map for the parametric circuit.

Returns:

Returns all single rotation angles in the ordering (x_rotation_angles, gamma_singles, zz_rotation_angles) where x_rotation_angles = (beta_q0_t0, beta_q1_t0, ... , beta_qn_tp) and the same for z_rotation_angles and zz_rotation_angles

Return type:

np.array

update_from_dict(new_values)

Update all the parameters from a dictionary.

The input has the same format as the output of self.asdict().

Parameters:

new_values (dict) – A dictionary with the new parameters. Must have the same keys as the output of self.asdict().

update_from_raw(new_values)[source]

Update all the parameters from a 1D array.

The input has the same format as the output of self.raw(). This is useful for scipy.optimize.minimize which expects the parameters that need to be optimized to be a 1D array.

Parameters:

new_values (Union[list, np.array]) – A 1D array with the new parameters. Must have length len(self) and the ordering of the flattend parameters in __init__().

Annealing Parameters

class openqaoa.qaoa_components.variational_parameters.annealingparams.QAOAVariationalAnnealingParams(qaoa_descriptor, total_annealing_time, schedule)[source]

QAOA parameters that implement a state preparation circuit of the form

\[U = e^{-i (1-s(t_p)) H_M \Delta t} e^{-i s(t_p) H_C \Delta t} \cdots e^{-i(1-s(t_1)H_M \Delta t} e^{-i s(t_1) H_C \Delta t}\]

where the \(s(t_i) =: s_i\) are the variable parameters and \(\Delta t= \frac{T}{N}\). So the schedule is specified by specifying s(t) at evenly spaced timelayers.

Parameters:
  • qaoa_descriptor (QAOADescriptor) – QAOADescriptor object containing circuit instructions

  • total_annealing_time (float) – Total annealing time for the schedule

  • schedule (list) – List specifying the annealing schedule

schedule

An 1D array holding the values of the schedule function at each timestep.

Type:

np.array

total_annealing_time

Total annealing time for the schedule

Type:

float

dt

annealing time step

Type:

float

mixer_time

schedule for mixer application

Type:

np.array

cost_time

schedule for cost application

Type:

np.array

asdict()

Return the parameters as a dictionary.

Returns:

The parameters as a dictionary. Has the same output format as the expected input of self.update_from_dict.

Return type:

dict

property cost_1q_angles

2D array with the Z-rotation angles.

1st index goes over the p and the 2nd index over the qubits, to apply Z-rotations on.

property cost_2q_angles

2D array with ZZ-rotation angles.

1st index goes over the p and the 2nd index over the qubit pairs, to apply ZZ-rotations on.

classmethod empty(qaoa_descriptor, total_annealing_time)[source]

Alternative to __init__ that only takes qaoa_descriptor and fills parameters via np.empty

Parameters:

qaoa_descriptor (QAOADescriptor) – QAOADescriptor object containing information about terms,weights,register and p

Returns:

A Parameter object with the parameters filled by np.empty

Return type:

QAOAVariationalBaseParams

classmethod from_other_parameters(params)

Alternative to __init__ that takes parameters with less degrees of freedom as the input.

Parameters:

params (QAOAVaritionalBaseParams) – The input parameters object to construct the new parameters object from.

Returns:

The converted paramters s.t. all the rotation angles of the in and output parameters are the same.

Return type:

QAOAVariationalBaseParams

classmethod linear_ramp_from_hamiltonian(qaoa_descriptor, total_annealing_time=None, time=None)[source]
Returns:

An AnnealingParams object corresponding to a linear ramp schedule.

Return type:

AnnealingParams

property mixer_1q_angles

2D array with the X-rotation angles.

1st index goes over p and the 2nd index over the qubits, to apply X-rotations on.

property mixer_2q_angles: ndarray

2D array with the XX and YY-rotation angles.

1st index goes over p and the 2nd index over the qubit pairs, to apply XX and YY-rotations on.

plot(ax=None, **kwargs)[source]

Plots self in a sensible way to the canvas ax, if provided.

Parameters:
  • ax (matplotlib.axes._subplots.AxesSubplot) – The canvas to plot itself on

  • kwargs – All remaining keyword arguments are passed forward to the plot function

classmethod random(qaoa_descriptor, total_annealing_time, seed=None)[source]
Returns:

randomly initialised AnnealingParams object

Return type:

AnnealingParams

raw()[source]

Return the parameters in a 1D array.

This 1D array is needed by scipy.optimize.minimize which expects the parameters that need to be optimized to be a 1D array.

Returns:

The parameters in a 1D array. Has the same output format as the expected input of self.update_from_raw. Hence corresponds to the flattened parameters in __init__()

Return type:

np.array

raw_rotation_angles()

Flat array of the rotation angles for the memory map for the parametric circuit.

Returns:

Returns all single rotation angles in the ordering (x_rotation_angles, gamma_singles, zz_rotation_angles) where x_rotation_angles = (beta_q0_t0, beta_q1_t0, ... , beta_qn_tp) and the same for z_rotation_angles and zz_rotation_angles

Return type:

np.array

update_from_dict(new_values)

Update all the parameters from a dictionary.

The input has the same format as the output of self.asdict().

Parameters:

new_values (dict) – A dictionary with the new parameters. Must have the same keys as the output of self.asdict().

update_from_raw(new_values)[source]

Update all the parameters from a 1D array.

The input has the same format as the output of self.raw(). This is useful for scipy.optimize.minimize which expects the parameters that need to be optimized to be a 1D array.

Parameters:

new_values (Union[list, np.array]) – A 1D array with the new parameters. Must have length len(self) and the ordering of the flattend parameters in __init__().