QuadraticFormGate
class qiskit.circuit.library.QuadraticFormGate(num_result_qubits=None, quadratic=None, linear=None, offset=None, label='Q(x)')
Bases: Gate
Implements a quadratic form on binary variables encoded in qubit registers.
A quadratic form on binary variables is a quadratic function acting on a binary variable of bits, . For an integer matrix , an integer vector and an integer the function can be written as
If , or contain scalar values, this circuit computes only an approximation of the quadratic form.
Provided with qubits to encode the value, this circuit computes in [two’s complement](https://stackoverflow.com/questions/1049722/what-is-2s-complement) representation.
Since we use two’s complement e.g. the value of requires 2 bits to represent the value and 1 bit for the sign: 3 = ‘011’ where the first 0 indicates a positive value. On the other hand, would be -3 = ‘101’, where the first 1 indicates a negative value and 01 is the two’s complement of 3.
If the value of is too large to be represented with m qubits, the resulting bitstring is .
The implementation of this circuit is discussed in [1], Fig. 6.
References
[1]: Gilliam et al., Grover Adaptive Search for Constrained Polynomial Binary Optimization.
Create a new gate.
Parameters
- name – The Qobj name of the gate.
- num_qubits – The number of qubits the gate acts on.
- params – A list of parameters.
- label (str) – An optional label for the gate.
- num_result_qubits (int | None) –
- quadratic (Sequence[Sequence[float]] | None) –
- linear (Sequence[Sequence[float]] | None) –
- offset (float | None) –
Attributes
base_class
Get the base class of this instruction. This is guaranteed to be in the inheritance tree of self
.
The “base class” of an instruction is the lowest class in its inheritance tree that the object should be considered entirely compatible with for _all_ circuit applications. This typically means that the subclass is defined purely to offer some sort of programmer convenience over the base class, and the base class is the “true” class for a behavioral perspective. In particular, you should not override base_class
if you are defining a custom version of an instruction that will be implemented differently by hardware, such as an alternative measurement strategy, or a version of a parametrized gate with a particular set of parameters for the purposes of distinguishing it in a Target
from the full parametrized gate.
This is often exactly equivalent to type(obj)
, except in the case of singleton instances of standard-library instructions. These singleton instances are special subclasses of their base class, and this property will return that base. For example:
>>> isinstance(XGate(), XGate)
True
>>> type(XGate()) is XGate
False
>>> XGate().base_class is XGate
True
In general, you should not rely on the precise class of an instruction; within a given circuit, it is expected that Instruction.name
should be a more suitable discriminator in most situations.
decompositions
Get the decompositions of the instruction from the SessionEquivalenceLibrary.
definition
Return definition in terms of other basic gates.
label
Return instruction label
mutable
Is this instance is a mutable unique instance or not.
If this attribute is False
the gate instance is a shared singleton and is not mutable.
name
Return the name.
num_clbits
Return the number of clbits.
num_qubits
Return the number of qubits.
params
The parameters of this Instruction
. Ideally these will be gate angles.
Methods
required_result_qubits
static required_result_qubits(quadratic, linear, offset)
Get the number of required result qubits.
Parameters
- quadratic (Sequence[Sequence[float]]) – A matrix containing the quadratic coefficients.
- linear (Sequence[float]) – An array containing the linear coefficients.
- offset (float) – A constant offset.
Returns
The number of qubits needed to represent the value of the quadratic form in twos complement.
Return type