Main Content

quantum.gate.SimpleGate Class

Namespace: quantum.gate

Simple gate for quantum computing

Since R2023a

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

Description

A SimpleGate object represents a simple quantum gate that operates on a small number of qubits. Simple gates are the building blocks of a quantum circuit. You can construct composite gates from a combination of simple gates. You can assign SimpleGate objects to the Gates property of a quantumCircuit object (as a vector of gates) to represent the gate operations of the circuit.

Creation

Use gate creation functions, such as hGate, cxGate, and swapGate, to construct a SimpleGate object. For a complete list of the gate creation functions, see Creation Functions for SimpleGate Objects.

Properties

expand all

Type of the gate, returned as a string scalar.

Example: "h", "x", "swap", "cx"

Attributes:

GetAccess
public
SetAccess
private

Control qubits of the gate, returned as a numeric scalar or numeric row vector of qubit indices indicating which qubits control the gate.

Example: [1 2]

Attributes:

GetAccess
public
SetAccess
private

Target qubits of the gate, returned as a numeric scalar or numeric row vector of qubit indices indicating which qubits the gate acts on.

Example: [3 4]

Attributes:

GetAccess
public
SetAccess
private

Angle that configures the gate, specified as a numeric scalar by which a gate rotates or applies phase shift to its target qubits. If the gate operation does not have an angle parameter, then Angles is always a 1-by-0 empty value.

Example: 1.5708

Attributes:

GetAccess
public
SetAccess
public

Methods

expand all

Examples

collapse all

Create a Hadamard gate acting on a qubit with index 2.

g = hGate(2)
g = 

  SimpleGate with properties:

             Type: "h"
    ControlQubits: [1×0 double]
     TargetQubits: 2
           Angles: [1×0 double]

Create a y-axis rotation gate with a rotation angle of π/2.

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

  SimpleGate with properties:

             Type: "ry"
    ControlQubits: [1×0 double]
     TargetQubits: 1
           Angles: 1.5708

Find its inverse.

ginv = inv(g)
ginv = 

  SimpleGate with properties:

             Type: "ry"
    ControlQubits: [1×0 double]
     TargetQubits: 1
           Angles: -1.5708

Create an array of three controlled x-axis rotation gates. The first gate acts on control qubit 1 and target qubit 4 with rotation angle pi/4. The second gate acts on control qubit 2 and target qubit 4 with rotation angle pi/2. The final gate acts on control qubit 3 and target qubit 4 with rotation angle 3*pi/4.

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

  3×1 SimpleGate array with gates:

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

Version History

Introduced in R2023a