Hauptinhalt

cr1Gate

Controlled z-axis rotation gate with global phase

Since R2023a

Description

Add-On Required: This feature requires the MATLAB Support Package for Quantum Computing add-on.

g = cr1Gate(controlQubit,targetQubit,theta) applies a controlled R1 gate (controlled z-axis rotation gate with global phase) to a target qubit based on the state of a control qubit and returns a quantum.gate.SimpleGate object. If the control qubit is in the |0 state, then this gate does nothing. If the control qubit is in the |1 state, then this gate changes the phase of the target qubit |1 state by an angle of theta.

  • If controlQubit, targetQubit, and theta are vectors of the same length, cr1Gate returns a column vector of gates, where g(i) represents a controlled R1 gate applied to the ith element triplet of controlQubit, targetQubit, and theta.

  • If any of controlQubit, targetQubit, or theta is a scalar, and at least one of the inputs is a vector, then MATLAB® expands the scalar to match the size of the vector input.

  • The qubit indices in each element pair of controlQubit and targetQubit must not be the same.

example

Examples

collapse all

Create a controlled R1 gate that acts on a control qubit with index 1 and a target qubit with index 2 using a rotation angle of pi/2.

g = cr1Gate(1,2,pi/2)
g = 

  SimpleGate with properties:

             Type: "cr1"
    ControlQubits: 1
     TargetQubits: 2
           Angles: 1.5708

Get the matrix representation of the gate.

M = getMatrix(g)
M =

   1.0000 + 0.0000i   0.0000 + 0.0000i   0.0000 + 0.0000i   0.0000 + 0.0000i
   0.0000 + 0.0000i   1.0000 + 0.0000i   0.0000 + 0.0000i   0.0000 + 0.0000i
   0.0000 + 0.0000i   0.0000 + 0.0000i   1.0000 + 0.0000i   0.0000 + 0.0000i
   0.0000 + 0.0000i   0.0000 + 0.0000i   0.0000 + 0.0000i   0.0000 + 1.0000i

Create an array of three controlled R1 gates. The first gate acts on control qubit 1 and target qubit 2 with rotation angle pi/4, the next gate acts on control qubit 2 and target qubit 3 with rotation angle pi/2, and the final gate acts on control qubit 3 and target qubit 4 with rotation angle 3*pi/4.

g = cr1Gate(1:3,2:4,pi/4*(1:3))
g = 

  3×1 SimpleGate array with gates:

    Id   Gate   Control   Target   Angle
     1   cr1    1         2        pi/4 
     2   cr1    2         3        pi/2 
     3   cr1    3         4        3pi/4

Input Arguments

collapse all

Control qubit of the gate, specified as a positive integer scalar index or vector of qubit indices.

Example: 2

Example: 6:8

Target qubit of the gate, specified as a positive integer scalar index or vector of qubit indices.

Example: 1

Example: 3:5

Rotation angle, specified as a real scalar, real vector, string scalar, string vector, symbolic scalar, or symbolic vector. Specify the rotation angle as a vector to create an array of gates where each element of the vector corresponds to the rotation angle of one gate.

Use strings or symbolic values to specify variables for parameterized rotation angles. You can specify values for parameters when calling the simulate, getMatrix, and observe functions on a quantum circuit that contains parameterized gates. (since R2026a)

Example: pi

Example: (1:3)*pi/2

Example: ["x" "y" "z"]

More About

collapse all

Version History

Introduced in R2023a

expand all