139 lines
4.4 KiB
Plaintext
139 lines
4.4 KiB
Plaintext
---
|
||
title: QuadraticExpression (v0.29)
|
||
description: API reference for qiskit.optimization.problems.QuadraticExpression in qiskit v0.29
|
||
in_page_toc_min_heading_level: 1
|
||
python_api_type: class
|
||
python_api_name: qiskit.optimization.problems.QuadraticExpression
|
||
---
|
||
|
||
# QuadraticExpression
|
||
|
||
<Class id="qiskit.optimization.problems.QuadraticExpression" isDedicatedPage={true} github="https://github.com/qiskit-community/qiskit-aqua/tree/stable/0.9/qiskit/optimization/problems/quadratic_expression.py" signature="QuadraticExpression(quadratic_program, coefficients)" modifiers="class">
|
||
Bases: `qiskit.optimization.problems.quadratic_program_element.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}.
|
||
|
||
**Parameters**
|
||
|
||
* **quadratic\_program** (`Any`) – The parent QuadraticProgram.
|
||
* **coefficients** (`Union`\[`ndarray`, `spmatrix`, `List`\[`List`\[`float`]], `Dict`\[`Tuple`\[`Union`\[`int`, `str`], `Union`\[`int`, `str`]], `float`]]) – The (sparse) representation of the coefficients.
|
||
|
||
## Methods
|
||
|
||
<span id="qiskit-optimization-problems-quadraticexpression-evaluate" />
|
||
|
||
### evaluate
|
||
|
||
<Function id="qiskit.optimization.problems.QuadraticExpression.evaluate" signature="QuadraticExpression.evaluate(x)">
|
||
Evaluate the quadratic expression for given variables: x \* Q \* x.
|
||
|
||
**Parameters**
|
||
|
||
**x** (`Union`\[`ndarray`, `List`, `Dict`\[`Union`\[`int`, `str`], `float`]]) – The values of the variables to be evaluated.
|
||
|
||
**Return type**
|
||
|
||
`float`
|
||
|
||
**Returns**
|
||
|
||
The value of the quadratic expression given the variable values.
|
||
</Function>
|
||
|
||
<span id="qiskit-optimization-problems-quadraticexpression-evaluate-gradient" />
|
||
|
||
### evaluate\_gradient
|
||
|
||
<Function id="qiskit.optimization.problems.QuadraticExpression.evaluate_gradient" signature="QuadraticExpression.evaluate_gradient(x)">
|
||
Evaluate the gradient of the quadratic expression for given variables.
|
||
|
||
**Parameters**
|
||
|
||
**x** (`Union`\[`ndarray`, `List`, `Dict`\[`Union`\[`int`, `str`], `float`]]) – The values of the variables to be evaluated.
|
||
|
||
**Return type**
|
||
|
||
`ndarray`
|
||
|
||
**Returns**
|
||
|
||
The value of the gradient quadratic expression given the variable values.
|
||
</Function>
|
||
|
||
<span id="qiskit-optimization-problems-quadraticexpression-to-array" />
|
||
|
||
### to\_array
|
||
|
||
<Function id="qiskit.optimization.problems.QuadraticExpression.to_array" signature="QuadraticExpression.to_array(symmetric=False)">
|
||
Returns the coefficients of the quadratic expression as array.
|
||
|
||
**Parameters**
|
||
|
||
**symmetric** (`bool`) – Determines whether the output is in a symmetric form or not.
|
||
|
||
**Return type**
|
||
|
||
`ndarray`
|
||
|
||
**Returns**
|
||
|
||
An array with the coefficients corresponding to the quadratic expression.
|
||
</Function>
|
||
|
||
<span id="qiskit-optimization-problems-quadraticexpression-to-dict" />
|
||
|
||
### to\_dict
|
||
|
||
<Function id="qiskit.optimization.problems.QuadraticExpression.to_dict" signature="QuadraticExpression.to_dict(symmetric=False, use_name=False)">
|
||
Returns the coefficients of the quadratic expression as dictionary, either using tuples of variable names or indices as keys.
|
||
|
||
**Parameters**
|
||
|
||
* **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.
|
||
|
||
**Return type**
|
||
|
||
`Dict`\[`Union`\[`Tuple`\[`int`, `int`], `Tuple`\[`str`, `str`]], `float`]
|
||
|
||
**Returns**
|
||
|
||
An dictionary with the coefficients corresponding to the quadratic expression.
|
||
</Function>
|
||
|
||
## Attributes
|
||
|
||
### coefficients
|
||
|
||
<Attribute id="qiskit.optimization.problems.QuadraticExpression.coefficients">
|
||
Returns the coefficients of the quadratic expression.
|
||
|
||
**Return type**
|
||
|
||
`dok_matrix`
|
||
|
||
**Returns**
|
||
|
||
The coefficients of the quadratic expression.
|
||
</Attribute>
|
||
|
||
### quadratic\_program
|
||
|
||
<Attribute id="qiskit.optimization.problems.QuadraticExpression.quadratic_program">
|
||
Returns the parent QuadraticProgram.
|
||
|
||
**Return type**
|
||
|
||
`Any`
|
||
|
||
**Returns**
|
||
|
||
The parent QuadraticProgram.
|
||
</Attribute>
|
||
</Class>
|
||
|