Variational Gate — VQGate
Deprecated: The
VariationalGateclass has been removed from pyqpanda3. Variational gates are now created throughVQCircuitandVQGate. See VQCircuit for the current API.
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 (ParamExpression) into a Parameter array rather than fixed numeric values.
VQGate
Base class for variational quantum gates. VQGate objects are created by the variational gate factory functions (which are overloaded versions of standard gate functions taking a ParamExpression instead of a float) and can be appended to VQCircuit.
Signature
class VQGateVQGate instances hold a gate type together with ParamExpression references into a Parameter array. At circuit execution time, concrete values are bound through VQCircuit.__call__().
ParamExpression and Parameter are defined in pyqpanda3.vqcircuit; ParamExpression instances are produced by VQCircuit.Param(...).
Variational Gate Factory Functions
Each function returns a VQGate. A param argument of type ParamExpression references a position in the Parameter array that supplies the rotation angle.
Single-Qubit Variational Gates
P (variational)
P(qbit_idx: int, param: ParamExpression) -> VQGate| Parameter | Type | Description |
|---|---|---|
| qbit_idx | int | Target qubit index |
| param | ParamExpression | Symbolic reference into the Parameter array |
Returns a variational P gate.
RX (variational)
RX(qbit_idx: int, param: ParamExpression) -> VQGateReturns a variational
RY (variational)
RY(qbit_idx: int, param: ParamExpression) -> VQGateReturns a variational
RZ (variational)
RZ(qbit_idx: int, param: ParamExpression) -> VQGateReturns a variational
U1 (variational)
U1(qbit_idx: int, param: ParamExpression) -> VQGateReturns a variational U1 gate.
IDLE (variational)
IDLE(qbit_idx: int, param: ParamExpression) -> VQGateReturns a variational IDLE gate.
Two-Parameter Variational Gates
U2 (variational, overload 1)
U2(qbit_idx: int, param1: ParamExpression, param2: Union[float, ParamExpression]) -> VQGate| Parameter | Type | Description |
|---|---|---|
| qbit_idx | int | Target qubit index |
| param1 | ParamExpression | Mutable parameter index for first angle |
| param2 | Union[float, ParamExpression] | Fixed value or mutable parameter index for second angle |
U2 (variational, overload 2)
U2(qbit_idx: int, param1: float, param2: ParamExpression) -> VQGate| Parameter | Type | Description |
|---|---|---|
| qbit_idx | int | Target qubit index |
| param1 | float | Fixed value for first angle |
| param2 | ParamExpression | Mutable parameter index for second angle |
RPhi (variational, overload 1)
RPhi(qbit_idx: int, param1: ParamExpression, param2: Union[float, ParamExpression]) -> VQGate| Parameter | Type | Description |
|---|---|---|
| qbit_idx | int | Target qubit index |
| param1 | ParamExpression | Mutable parameter index for theta |
| param2 | Union[float, ParamExpression] | Fixed value or mutable parameter index for phi |
RPhi (variational, overload 2)
RPhi(qbit_idx: int, param1: float, param2: ParamExpression) -> VQGate| Parameter | Type | Description |
|---|---|---|
| qbit_idx | int | Target qubit index |
| param1 | float | Fixed value for theta |
| param2 | ParamExpression | Mutable parameter index for phi |
Three-Parameter Variational Gates
U3 (variational, overload 1)
U3(qbit_idx: int, param1: ParamExpression, param2: Union[float, ParamExpression], param3: Union[float, ParamExpression]) -> VQGate| Parameter | Type | Description |
|---|---|---|
| qbit_idx | int | Target qubit index |
| param1 | ParamExpression | Mutable parameter index for first angle |
| param2 | Union[float, ParamExpression] | Fixed value or mutable parameter index for second angle |
| param3 | Union[float, ParamExpression] | Fixed value or mutable parameter index for third angle |
U3 (variational, overload 2)
U3(qbit_idx: int, param1: float, param2: ParamExpression, param3: Union[float, ParamExpression]) -> VQGate| Parameter | Type | Description |
|---|---|---|
| qbit_idx | int | Target qubit index |
| param1 | float | Fixed value for first angle |
| param2 | ParamExpression | Mutable parameter index for second angle |
| param3 | Union[float, ParamExpression] | Fixed value or mutable parameter index for third angle |
U3 (variational, overload 3)
U3(qbit_idx: int, param1: float, param2: float, param3: ParamExpression) -> VQGate| Parameter | Type | Description |
|---|---|---|
| qbit_idx | int | Target qubit index |
| param1 | float | Fixed value for first angle |
| param2 | float | Fixed value for second angle |
| param3 | ParamExpression | Mutable parameter index for third angle |
Four-Parameter Variational Gates
U4 (variational, overload 1)
U4(qbit_idx: int, param1: ParamExpression, param2: Union[float, ParamExpression], param3: Union[float, ParamExpression], param4: Union[float, ParamExpression]) -> VQGate| Parameter | Type | Description |
|---|---|---|
| qbit_idx | int | Target qubit index |
| param1 | ParamExpression | Mutable parameter index for first angle |
| param2 | Union[float, ParamExpression] | Fixed value or mutable parameter index for second angle |
| param3 | Union[float, ParamExpression] | Fixed value or mutable parameter index for third angle |
| param4 | Union[float, ParamExpression] | Fixed value or mutable parameter index for fourth angle |
U4 (variational, overload 2)
U4(qbit_idx: int, param1: float, param2: ParamExpression, param3: Union[float, ParamExpression], param4: Union[float, ParamExpression]) -> VQGate| Parameter | Type | Description |
|---|---|---|
| qbit_idx | int | Target qubit index |
| param1 | float | Fixed value for first angle |
| param2 | ParamExpression | Mutable parameter index for second angle |
| param3 | Union[float, ParamExpression] | Fixed value or mutable parameter index for third angle |
| param4 | Union[float, ParamExpression] | Fixed value or mutable parameter index for fourth angle |
U4 (variational, overload 3)
U4(qbit_idx: int, param1: float, param2: float, param3: ParamExpression, param4: Union[float, ParamExpression]) -> VQGate| Parameter | Type | Description |
|---|---|---|
| qbit_idx | int | Target qubit index |
| param1 | float | Fixed value for first angle |
| param2 | float | Fixed value for second angle |
| param3 | ParamExpression | Mutable parameter index for third angle |
| param4 | Union[float, ParamExpression] | Fixed value or mutable parameter index for fourth angle |
U4 (variational, overload 4)
U4(qbit_idx: int, param1: float, param2: float, param3: float, param4: ParamExpression) -> VQGate| Parameter | Type | Description |
|---|---|---|
| qbit_idx | int | Target qubit index |
| param1 | float | Fixed value for first angle |
| param2 | float | Fixed value for second angle |
| param3 | float | Fixed value for third angle |
| param4 | ParamExpression | Mutable parameter index for fourth angle |
Two-Qubit Variational Gates
CU (variational, overload 1)
CU(control_qbit_idx: int, target_qbit_idx: int, param1: ParamExpression, param2: Union[float, ParamExpression], param3: Union[float, ParamExpression], param4: Union[float, ParamExpression]) -> VQGate| Parameter | Type | Description |
|---|---|---|
| control_qbit_idx | int | Control qubit index |
| target_qbit_idx | int | Target qubit index |
| param1 | ParamExpression | Mutable parameter index for first angle |
| param2 | Union[float, ParamExpression] | Fixed value or mutable parameter index for second angle |
| param3 | Union[float, ParamExpression] | Fixed value or mutable parameter index for third angle |
| param4 | Union[float, ParamExpression] | Fixed value or mutable parameter index for 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)
CP(control_qbit_idx: int, target_qbit_idx: int, param: ParamExpression) -> VQGate| Parameter | Type | Description |
|---|---|---|
| control_qbit_idx | int | Control qubit index |
| target_qbit_idx | int | Target qubit index |
| param | ParamExpression | Mutable parameter index |
CRX (variational)
CRX(control_qbit_idx: int, target_qbit_idx: int, param: ParamExpression) -> VQGate| Parameter | Type | Description |
|---|---|---|
| control_qbit_idx | int | Control qubit index |
| target_qbit_idx | int | Target qubit index |
| param | ParamExpression | Mutable parameter index |
CRY (variational)
CRY(control_qbit_idx: int, target_qbit_idx: int, param: ParamExpression) -> VQGate| Parameter | Type | Description |
|---|---|---|
| control_qbit_idx | int | Control qubit index |
| target_qbit_idx | int | Target qubit index |
| param | ParamExpression | Mutable parameter index |
CRZ (variational)
CRZ(control_qbit_idx: int, target_qbit_idx: int, param: ParamExpression) -> VQGate| Parameter | Type | Description |
|---|---|---|
| control_qbit_idx | int | Control qubit index |
| target_qbit_idx | int | Target qubit index |
| param | ParamExpression | Mutable parameter index |
CR (variational, alias for CP)
CR(control_qbit_idx: int, target_qbit_idx: int, param: ParamExpression) -> VQGate| Parameter | Type | Description |
|---|---|---|
| control_qbit_idx | int | Control qubit index |
| target_qbit_idx | int | Target qubit index |
| param | ParamExpression | Mutable parameter index |
RXX (variational)
RXX(control_qbit_idx: int, target_qbit_idx: int, param: ParamExpression) -> VQGate| Parameter | Type | Description |
|---|---|---|
| control_qbit_idx | int | Control qubit index |
| target_qbit_idx | int | Target qubit index |
| param | ParamExpression | Mutable parameter index |
RYY (variational)
RYY(control_qbit_idx: int, target_qbit_idx: int, param: ParamExpression) -> VQGate| Parameter | Type | Description |
|---|---|---|
| control_qbit_idx | int | Control qubit index |
| target_qbit_idx | int | Target qubit index |
| param | ParamExpression | Mutable parameter index |
RZZ (variational)
RZZ(control_qbit_idx: int, target_qbit_idx: int, param: ParamExpression) -> VQGate| Parameter | Type | Description |
|---|---|---|
| control_qbit_idx | int | Control qubit index |
| target_qbit_idx | int | Target qubit index |
| param | ParamExpression | Mutable parameter index |
RZX (variational)
RZX(control_qbit_idx: int, target_qbit_idx: int, param: ParamExpression) -> VQGate| Parameter | Type | Description |
|---|---|---|
| control_qbit_idx | int | Control qubit index |
| target_qbit_idx | int | Target qubit index |
| param | ParamExpression | Mutable parameter index |
Usage with VQCircuit
Variational gates are the building blocks of VQCircuit. A ParamExpression produced by VQCircuit.Param(...) refers to a position in the Parameter array:
from pyqpanda3.vqcircuit import VQCircuit
from pyqpanda3.core import RX, CP
# Create a variational circuit
vqc = VQCircuit()
# Initialize the parameter array: 1D with 3 elements, dimension label "params"
vqc.set_Param([3], ["params"])
# Create parameter placeholders at specific indices with element labels
p0 = vqc.Param([0], "rx0") # parameter for first RX
p1 = vqc.Param([1], "rx1") # parameter for second RX
p2 = vqc.Param([2], "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
print(type(result).__name__)Output:
VQCResult