Skip to content

Variational Gate — VQGate

API reference for parameterized (variational) gate variants used in variational quantum circuits (VQAs). These gates differ from standard gates in that their rotation parameters are symbolic references to a Parameter vector rather than fixed numeric values.

VQGate

Base class for variational quantum gates. VQGate objects are created by the variational gate factory functions and can be appended to VQCircuit.

Signature

python
class VQGate

VQGate instances hold a gate type and references to mutable parameter positions within a Parameter vector. At circuit execution time, concrete values are bound through VQCircuit.__call__().

Variational Gate Factory Functions

Each function returns a VQGate (i.e. VariationalQuantumGate). The param argument specifies the index in the Parameter vector that supplies the rotation angle.

Single-Qubit Variational Gates

P (variational)

python
P(qbit_idx: int, param: MutableParamType) -> VQGate
ParameterTypeDescription
qbit_idxintTarget qubit index
paramMutableParamTypeIndex into the Parameter vector

Returns a variational P gate.

RX (variational)

python
RX(qbit_idx: int, param: MutableParamType) -> VQGate

Returns a variational RX gate.

RY (variational)

python
RY(qbit_idx: int, param: MutableParamType) -> VQGate

Returns a variational RY gate.

RZ (variational)

python
RZ(qbit_idx: int, param: MutableParamType) -> VQGate

Returns a variational RZ gate.

U1 (variational)

python
U1(qbit_idx: int, param: MutableParamType) -> VQGate

Returns a variational U1 gate.

IDLE (variational)

python
IDLE(qbit_idx: int, param: MutableParamType) -> VQGate

Returns a variational IDLE gate.

Two-Parameter Variational Gates

U2 (variational, overload 1)

python
U2(qbit_idx: int, param1: MutableParamType, param2: Union[float, MutableParamType]) -> VQGate
ParameterTypeDescription
qbit_idxintTarget qubit index
param1MutableParamTypeMutable parameter index for first angle
param2Union[float, MutableParamType]Fixed value or mutable parameter index for second angle

U2 (variational, overload 2)

python
U2(qbit_idx: int, param1: float, param2: MutableParamType) -> VQGate
ParameterTypeDescription
qbit_idxintTarget qubit index
param1floatFixed value for first angle
param2MutableParamTypeMutable parameter index for second angle

RPhi (variational, overload 1)

python
RPhi(qbit_idx: int, param1: MutableParamType, param2: Union[float, MutableParamType]) -> VQGate
ParameterTypeDescription
qbit_idxintTarget qubit index
param1MutableParamTypeMutable parameter index for theta
param2Union[float, MutableParamType]Fixed value or mutable parameter index for phi

RPhi (variational, overload 2)

python
RPhi(qbit_idx: int, param1: float, param2: MutableParamType) -> VQGate
ParameterTypeDescription
qbit_idxintTarget qubit index
param1floatFixed value for theta
param2MutableParamTypeMutable parameter index for phi

Three-Parameter Variational Gates

U3 (variational, overload 1)

python
U3(qbit_idx: int, param1: MutableParamType, param2: Union[float, MutableParamType], param3: Union[float, MutableParamType]) -> VQGate
ParameterTypeDescription
qbit_idxintTarget qubit index
param1MutableParamTypeMutable parameter index for first angle
param2Union[float, MutableParamType]Fixed value or mutable parameter index for second angle
param3Union[float, MutableParamType]Fixed value or mutable parameter index in third angle

U3 (variational, overload 2)

python
U3(qbit_idx: int, param1: float, param2: MutableParamType, param3: Union[float, MutableParamType]) -> VQGate
ParameterTypeDescription
qbit_idxintTarget qubit index
param1floatFixed value for first angle
param2MutableParamTypeMutable parameter index in second angle
param3Union[float, MutableParamType]Fixed value or mutable parameter index in third angle

U3 (variational, overload 3)

python
U3(qbit_idx: int, param1: float, param2: float, param3: MutableParamType) -> VQGate
ParameterTypeDescription
qbit_idxintTarget qubit index
param1floatFixed value for first angle
param2floatFixed value in second angle
param3MutableParamTypeMutable parameter index in third angle

Four-Parameter Variational Gates

U4 (variational, overload 1)

python
U4(qbit_idx: int, param1: MutableParamType, param2: Union[float, MutableParamType], param3: Union[float, MutableParamType], param4: Union[float, MutableParamType]) -> VQGate
ParameterTypeDescription
qbit_idxintTarget qubit index
param1MutableParamTypeMutable parameter index for first angle
param2Union[float, MutableParamType]Fixed value or mutable parameter index in second angle
param3Union[float, MutableParamType]Fixed value or mutable parameter index in third angle
param4Union[float, MutableParamType]Fixed value or mutable parameter index in fourth angle

U4 (variational, overload 2)

python
U4(qbit_idx: int, param1: float, param2: MutableParamType, param3: Union[float, MutableParamType], param4: Union[float, MutableParamType]) -> VQGate
ParameterTypeDescription
qbit_idxintTarget qubit index
param1floatFixed value in first angle
param2MutableParamTypeMutable parameter index in second angle
param3Union[float, MutableParamType]Fixed value or mutable parameter index in third angle
param4Union[float, MutableParamType]Fixed value or mutable parameter index in fourth angle

U4 (variational, overload 3)

python
U4(qbit_idx: int, param1: float, param2: float, param3: MutableParamType, param4: Union[float, MutableParamType]) -> VQGate
ParameterTypeDescription
qbit_idxintTarget qubit index
param1floatFixed value in first angle
param2floatFixed value in second angle
param3MutableParamTypeMutable parameter index in third angle
param4Union[float, MutableParamType]Fixed value or mutable parameter index in fourth angle

U4 (variational, overload 4)

python
U4(qbit_idx: int, param1: float, param2: float, param3: float, param4: MutableParamType) -> VQGate
ParameterTypeDescription
qbit_idxintTarget qubit index
param1floatFixed value in first angle
param2floatFixed value in second angle
param3floatFixed value in third angle
param4MutableParamTypeMutable parameter index in fourth angle

Two-Qubit Variational Gates

CU (variational, overload 1)

python
CU(control_qbit_idx: int, target_qbit_idx: int, param1: MutableParamType, param2: Union[float, MutableParamType], param3: Union[float, MutableParamType], param4: Union[float, MutableParamType]) -> VQGate
ParameterTypeDescription
control_qbit_idxintControl qubit index
target_qbit_idxintTarget qubit index
param1MutableParamTypeMutable parameter index in first angle
param2Union[float, MutableParamType]Fixed value or mutable parameter index in second angle
param3Union[float, MutableParamType]Fixed value or mutable parameter index in third angle
param4Union[float, MutableParamType]Fixed value or mutable parameter index in fourth angle

CU (variational, overloads 2-4)

Additional overloads follow the same pattern as U4, with one additional fixed value per overload. Each overload takes control_qbit_idx and target_qbit_idx as the first two arguments.

CP (variational)

python
CP(control_qbit_idx: int, target_qbit_idx: int, param: MutableParamType) -> VQGate
ParameterTypeDescription
control_qbit_idxintControl qubit index
target_qbit_idxintTarget qubit index
paramMutableParamTypeMutable parameter index

CRX (variational)

python
CRX(control_qbit_idx: int, target_qbit_idx: int, param: MutableParamType) -> VQGate
ParameterTypeDescription
control_qbit_idxintControl qubit index
target_qbit_idxintTarget qubit index
paramMutableParamTypeMutable parameter index

CRY (variational)

python
CRY(control_qbit_idx: int, target_qbit_idx: int, param: MutableParamType) -> VQGate

CRZ (variational)

python
CRZ(control_qbit_idx: int, target_qbit_idx: int, param: MutableParamType) -> VQGate

CR (variational, alias for CP)

python
CR(control_qbit_idx: int, target_qbit_idx: int, param: MutableParamType) -> VQGate

RXX (variational)

python
RXX(control_qbit_idx: int, target_qbit_idx: int, param: MutableParamType) -> VQGate

RYY (variational)

python
RYY(control_qbit_idx: int, target_qbit_idx: int, param: MutableParamType) -> VQGate

RZZ (variational)

python
RZZ(control_qbit_idx: int, target_qbit_idx: int, param: MutableParamType) -> VQGate

RZX (variational)

python
RZX(control_qbit_idx: int, target_qbit_idx: int, param: MutableParamType) -> VQGate

Usage with VQCircuit

Variational gates are the building blocks of VQCircuit. The param argument refers to a position in the Parameter vector:

python
from pyqpanda3.vqcircuit import VQCircuit
from pyqpanda3.core import RX, CP

# Create a variational circuit
vqc = VQCircuit()

# Create parameter placeholders (returns index positions)
p0 = vqc.Param("rx0")   # parameter for first RX
p1 = vqc.Param("rx1")   # parameter for second RX
p2 = vqc.Param("cp")    # parameter for controlled-phase

# Add variational gates using parameter indices
vqc << RX(0, p0)         # RX on qubit 0, angle from p0
vqc << RX(1, p1)         # RX on qubit 1, angle from p1
vqc << CP(0, 1, p2)      # Controlled-Phase using p2
vqc << RX(0, p2)         # RX on qubit 0, angle from p2

# Get parameter values and bind concrete values
import numpy as np
theta = np.array([0.5, 0.3, 0.1])
result = vqc(theta)  # pass concrete values

See Also

  • VQCircuit — Variational quantum circuit class
  • Parameter — Parameter vector class
  • Gates — Standard (non-variational) gate functions
  • Gradient — Gradient computation with variational gates

Released under the MIT License.