pprop.gates.controlledrotation module¶
This submodule defines ControlledRotationGate, the base class for
single-parameter controlled rotation gates, and the concrete gates
CRX, CRY, and CRZ.
Coefficient encoding¶
Controlled rotation gates produce factors of the form
\(\cos(\theta/2)\), \(\sin(\theta/2)\),
\(\cos^2(\theta/2)\), \(\sin^2(\theta/2)\), and
\(\sin(\theta/2)\cos(\theta/2)\). Setting \(p\) =
parameter, these map directly onto CoeffTerm
tuples with repeated indices:
Factor |
CoeffTerm multiplier |
|---|---|
\(\cos(\theta/2)\) |
|
\(\sin(\theta/2)\) |
|
\(\cos^2(\theta/2) = (1+\cos\theta)/2\) |
|
\(\sin^2(\theta/2) = (1-\cos\theta)/2\) |
|
\(\sin(\theta/2)\cos(\theta/2) = \sin(\theta)/2\) |
|
Warning
Half-angle convention for cos(θ/2) and sin(θ/2) terms.
Rules involving cos(θ/2) or sin(θ/2) (e.g. the "XI", "YI"
entries) cannot be represented exactly as CoeffTerm
tuples in θ, only in θ/2. To match PennyLane’s output exactly,
the user must pass θ/2 as the parameter for any CRX,
CRY, or CRZ gate in the ansatz:
# Correct: pass theta/2 so that pprop and PennyLane agree
qml.CRX(params[i] / 2, wires=[0, 1])
# Wrong: pprop will NOT match PennyLane
qml.CRX(params[i], wires=[0, 1])
The (1 \pm \cos\theta)/2 and \sin(\theta)/2 factors (e.g.
"IY", "ZZ" entries) are represented exactly in θ and require
no rescaling.
- class pprop.gates.controlledrotation.CRX(wires, parameter)[source]¶
Bases:
ControlledRotationGateThe controlled-\(R_x\) gate.
\[\begin{split}CR_x(\theta) = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & \cos(\theta) & -i\sin(\theta) \\ 0 & 0 & -i\sin(\theta) & \cos(\theta) \end{bmatrix}\end{split}\]Note
The parameter
θhere corresponds toθ/2in PennyLane’s convention. Passparams[i] / 2toqml.CRXto match.- Parameters:
wires (list[int]) –
[control, target]qubit indices.parameter (int) – Index of \(\\theta\) in the global parameter vector.
- class pprop.gates.controlledrotation.CRY(wires, parameter)[source]¶
Bases:
ControlledRotationGateThe controlled-\(R_y\) gate.
\[\begin{split}CR_y(\theta) = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & \cos(\theta) & -\sin(\theta) \\ 0 & 0 & \sin(\theta) & \cos(\theta) \end{bmatrix}\end{split}\]Note
The parameter
θhere corresponds toθ/2in PennyLane’s convention. Passparams[i] / 2toqml.CRYto match.- Parameters:
wires (list[int]) –
[control, target]qubit indices.parameter (int) – Index of \(\\theta\) in the global parameter vector.
- class pprop.gates.controlledrotation.CRZ(wires, parameter)[source]¶
Bases:
ControlledRotationGateThe controlled-\(R_z\) gate.
\[\begin{split}CR_z(\theta) = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & e^{-i\theta} & 0 \\ 0 & 0 & 0 & e^{i\theta} \end{bmatrix}\end{split}\]Note
The parameter
θhere corresponds toθ/2in PennyLane’s convention. Passparams[i] / 2toqml.CRZto match.- Parameters:
wires (list[int]) –
[control, target]qubit indices.parameter (int) – Index of \(\\theta\) in the global parameter vector.
- class pprop.gates.controlledrotation.ControlledRotationGate(wires, qml_gate, parameter, rule)[source]¶
Bases:
GateBase class for single-parameter two-qubit controlled rotation gates.
Unlike
RotationGate, controlled rotations act non-trivially only when the control qubit is in the \(|1\rangle\) state. This produces factors of \(\cos(\theta/2)\), \(\sin(\theta/2)\), and their squares, each encoded as aCoeffTermwith repeatedparameterentries (see module docstring for the full table).Each rule entry maps a two-character Pauli string
"PQ"(control ⊗ target) to a list of(output_label, multiplier)pairs, wheremultiplieris aCoeffTermwith-1as a placeholder forparameter.- Parameters:
wires (list[int]) –
[control, target]qubit indices.qml_gate (pennylane.operation.Operation) – Corresponding PennyLane gate class.
parameter (int, float) – Index of \(\theta\) in the global parameter vector if int. Actual value of the rotation if float.
rule (EvolutionRule) – Heisenberg evolution rule dict.
- rule¶
The evolution rule for this gate.
- Type:
EvolutionRule
- evolve(word, k1, k2)[source]¶
Heisenberg-evolve a Pauli word through this controlled rotation gate.
For each matching rule entry the existing
CoeffTermsare scaled by the rule’s multiplier: the multiplier’ssin_idxandcos_idx(which use-1as a placeholder) are substituted withself.parameterand then appended to every existing term’s index lists.The weight cutoff
k1is checked on the output Pauli word. The frequency cutoffk2is checked on each existing term before appending new trig factors.