Skip to main contentIBM Quantum Documentation
This page is from a dev version of Qiskit SDK. This is a new interface that does not exist in the stable version.

QuadraticFormGate

class qiskit.circuit.library.QuadraticFormGate(num_result_qubits=None, quadratic=None, linear=None, offset=None, label='Q(x)')

GitHub

Bases: Gate

Implements a quadratic form on binary variables encoded in qubit registers.

A quadratic form on binary variables is a quadratic function QQ acting on a binary variable of nn bits, x=x0...xn1x = x_0 ... x_{n-1}. For an integer matrix AA, an integer vector bb and an integer cc the function can be written as

Q(x)=xTAx+xTb+cQ(x) = x^T A x + x^T b + c

If AA, bb or cc contain scalar values, this circuit computes only an approximation of the quadratic form.

Provided with mm qubits to encode the value, this circuit computes Q(x)mod2mQ(x) \mod 2^m in [two’s complement](https://stackoverflow.com/questions/1049722/what-is-2s-complement) representation.

xn0mxn(Q(x)+2m)mod2mm|x\rangle_n |0\rangle_m \mapsto |x\rangle_n |(Q(x) + 2^m) \mod 2^m \rangle_m

Since we use two’s complement e.g. the value of Q(x)=3Q(x) = 3 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, Q(x)=3Q(x) = -3 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 Q(x)Q(x) is too large to be represented with m qubits, the resulting bitstring is (Q(x)+2m)mod2m)(Q(x) + 2^m) \mod 2^m).

The implementation of this circuit is discussed in [1], Fig. 6.

References

[1]: Gilliam et al., Grover Adaptive Search for Constrained Polynomial Binary Optimization.

arXiv:1912.04088

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)

GitHub

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

int

validate_parameter

validate_parameter(parameter)

GitHub

Gate parameters should be int, float, or ParameterExpression

Was this page helpful?
Report a bug or request content on GitHub.