Main Content

cr1Gate

Controlled z-axis rotation gate with global phase

Since R2023a

Installation Required: This functionality requires MATLAB Support Package for Quantum Computing.

Description

example

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.

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 or vector.

Example: pi

Example: (1:3)*pi/2

More About

collapse all

Matrix Representation of Controlled R1 Gate

The matrix representation of a controlled R1 gate applied to control qubit 1 and target qubit 2 with a rotation angle of θ is

[100001000010000exp(iθ)].

Because this gate affects only the |11 state, swapping the control and target qubits does not change the gate operation.

Version History

Introduced in R2023a