QuadraticExpression#

class QuadraticExpression(quadratic_program, coefficients)[source]#

Bases: QuadraticProgramElement

Representation of a quadratic expression by its coefficients.

Creates a new quadratic expression.

The quadratic expression can be defined via an array, a list, a sparse matrix, or a dictionary that uses variable names or indices as keys and stores the values internally as a dok_matrix. We stores values in a compressed way, i.e., values at symmetric positions are summed up in the upper triangle. For example, {(0, 1): 1, (1, 0): 2} -> {(0, 1): 3}.

প্যারামিটার:

Attributes

bounds#

Returns the lower bound and the upper bound of the quadratic expression

রিটার্নস:

The lower bound and the upper bound of the quadratic expression

রেইজেস:

QiskitOptimizationError -- if the quadratic expression contains any unbounded variable

coefficients#

Returns the coefficients of the quadratic expression.

রিটার্নস:

The coefficients of the quadratic expression.

quadratic_program#

Returns the parent QuadraticProgram.

রিটার্নস:

The parent QuadraticProgram.

Methods

evaluate(x)[source]#

Evaluate the quadratic expression for given variables: x * Q * x.

প্যারামিটার:

x (ndarray | List | Dict[int | str, float]) -- The values of the variables to be evaluated.

রিটার্নস:

The value of the quadratic expression given the variable values.

রিটার্ন টাইপ:

float

evaluate_gradient(x)[source]#

Evaluate the gradient of the quadratic expression for given variables.

প্যারামিটার:

x (ndarray | List | Dict[int | str, float]) -- The values of the variables to be evaluated.

রিটার্নস:

The value of the gradient quadratic expression given the variable values.

রিটার্ন টাইপ:

ndarray

to_array(symmetric=False)[source]#

Returns the coefficients of the quadratic expression as array.

প্যারামিটার:

symmetric (bool) -- Determines whether the output is in a symmetric form or not.

রিটার্নস:

An array with the coefficients corresponding to the quadratic expression.

রিটার্ন টাইপ:

ndarray

to_dict(symmetric=False, use_name=False)[source]#

Returns the coefficients of the quadratic expression as dictionary, either using tuples of variable names or indices as keys.

প্যারামিটার:
  • symmetric (bool) -- Determines whether the output is in a symmetric form or not.

  • use_name (bool) -- Determines whether to use index or names to refer to variables.

রিটার্নস:

An dictionary with the coefficients corresponding to the quadratic expression.

রিটার্ন টাইপ:

Dict[Tuple[int, int] | Tuple[str, str], float]