Home Reference Source
import {ControlledGate} from 'projectq/src/ops/metagates.js'
public class | source

ControlledGate

Extends:

BasicGate → ControlledGate

Controlled version of a gate.

Note: Use the meta function :func:C() to create a controlled gate

A wrapper class which enables (multi-) controlled gates. It overloads the or-operator, using the first qubits provided as control qubits. The n control-qubits need to be the first n qubits. They can be in separate quregs.

Example:


ControlledGate(gate, 2) | (qb0, qb2, qb3) # qb0 & qb2 are controls
C(gate, 2) | (qb0, qb2, qb3) # This is much nicer.
C(gate, 2) | ([qb0,qb2], qb3) # Is equivalent

Note:
Use :func:`C` rather than ControlledGate, i.e.,

C(X, 2) == Toffoli

Constructor Summary

Public Constructor
public

Member Summary

Public Members
public

gate: *

public

n: *

Method Summary

Public Methods
public

equal(other: *): boolean

public

getInverse(): *

public

or(qubits: Array<Qureg>)

Apply the controlled gate to qubits, using the first n qubits as controls.

public

Inherited Summary

From class BasicGate
public static

makeTupleOfQureg(qubits: Qubit | Qubit[] | Qureg | Qureg[]): Qureg[]

Convert quantum input of "gate | quantum input" to internal formatting.

public
public
public

equal(other: BasicGate | Object): boolean

public

generateCommand(qubits: *): Command

Helper function to generate a command consisting of the gate and the qubits being acted upon.

public
public
public
public

or(qubits: *)

Operator| overload which enables the syntax Gate | qubits.

public

Public Constructors

public constructor(gate: BasicGate, n: number) source

Override:

BasicGate#constructor

Params:

NameTypeAttributeDescription
gate BasicGate

Gate to wrap.

n number

Number of control qubits.

Public Members

public gate: * source

public n: * source

Public Methods

public equal(other: *): boolean source

Override:

BasicGate#equal

Params:

NameTypeAttributeDescription
other *

Return:

boolean

public getInverse(): * source

Override:

BasicGate#getInverse

Return:

*

public or(qubits: Array<Qureg>) source

Apply the controlled gate to qubits, using the first n qubits as controls.

Note: The control qubits can be split across the first quregs. However, the n-th control qubit needs to be the last qubit in a qureg. The following quregs belong to the gate.

Override:

BasicGate#or

Params:

NameTypeAttributeDescription
qubits Array<Qureg>

qubits to which to apply the gate.

public toString(): string source

Override:

BasicGate#toString

Return:

string