跳转至

BasicGate

QuICT.core.gate.BasicGate

BasicGate(controls: int, targets: int, params: int, type_: GateType, matrix_type: MatrixType = MatrixType.normal, pargs: list = [], precision: str = 'double', is_original_gate: bool = False)

Bases: object

the abstract SuperClass of all basic quantum gate

All basic quantum gate described in the framework have some common attributes and some common functions which defined in this class

Attributes:

  • type(GateType, (read only) –

    gate's type described by GateType

  • matrix_type(MatrixType, (read only) –

    gate matrix's type described by MatrixType

  • precision(str) (read only) –

    The gate's precision, one of [double, single]

  • qasm_name(str, (read only) –

    gate's name in the OpenQASM 2.0

  • matrix(np.array) (read only) –

    the unitary matrix of the quantum gate act on qubits

  • target_matrix(np.array) (read only) –

    the unitary matrix of the quantum gate act on targets

  • targets(int) (read only) –

    the number of the target bits of the gate

  • targs(list<int>) (read only) –

    the list of the index of target bits in the circuit

  • targ(int, (read only) –

    the first object of targs

  • controls(int) (read only) –

    the number of the control bits of the gate

  • cargs(list<int>) (read only) –

    the list of the index of control bits in the circuit

  • carg(int, (read only) –

    the first object of cargs

  • params(list) (read only) –

    the number of the parameter of the gate

  • pargs(list) (read only) –

    the list of the parameter

  • parg(read (only) –

    the first object of pargs

Parameters:

  • controls (int) –

    The number of control qubits

  • targets (int) –

    The number of target qubits

  • params (int) –

    The number of gate's parameters

  • type_ (GateType) –

    The gate's type

  • matrix_type (MatrixType, default: normal ) –

    The gate matrix's type. Defaults to MatrixType.normal.

  • pargs (list, default: [] ) –

    The gate's parameters. Defaults to [].

  • precision (str, default: 'double' ) –

    The gate's precison, one of [double, single]. Defaults to "double".

  • is_original_gate (bool, default: False ) –

    Whether is the initial quantum gate, such as H. Defaults to False.

Source code in QuICT/core/gate/gate.py
def __init__(
    self,
    controls: int,
    targets: int,
    params: int,
    type_: GateType,
    matrix_type: MatrixType = MatrixType.normal,
    pargs: list = [],
    precision: str = "double",
    is_original_gate: bool = False
):
    """
    Args:
        controls (int): The number of control qubits
        targets (int): The number of target qubits
        params (int): The number of gate's parameters
        type_ (GateType): The gate's type
        matrix_type (MatrixType, optional): The gate matrix's type. Defaults to MatrixType.normal.
        pargs (list, optional): The gate's parameters. Defaults to [].
        precision (str, optional): The gate's precison, one of [double, single]. Defaults to "double".
        is_original_gate (bool, optional): Whether is the initial quantum gate, such as H. Defaults to False.
    """
    assert isinstance(controls, int), TypeError("BasicGate.controls", "int", type(controls))
    assert isinstance(targets, int), TypeError("BasicGate.targets", "int", type(targets))
    assert isinstance(params, int), TypeError("BasicGate.params", "int", type(params))
    self._targets = targets
    self._targs = []    # list of int

    self._controls = controls
    self._cargs = []    # list of int

    self._params = params
    self._pargs = []
    self._symbol_gate = False
    self._required_grad = None
    self._variables = 0
    self._free_symbols = []
    self._symbol_pargs = dict()
    if self._params > 0:
        if len(pargs) > 0:
            pargs = self.permit_element(pargs)
        else:
            pargs = GATE_ARGS_MAP[type_]
        self._pargs = pargs    # list of float/..

    assert isinstance(type_, GateType), TypeError("BasicGate.type", "GateType", type(type_))
    assert isinstance(matrix_type, MatrixType), TypeError("BasicGate.matrixtype", "MatrixType", type(type_))
    self._type = type_
    self._matrix_type = matrix_type

    assert precision in ["double", "single"], \
        ValueError("BasicGate.precision", "not within [double, single]", precision)
    self._precision = precision
    self._matrix = None
    self._target_matrix = None
    self._grad_matrix = None
    self._qasm_name = str(type_.name)
    self._is_matrix_update = False
    self._is_original = is_original_gate

__and__

__and__(targets)

deal the operator '&'

Use the syntax "gate & int" or "gate & list" to set gate's attribute. Special uses when in composite gate's context.

Some Examples are like this: X & 1 CX & [0, 1]

Note that the order of qubits is that control bits first and target bits followed.

Parameters:

  • targets

    the targets the gate acts on, it can have following form, 1) int 2) list

Raise

TypeError: the type of targets is wrong

Source code in QuICT/core/gate/gate.py
def __and__(self, targets):
    """deal the operator '&'

    Use the syntax "gate & int" or "gate & list<int>" to set gate's attribute.
    Special uses when in composite gate's context.

    Some Examples are like this:
    X       & 1
    CX      & [0, 1]

    Note that the order of qubits is that control bits first
    and target bits followed.

    Args:
        targets: the targets the gate acts on, it can have following form,
            1) int
            2) list<int>

    Raise:
        TypeError: the type of targets is wrong
    """
    if isinstance(targets, (np.int32, np.int64)):
        targets = int(targets)

    if isinstance(targets, int):
        targets = [targets]

    if not isinstance(targets, list):
        raise TypeError("BasicGate.&", "int or list<int>", type(targets))

    assert len(targets) == self.controls + self.targets, \
        GateQubitAssignedError("The qubits number should equal to the quantum gate.")

    if self._is_original:
        _gate = self.copy()
    else:
        _gate = self

    _gate.cargs = targets[:_gate.controls]
    _gate.targs = targets[_gate.controls:]

    if CGATE_LIST:
        target_cgate = CGATE_LIST[-1]
        if not CGATE_HOLD[target_cgate.name]:
            CGATE_HOLD[target_cgate.name] = True
            target_cgate.append(_gate)
            CGATE_HOLD[target_cgate.name] = False

    return _gate

__call__

__call__(*args, required_grad=None)

give parameters for the gate, and give parameters by "()", and parameters should be one of int/float/complex

Some Examples are like this:

Rz(np.pi / 2) U3(np.pi / 2, 0, 0)

Important: There is no parameters for some quantum gate.

Returns:

  • BasicGate

    the gate after filled by parameters

Source code in QuICT/core/gate/gate.py
def __call__(self, *args, required_grad=None):
    """ give parameters for the gate, and give parameters by "()", and parameters should be one of int/float/complex

    Some Examples are like this:

    Rz(np.pi / 2)
    U3(np.pi / 2, 0, 0)

    *Important*: There is no parameters for some quantum gate.

    Returns:
        BasicGate: the gate after filled by parameters
    """
    assert len(args) == self.params, \
        GateParametersAssignedError("The number of given parameters not matched the quantum gate.")

    if self._is_original:
        _gate = self.copy()
    else:
        _gate = self

    _gate.pargs = list(args)

    if required_grad is None:
        _gate._required_grad = _gate._symbol_gate
    else:
        if required_grad and not _gate.symbol_gate:
            warnings.warn("Cannot calculate gradients for non-symbol gates.")
            _gate._required_grad = False
        else:
            if not required_grad:
                _gate._variables = 0
            _gate._required_grad = required_grad
    return _gate

__or__

__or__(targets)

deal the operator '|'

Use the syntax "gate | circuit" or "gate | Composite Gate" to add the gate into the circuit or composite gate Some Examples are like this:

X | circuit CX | circuit([0, 1]) Measure | CompositeGate

Note that the order of qubits is that control bits first and target bits followed.

Parameters:

  • targets

    the targets the gate acts on, it can have following form, 1) Circuit 2) CompositeGate

Raise

TypeError: the type of other is wrong

Source code in QuICT/core/gate/gate.py
def __or__(self, targets):
    """deal the operator '|'

    Use the syntax "gate | circuit" or "gate | Composite Gate"
    to add the gate into the circuit or composite gate
    Some Examples are like this:

    X       | circuit
    CX      | circuit([0, 1])
    Measure | CompositeGate

    Note that the order of qubits is that control bits first
    and target bits followed.

    Args:
        targets: the targets the gate acts on, it can have following form,
            1) Circuit
            2) CompositeGate

    Raise:
        TypeError: the type of other is wrong
    """
    try:
        targets.append(self)
    except Exception as e:
        raise GateAppendError(f"Failure to append gate {self} to targets, due to {e}")

build_gate

build_gate(qidxes: list = None)

Gate Decomposition, which divided the current gate with a set of small gates.

Source code in QuICT/core/gate/gate.py
def build_gate(self, qidxes: list = None):
    """ Gate Decomposition, which divided the current gate with a set of small gates. """
    if self.type == GateType.cu3:
        cgate = ComplexGateBuilder.build_gate(self.type, self.parg, self.matrix)
    else:
        gate_list = ComplexGateBuilder.build_gate(self.type, self.pargs)
        if gate_list is None:
            return gate_list

        cgate = self._cgate_generator_from_build_gate(gate_list)

    gate_args = self.cargs + self.targs if qidxes is None else qidxes
    if len(gate_args) > 0:
        cgate & gate_args

    return cgate

commutative

commutative(goal: BasicGate, eps=1e-07)

decide whether gate is commutative with another gate

note when the gate is special gates like Unitary, Permutation, Measure and so on, return False.

Parameters:

  • goal(BasicGate)

    the target gate

  • eps(float)

    the precision of comparision

Return

bool: True if commutative

Source code in QuICT/core/gate/gate.py
def commutative(self, goal: BasicGate, eps=1e-7):
    """ decide whether gate is commutative with another gate

    note when the gate is special gates like Unitary, Permutation, Measure and so on, return False.

    Args:
        goal(BasicGate): the target gate
        eps(float): the precision of comparision

    Return:
        bool: True if commutative
    """
    # Check the affected qubits
    self_controls = set(self.cargs)
    self_targets = set(self.targs)
    goal_controls = set(goal.cargs)
    goal_targets = set(goal.targs)
    # If the affected qubits of the gates are completely different, they must commute
    self_qubits = self_controls | self_targets
    goal_qubits = goal_controls | goal_targets
    if len(self_qubits & goal_qubits) == 0:
        return True

    # Ignore all the special gates except for the unitary gates due to the difficulty of getting the matrices
    if (
        (self.is_special() and self.type != GateType.unitary) or
        (goal.is_special() and self.type != GateType.unitary)
    ):
        return False

    # It means commuting that any of the target matrices is close to identity
    if (self.is_identity() or goal.is_identity()):
        return True

    # Check the target matrices of the gates
    A = self.target_matrix
    B = goal.target_matrix
    # For gates whose number of target qubits is 1, optimized judgment could be used
    if self.targets == 1 and goal.targets == 1:
        # Diagonal target gates commutes with the control qubits
        if (
            (len(self_controls & goal_targets) > 0 and not goal.is_diagonal()) or
            (len(goal_controls & self_targets) > 0 and not self.is_diagonal())
        ):
            return False
        # Compute the target matrix commutation
        if (
            len(goal_targets & self_targets) > 0 and
            not np.allclose(A.dot(B), B.dot(A), rtol=eps, atol=eps)
        ):
            return False

        return True
    # Otherwise, we need to calculate the matrix commutation directly
    else:
        # Collect all the affected qubits and create the converter to the minimal qubits
        qubits = self_qubits | goal_qubits
        qubits_dict = {}
        for idx, x in enumerate(qubits):
            qubits_dict[x] = idx
        # Create two masked gates whose affected qubits are the minimal ones
        self_masked = self.cargs + self.targs
        for i in range(len(self_masked)):
            self_masked[i] = qubits_dict[self_masked[i]]
        goal_masked = goal.cargs + goal.targs
        for i in range(len(goal_masked)):
            goal_masked[i] = qubits_dict[goal_masked[i]]
        # Compute the matrix commutation
        self_matrix = self.expand(list(qubits))
        goal_matrix = goal.expand(list(qubits))
        return np.allclose(self_matrix.dot(goal_matrix), goal_matrix.dot(self_matrix), rtol=eps, atol=eps)

copy

copy()

return a copy of this gate

Returns:

Source code in QuICT/core/gate/gate.py
def copy(self):
    """ return a copy of this gate

    Returns:
        gate(BasicGate): a copy of this gate
    """
    pargs = [parg for parg in self.pargs]
    gate = BasicGate(
        self.controls, self.targets, self.params, self.type,
        self.matrix_type, pargs, self.precision
    )

    if len(self.targs) > 0:
        gate.targs = self.targs[:]

    if self.controls > 0 and len(self.cargs) > 0:
        gate.cargs = self.cargs[:]

    gate._required_grad = self._required_grad
    gate._free_symbols = self._free_symbols.copy()
    gate._symbol_pargs = self._symbol_pargs.copy()
    return gate

expand

expand(qubits: Union[int, list], device: str = 'CPU') -> bool

expand self matrix into the circuit's unitary linear space. If input qubits is integer, please make sure the indexes of current gate is within [0, qubits).

Parameters:

  • qubits (Union[int, list]) –

    the total number of qubits of the target circuit or the indexes of expand qubits.

Source code in QuICT/core/gate/gate.py
def expand(self, qubits: Union[int, list], device: str = "CPU") -> bool:
    """ expand self matrix into the circuit's unitary linear space. If input qubits is integer, please make sure
    the indexes of current gate is within [0, qubits).

    Args:
        qubits Union[int, list]: the total number of qubits of the target circuit or the indexes of expand qubits.
    """
    if isinstance(qubits, int):
        qubits = list(range(qubits))

    qubits_num = len(qubits)
    if qubits_num == self.controls + self.targets:
        return self.matrix

    assert qubits_num > self.controls + self.targets, GateQubitAssignedError(
        "The expand qubits' num should >= gate's qubits num."
    )
    gate_args = self.cargs + self.targs
    if len(gate_args) == 0:     # Deal with not assigned quantum gate
        gate_args = [qubits[i] for i in range(self.controls + self.targets)]

    updated_args = [qubits.index(garg) for garg in gate_args]
    return matrix_product_to_circuit(self.matrix, updated_args, qubits_num, device)

init_pargs

init_pargs(symbols: list, values: Union[list, ndarray])

Initialize the trainable parameters of the gate.

Parameters:

  • symbols (list) –

    The symbols that needs to be assigned values.

  • values (Union[list, ndarray]) –

    The values to be assigned.

Source code in QuICT/core/gate/gate.py
def init_pargs(self, symbols: list, values: Union[list, np.ndarray]):
    """Initialize the trainable parameters of the gate.

    Args:
        symbols (list): The symbols that needs to be assigned values.
        values (Union[list, np.ndarray]): The values to be assigned.
    """
    assert self._symbol_gate, "Only the parameters of symbol gates can be initialized."
    if not isinstance(symbols, list):
        symbols = [symbols]
    if not isinstance(values, (list, np.ndarray)):
        values = [values]
    assert len(set(symbols)) == len(symbols), "There cannot be duplicates in symbols list."
    assert len(symbols) == len(values), "The symbols list and values list must match one-to-one."

    for symbol, value in zip(symbols, values):
        if not isinstance(value, numbers.Number):
            raise TypeError("basicGate.pargs", "Number", type(value))
        if symbol in self._free_symbols:
            for key in self._symbol_pargs.keys():
                if symbol == key.symbol:
                    self._symbol_pargs[key] = value * key.multiplier

inverse

inverse()

the inverse of the quantum gate, if there is no inverse gate, return itself.

Return

BasicGate: the inverse of the gate

Source code in QuICT/core/gate/gate.py
def inverse(self):
    """ the inverse of the quantum gate, if there is no inverse gate, return itself.

    Return:
        BasicGate: the inverse of the gate
    """
    if self.symbol_gate:
        assert self.assigned_value, "The symbol gate must be assigned values before calculation."
        pargs = []
        for i in range(self.params):
            pargs.append(self.symbol_pargs[self.pargs[i]])
    else:
        pargs = self.pargs
    inverse_gargs, inverse_pargs = InverseGate.get_inverse_gate(self.type, pargs)

    # Deal with inverse_gargs
    if inverse_gargs is None:
        return self

    inverse_gate = gate_builder(inverse_gargs, params=inverse_pargs)
    gate_args = self.cargs + self.targs
    if len(gate_args) > 0:
        inverse_gate & gate_args

    return inverse_gate

is_clifford

is_clifford() -> bool

judge whether gate's matrix is a Clifford gate

Returns:

  • bool ( bool ) –

    True if gate's matrix is a Clifford gate

Source code in QuICT/core/gate/gate.py
def is_clifford(self) -> bool:
    """ judge whether gate's matrix is a Clifford gate

    Returns:
        bool: True if gate's matrix is a Clifford gate
    """
    return self.type in CLIFFORD_GATE_SET

is_control_single

is_control_single() -> bool

judge whether gate has one control bit and one target bit

Returns:

  • bool ( bool ) –

    True if it is has one control bit and one target bit

Source code in QuICT/core/gate/gate.py
def is_control_single(self) -> bool:
    """ judge whether gate has one control bit and one target bit

    Returns:
        bool: True if it is has one control bit and one target bit
    """
    return self.controls == 1 and self.targets == 1

is_diagonal

is_diagonal() -> bool

judge whether gate's matrix is diagonal

Returns:

  • bool ( bool ) –

    True if gate's matrix is diagonal

Source code in QuICT/core/gate/gate.py
def is_diagonal(self) -> bool:
    """ judge whether gate's matrix is diagonal

    Returns:
        bool: True if gate's matrix is diagonal
    """
    return self.matrix_type in [MatrixType.diagonal, MatrixType.control]

is_identity

is_identity() -> bool

judge whether gate's matrix is identity matrix

Returns:

  • bool ( bool ) –

    True if gate's matrix is identity

Source code in QuICT/core/gate/gate.py
def is_identity(self) -> bool:
    """ judge whether gate's matrix is identity matrix

    Returns:
        bool: True if gate's matrix is identity
    """
    return self.type == GateType.id or self.matrix_type == MatrixType.identity

is_pauli

is_pauli() -> bool

judge whether gate's matrix is a Pauli gate

Returns:

  • bool ( bool ) –

    True if gate's matrix is a Pauli gate

Source code in QuICT/core/gate/gate.py
def is_pauli(self) -> bool:
    """ judge whether gate's matrix is a Pauli gate

    Returns:
        bool: True if gate's matrix is a Pauli gate
    """
    return self.type in PAULI_GATE_SET

is_single

is_single() -> bool

judge whether gate is a one qubit gate(excluding special gate like measure, reset, custom and so on)

Returns:

  • bool ( bool ) –

    True if it is a one qubit gate

Source code in QuICT/core/gate/gate.py
def is_single(self) -> bool:
    """ judge whether gate is a one qubit gate(excluding special gate like measure, reset, custom and so on)

    Returns:
        bool: True if it is a one qubit gate
    """
    return self.targets + self.controls == 1

is_special

is_special() -> bool

judge whether gate's is special gate, which is one of [Measure, Reset, Barrier, Perm, ...]

Returns:

  • bool ( bool ) –

    True if gate's matrix is special

Source code in QuICT/core/gate/gate.py
def is_special(self) -> bool:
    """ judge whether gate's is special gate, which is one of
    [Measure, Reset, Barrier, Perm, ...]

    Returns:
        bool: True if gate's matrix is special
    """
    return self.matrix_type == MatrixType.special

permit_element

permit_element(element)

judge whether the type of a parameter is int/float/complex

for a quantum gate, the parameter should be int/float/complex

Parameters:

  • element

    the element to be judged

Returns:

  • bool

    True if the type of element is int/float/complex

Source code in QuICT/core/gate/gate.py
def permit_element(self, element):
    """ judge whether the type of a parameter is int/float/complex

    for a quantum gate, the parameter should be int/float/complex

    Args:
        element: the element to be judged

    Returns:
        bool: True if the type of element is int/float/complex
    """
    if not isinstance(element, list):
        element = [element]

    assert len(element) == self.params, \
        ValueError("BasicGate.pargs:length", f"equal to gate's parameter number {self._params}", len(element))

    for i in range(self._params):
        if not isinstance(element[i], (numbers.Number, str, Parameter)):
            raise TypeError("basicGate.pargs", "Number/str/Parameter", type(element[i]))
        if isinstance(element[i], str):
            element[i] = Parameter(element[i])
        if isinstance(element[i], Parameter):
            self._symbol_gate = True
            if element[i].symbol not in self._free_symbols:
                self._free_symbols.append(element[i].symbol)
            self._variables += 1
            self._symbol_pargs[element[i]] = None
    return element

qasm

qasm(targs: list = None)

generator OpenQASM string for the gate

Return

string: the OpenQASM 2.0 describe of the gate

Source code in QuICT/core/gate/gate.py
def qasm(self, targs: list = None):
    """ generator OpenQASM string for the gate

    Return:
        string: the OpenQASM 2.0 describe of the gate
    """
    if self.type in [GateType.perm, GateType.perm_fx]:
        raise QASMError(f"This gate do not support qasm, {self.type}")
    if self.symbol_gate and not self.assigned_value:
        raise QASMError("Symbol gates must be assigned values before generating qasm.")

    qasm_string = self.qasm_name
    if self.params > 0:
        params = []
        for parg in self.pargs:
            parg = self.symbol_pargs[parg] if isinstance(parg, Parameter) else parg
            params.append(str(parg))
        params_string = "(" + ", ".join(params) + ")"

        qasm_string += params_string

    qubit_idxes = self.cargs + self.targs if targs is None else targs
    ctargs = [f"q[{ctarg}]" for ctarg in qubit_idxes]
    ctargs_string = " " + ', '.join(ctargs) + ";\n"
    qasm_string += ctargs_string

    return qasm_string

QuICT.core.gate.Unitary

Unitary(matrix: Union[list, ndarray], matrix_type: MatrixType = None, name: str = None, is_kraus: bool = False)

Bases: BasicGate

The class about the Unitary Quantum Gate

Parameters:

  • matrix (Union[list, ndarray]) –

    The unitary matrix.

  • matrix_type (MatrixType, default: None ) –

    The matrix's type. Defaults to None.

  • name (str, default: None ) –

    The unitary gate's name

Source code in QuICT/core/gate/gate.py
def __init__(
    self,
    matrix: Union[list, np.ndarray],
    matrix_type: MatrixType = None,
    name: str = None,
    is_kraus: bool = False
):
    """
    Args:
        matrix (Union[list, np.ndarray]): The unitary matrix.
        matrix_type (MatrixType, optional): The matrix's type. Defaults to None.
        name (str): The unitary gate's name
    """
    self._name = name if name is not None else "U_" + unique_id_generator()
    self._is_kraus = is_kraus

    # Validate matrix type
    self.validate_matrix_shape(matrix)

    # Validate Matrix Type
    n = int(np.log2(matrix.shape[0]))
    validate_matrix_type, targets = self.validate_matrix_type(matrix)
    if matrix_type is not None:
        validate_matrix_type = matrix_type

    precision = "double" if matrix.dtype == np.complex128 else "single"
    super().__init__(
        controls=n - targets, targets=targets, params=0,
        type_=GateType.unitary, matrix_type=validate_matrix_type, precision=precision
    )
    self._matrix = matrix

validate_matrix_type staticmethod

validate_matrix_type(matrix: ndarray) -> MatrixType

Check the matrix's type about given unitary matrix

Parameters:

  • matrix (ndarry) –

    The given unitary matrix

Returns:

Source code in QuICT/core/gate/gate.py
@staticmethod
def validate_matrix_type(matrix: np.ndarray) -> MatrixType:
    """ Check the matrix's type about given unitary matrix

    Args:
        matrix (np.ndarry): The given unitary matrix

    Returns:
        MatrixType: The matrix type
    """
    length = matrix.shape[0]
    diagonal_value = np.diag(matrix)
    reverse_diag_value = np.diag(np.fliplr(matrix))

    if np.allclose(matrix, np.diag(diagonal_value)):
        matrix_type = MatrixType.diagonal
    elif np.allclose(np.fliplr(matrix), np.diag(reverse_diag_value)):
        matrix_type = MatrixType.reverse
    else:
        matrix_type = MatrixType.normal

    if matrix_type == MatrixType.reverse:
        return matrix_type, int(np.log2(length))

    target_value = reverse_diag_value if matrix_type == MatrixType.reverse else diagonal_value
    controls = (target_value != 1).argmax()
    # Validate Identity Matrix or Control Matrix
    if controls == 0 and target_value[0] == 1 and matrix_type == MatrixType.diagonal:
        return MatrixType.identity, int(np.log2(length))

    if (
        matrix_type == MatrixType.normal and
        not np.allclose(matrix[:controls, :controls], np.diag(target_value[:controls]))
    ):
        controls = 0

    targets = length - controls
    if targets == 1 and matrix_type == MatrixType.diagonal:
        return MatrixType.control, 1

    # Get Control qubits and target qubits
    target_number = int(np.ceil(np.log2(length - controls)))
    return matrix_type, target_number

QuICT.core.gate.Perm

Perm(targets: int, params: list)

Bases: BasicGate

Parameters:

  • n (int) –

    the number of target qubits

  • params (list[int]) –

    the list of index, and the index represent which should be 1.

Returns:

  • PermGate

    the Perm Gate.

Source code in QuICT/core/gate/gate.py
def __init__(self, targets: int, params: list):
    """
    Args:
        n (int): the number of target qubits
        params (list[int]): the list of index, and the index represent which should be 1.

    Returns:
        PermGate: the Perm Gate.
    """
    if not isinstance(params, list) or not isinstance(targets, int):
        raise TypeError(f"targets must be int {type(targets)}, params must be list {type(params)}")

    assert len(params) == targets, GateParametersAssignedError("the length of params must equal to targets")
    assert len(set(params)) == targets, ValueError("PermGate.params", "have no duplicated value", params)

    pargs = []
    for parg in params:
        if not isinstance(parg, int):
            raise TypeError("PermGate.params.values", "int", type(parg))

        if parg < 0 or parg >= targets:
            raise ValueError("PermGate.params.values", f"[0, {targets}]", parg)

        pargs.append(parg)

    super().__init__(0, targets, targets, GateType.perm, MatrixType.normal, pargs)

QuICT.core.gate.MultiControlGate

MultiControlGate(controls: int, gate_type: GateType, precision: str = 'double', params: list = [])

Bases: BasicGate

The multi-control qubits quantum gate.

Parameters:

  • controls (int) –

    The number of control qubits

  • gate_type (GateType) –

    The based quantum gate

  • precision (str, default: 'double' ) –

    The precison for quantum gate. Defaults to "double".

  • params (list, default: [] ) –

    The parameters for based quantum gate. Defaults to [].

Source code in QuICT/core/gate/gate.py
def __init__(self, controls: int, gate_type: GateType, precision: str = "double", params: list = []):
    """
    Args:
        controls (int): The number of control qubits
        gate_type (GateType): The based quantum gate
        precision (str, optional): The precison for quantum gate. Defaults to "double".
        params (list, optional): The parameters for based quantum gate. Defaults to [].
    """
    assert controls >= 0, ValueError("MultiControlGate.controls", ">= 0", controls)
    self._multi_controls = controls
    if gate_type not in GATEINFO_MAP.keys():
        raise TypeError("MultiControlGate.gate_type", "only support for QuICT Gate", gate_type)

    gate_info = list(GATEINFO_MAP[gate_type])
    gate_info[0] += controls
    super().__init__(*gate_info, params, precision)

inverse

inverse()

the inverse of the quantum gate, if there is no inverse gate, return itself.

Return

BasicGate: the inverse of the gate

Source code in QuICT/core/gate/gate.py
def inverse(self):
    """ the inverse of the quantum gate, if there is no inverse gate, return itself.

    Return:
        BasicGate: the inverse of the gate
    """
    if self.symbol_gate:
        assert self.assigned_value, "The symbol gate must be assigned values before calculation."
        pargs = []
        for i in range(self.params):
            pargs.append(self.symbol_pargs[self.pargs[i]])
    else:
        pargs = self.pargs
    inverse_gargs, inverse_pargs = InverseGate.get_inverse_gate(self.type, pargs)

    # Deal with inverse_gargs
    if inverse_gargs is None:
        return self

    inverse_gate = MultiControlGate(self._multi_controls, inverse_gargs, self.precision, params=inverse_pargs)
    gate_args = self.cargs + self.targs
    if len(gate_args) > 0:
        inverse_gate & gate_args

    return inverse_gate

QuICT.core.gate.Kraus

Kraus(matrix: ndarray)

Bases: BasicGate

Source code in QuICT/core/gate/gate.py
def __init__(self, matrix: np.ndarray):
    super().__init__(
        controls=0, targets=1, params=0, type_=GateType.kraus
    )
    self._matrix = matrix

expand

expand(qubits: Union[int, list], device: str = 'CPU') -> bool

expand self matrix into the circuit's unitary linear space. If input qubits is integer, please make sure the indexes of current gate is within [0, qubits).

Parameters:

  • qubits (Union[int, list]) –

    the total number of qubits of the target circuit or the indexes of expand qubits.

Source code in QuICT/core/gate/gate.py
def expand(self, qubits: Union[int, list], device: str = "CPU") -> bool:
    """ expand self matrix into the circuit's unitary linear space. If input qubits is integer, please make sure
    the indexes of current gate is within [0, qubits).

    Args:
        qubits Union[int, list]: the total number of qubits of the target circuit or the indexes of expand qubits.
    """
    if isinstance(qubits, int):
        qubits = list(range(qubits))

    qubits_num = len(qubits)
    if qubits_num == self.controls + self.targets:
        return self.matrix

    assert qubits_num > self.controls + self.targets, GateQubitAssignedError(
        "The expand qubits' num should >= gate's qubits num."
    )
    gate_args = self.cargs + self.targs
    if len(gate_args) == 0:     # Deal with not assigned quantum gate
        gate_args = [qubits[i] for i in range(self.controls + self.targets)]

    updated_args = [qubits.index(garg) for garg in gate_args]
    expand_matrix = [
        matrix_product_to_circuit(mat, updated_args, qubits_num, device) for mat in self._matrix
    ]

    return expand_matrix

QuICT.core.gate.gate_builder

gate_builder(gate_type, precision: str = 'double', params: list = [], random_params: bool = False) -> BasicGate

Build the target Quantum Gate.

Parameters:

  • gate_type (GateType) –

    The gate's type.

  • precision (str, default: 'double' ) –

    The gate's precision. Defaults to "double".

  • params (list, default: [] ) –

    The gate's parameters. Defaults to [].

  • random_params (bool, default: False ) –

    Whether using random parameters. Defaults to False.

Returns:

  • BasicGate ( BasicGate ) –

    The class of target quantum gate

Source code in QuICT/core/gate/gate.py
def gate_builder(gate_type, precision: str = "double", params: list = [], random_params: bool = False) -> BasicGate:
    """ Build the target Quantum Gate.

    Args:
        gate_type (GateType): The gate's type.  \n
        precision (str, optional): The gate's precision. Defaults to "double".  \n
        params (list, optional): The gate's parameters. Defaults to [].  \n
        random_params (bool, optional): Whether using random parameters. Defaults to False.

    Returns:
        BasicGate: The class of target quantum gate
    """
    if gate_type not in GATEINFO_MAP.keys():
        raise TypeError("gate_builder.gate_type", "only support for fixed qubits gate", gate_type)

    gate_info = GATEINFO_MAP[gate_type]
    if random_params:
        params = list(np.random.uniform(0, 2 * np.pi, gate_info[2]))

    return BasicGate(
        *gate_info, params, precision
    )

QuICT.core.gate.H module-attribute

H = BasicGate(*GATEINFO_MAP[h], is_original_gate=True)

Single-Qubit Hadamard Gate, which apply a pi rotation about the X and Z axis.

[Matrix Representation]

\[ H = \frac{1}{\sqrt{2}} \begin{bmatrix} 1 & 1 \\ 1 & -1 \\ \end{bmatrix} \]

[How to apply]

H | circuit(0)
H & 0 | circuit

[Graph Representation]

      ┌───┐
q0: ──┤ h ├──
      └───┘

[QASM Representation]

h q[0]

QuICT.core.gate.Hy module-attribute

Hy = BasicGate(*GATEINFO_MAP[hy], is_original_gate=True)

Single-Qubit Hy Gate.

[Matrix Representation]

\[ Hy = \frac{1}{\sqrt{2}} \begin{bmatrix} 1 & -i \\ i & -1 \\ \end{bmatrix} \]

[How to apply]

Hy | circuit(0)
Hy & 0 | circuit

[Graph Representation]

      ┌────┐
q0: ──┤ hy ├──
      └────┘

[QASM Representation]

hy q[0]

QuICT.core.gate.S module-attribute

S = BasicGate(*GATEINFO_MAP[s], is_original_gate=True)

Single-Qubit S Gate, same as \(Z^0.5\) Gate. It produce a phase of pi/2.

[Matrix Representation]

\[ S = \begin{bmatrix} 1 & 0 \\ 0 & i \\ \end{bmatrix} \]

[How to apply]

S | circuit(0)
S & 0 | circuit

[Graph Representation]

      ┌───┐
q0: ──┤ s ├──
      └───┘

[QASM Representation]

s q[0]

QuICT.core.gate.S_dagger module-attribute

S_dagger = BasicGate(*GATEINFO_MAP[sdg], is_original_gate=True)

Single-Qubit S_dagger Gate, which produce a phase of -pi / 2.

[Matrix Representation]

\[ Sdg = \begin{bmatrix} 1 & 0 \\ 0 & -i \\ \end{bmatrix} \]

[How to apply]

S_dagger | circuit(0)
S_dagger & 0 | circuit

[Graph Representation]

      ┌─────┐
q0: ──┤ sdg ├──
      └─────┘

[QASM Representation]

sdg q[0]

QuICT.core.gate.X module-attribute

X = BasicGate(*GATEINFO_MAP[x], is_original_gate=True)

Single-Qubit Pauli-X Gate.

[Matrix Representation]

\[ X = \begin{bmatrix} 0 & 1 \\ 1 & 0 \\ \end{bmatrix} \]

[How to apply]

X | circuit(0)
X & 0 | circuit

[Graph Representation]

       ┌───┐
     ──┤ x ├──
       └───┘

[QASM Representation]

x q[0]

QuICT.core.gate.Y module-attribute

Y = BasicGate(*GATEINFO_MAP[y], is_original_gate=True)

Single-Qubit Pauli-Y Gate.

[Matrix Representation]

\[ Y = \begin{bmatrix} 0 & -i \\ i & 0 \\ \end{bmatrix} \]

[How to apply]

Y | circuit(0)
Y & 0 | circuit

[Graph Representation]

      ┌───┐
q0: ──┤ y ├──
      └───┘

[QASM Representation]

y q[0]

QuICT.core.gate.Z module-attribute

Z = BasicGate(*GATEINFO_MAP[z], is_original_gate=True)

Single-Qubit Pauli-Z Gate.

[Matrix Representation]

\[ Z = \begin{bmatrix} 1 & 0 \\ 0 & -1 \\ \end{bmatrix} \]

[How to apply]

Z | circuit(0)
Z & 0 | circuit

[Graph Representation]

      ┌───┐
q0: ──┤ z ├──
      └───┘

[QASM Representation]

z q[0]

QuICT.core.gate.SX module-attribute

SX = BasicGate(*GATEINFO_MAP[sx], is_original_gate=True)

Single-Qubit Sqrt-X Gate.

[Matrix Representation]

\[ SX = \frac{1}{2} \begin{bmatrix} 1 + i & 1 - i \\ 1 - i & 1 + i \\ \end{bmatrix} \]

[How to apply]

SX | circuit(0)
SX & 0 | circuit

[Graph Representation]

      ┌────┐
q0: ──┤ sx ├──
      └────┘

[QASM Representation]

sx q[0]

QuICT.core.gate.SX_dagger module-attribute

SX_dagger = BasicGate(*GATEINFO_MAP[sxdg], is_original_gate=True)

Single-Qubit Sqrt-X Dagger Gate.

[Matrix Representation]

\[ SXdg = \frac{1}{2} \begin{bmatrix} 1 - i & 1 + i \\ 1 + i & 1 - i \\ \end{bmatrix} \]

[How to apply]

SX_dagger | circuit(0)
SX_dagger & 0 | circuit

[Graph Representation]

      ┌──────┐
q0: ──┤ sxdg ├──
      └──────┘

[QASM Representation]

sxdg q[0]

QuICT.core.gate.SY module-attribute

SY = BasicGate(*GATEINFO_MAP[sy], is_original_gate=True)

Single-Qubit Sqrt-Y Gate.

[Matrix Representation]

\[ SY = \frac{1}{\sqrt{2}} \begin{bmatrix} 1 & -1 \\ 1 & 1 \\ \end{bmatrix} \]

[How to apply]

SY | circuit(0)
SY & 0 | circuit

[Graph Representation]

      ┌────┐
q0: ──┤ sy ├──
      └────┘

[QASM Representation]

sy q[0]

QuICT.core.gate.SY_dagger module-attribute

SY_dagger = BasicGate(*GATEINFO_MAP[sydg], is_original_gate=True)

Single-Qubit Sqrt-Y Dagger Gate.

[Matrix Representation]

\[ SYdg = \frac{1}{\sqrt{2}} \begin{bmatrix} 1 & 1 \\ -1 & 1 \\ \end{bmatrix} \]

[How to apply]

SY_dagger | circuit(0)
SY_dagger & 0 | circuit

[Graph Representation]

      ┌──────┐
q0: ──┤ sydg ├──
      └──────┘

[QASM Representation]

sydg q[0]

QuICT.core.gate.SW module-attribute

SW = BasicGate(*GATEINFO_MAP[sw], is_original_gate=True)

Single-Qubit Sqrt-W Gate.

[Matrix Representation]

\[ SW = \begin{bmatrix} \frac{1}{\sqrt{2}} & -\sqrt{\frac{i}{2}} \\ \sqrt{\frac{-i}{2}} & \frac{1}{\sqrt{2}} \\ \end{bmatrix} \]

[How to apply]

SW | circuit(0)
SW & 0 | circuit

[Graph Representation]

      ┌────┐
q0: ──┤ sw ├──
      └────┘

[QASM Representation]

sw q[0]

QuICT.core.gate.ID module-attribute

ID = BasicGate(*GATEINFO_MAP[id], is_original_gate=True)

Single-Qubit Identity Gate.

[Matrix Representation]

\[ ID = \begin{bmatrix} 1 & 0 \\ 0 & 1 \\ \end{bmatrix} \]

[How to apply]

ID | circuit(0)
ID & 0 | circuit

[Graph Representation]

      ┌────┐
q0: ──┤ id ├──
      └────┘

[QASM Representation]

id q[0]

QuICT.core.gate.U1 module-attribute

U1 = BasicGate(*GATEINFO_MAP[u1], is_original_gate=True)

Single-Qubit Rotation Gate, which apply an \(\lambda\) rotation about Z axis.

[Matrix Representation]

\[ U1(\lambda) = \begin{bmatrix} 1 & 0 \\ 0 & e^{i\lambda} \\ \end{bmatrix} \]

[How to apply]

U1(pi) | circuit(0)
U1(pi) & 0 | circuit

[Graph Representation]

      ┌────────┐
q0: ──┤ u1(pi) ├──
      └────────┘

[QASM Representation]

u1(pi) q[0]

QuICT.core.gate.U2 module-attribute

U2 = BasicGate(*GATEINFO_MAP[u2], is_original_gate=True)

Single-Qubit Rotation Gate about X and Z axis.

[Matrix Representation]

\[ U2(\sigma, \lambda) = \frac{1}{\sqrt{2}} \begin{bmatrix} 1 & -e^{i\lambda} \\ e^{i\sigma} & e^{i(\lambda + \sigma)} \\ \end{bmatrix} \]

[How to apply]

U2(0, pi) | circuit(0)
U2(0, pi) & 0 | circuit

[Graph Representation]

      ┌───────────┐
q0: ──┤ u2(0, pi) ├──
      └───────────┘

[QASM Representation]

u2(0, pi) q[0]

QuICT.core.gate.U3 module-attribute

U3 = BasicGate(*GATEINFO_MAP[u3], is_original_gate=True)

Single-Qubit Rotation Gate with three Euler Angles.

[Matrix Representation]

\[ U3(\theta, \sigma, \lambda) = \begin{bmatrix} \cos(\frac{\theta}{2}) & -e^{i\lambda}\sin(\frac{\theta}{2}) \\ e^{i\sigma}\sin(\frac{\theta}{2}) & e^{i(\lambda + \sigma)}\cos(\frac{\theta}{2}) \\ \end{bmatrix} \]

[How to apply]

U3(0, pi, 1) | circuit(0)
U3(0, pi, 1) & 0 | circuit

[Graph Representation]

      ┌──────────────┐
q0: ──┤ u3(0, pi, 1) ├──
      └──────────────┘

[QASM Representation]

u3(0, pi, 1) q[0]

QuICT.core.gate.Rx module-attribute

Rx = BasicGate(*GATEINFO_MAP[rx], is_original_gate=True)

Single-Qubit Rotation Gate, which apply an \(\lambda\) rotation about X axis.

[Matrix Representation]

\[ Rx(\lambda) = \begin{bmatrix} \cos(\frac{\lambda}{2}) & -i\sin(\frac{\lambda}{2}) \\ -i\sin(\frac{\lambda}{2}) & \cos(\frac{\lambda}{2}) \\ \end{bmatrix} \]

[How to apply]

Rx(pi) | circuit(0)
Rx(pi) & 0 | circuit

[Graph Representation]

      ┌────────┐
q0: ──┤ rx(pi) ├──
      └────────┘

[QASM Representation]

rx(pi) q[0]

QuICT.core.gate.Ry module-attribute

Ry = BasicGate(*GATEINFO_MAP[ry], is_original_gate=True)

Single-Qubit Rotation Gate, which apply an \(\lambda\) rotation about Y axis. [Matrix Representation]

\[ Ry(\lambda) = \begin{bmatrix} \cos(\frac{\lambda}{2}) & -\sin(\frac{\lambda}{2}) \\ \sin(\frac{\lambda}{2}) & \cos(\frac{\lambda}{2}) \\ \end{bmatrix} \]

[How to apply]

Ry(pi) | circuit(0)
Ry(pi) & 0 | circuit

[Graph Representation]

      ┌────────┐
q0: ──┤ ry(pi) ├──
      └────────┘

[QASM Representation]

ry(pi) q[0]

QuICT.core.gate.Rz module-attribute

Rz = BasicGate(*GATEINFO_MAP[rz], is_original_gate=True)

Single-Qubit Rotation Gate, which apply an \(\lambda\) rotation about Z axis.

[Matrix Representation]

\[ Rz(\lambda) = \begin{bmatrix} e^{\frac{-i\lambda}{2}} & 0 \\ 0 & e^{\frac{i\lambda}{2}} \\ \end{bmatrix} \]

[How to apply]

Rz(pi) | circuit(0)
Rz(pi) & 0 | circuit

[Graph Representation]

      ┌────────┐
q0: ──┤ rz(pi) ├──
      └────────┘

[QASM Representation]

rz(pi) q[0]

QuICT.core.gate.T module-attribute

T = BasicGate(*GATEINFO_MAP[t], is_original_gate=True)

Single-Qubit T Gate, which produce a \(\frac{pi}{4}\) phase. Its matrix equals \(Rz(\frac{pi}{4})\).

[Matrix Representation]

\[ T = \begin{bmatrix} 1 & 0 \\ 0 & \frac{1}{\sqrt{2}} + \frac{i}{\sqrt{2}} \\ \end{bmatrix} \]

[How to apply]

T | circuit(0)
T & 0 | circuit

[Graph Representation]

      ┌───┐
q0: ──┤ t ├──
      └───┘

[QASM Representation]

t q[0]

QuICT.core.gate.T_dagger module-attribute

T_dagger = BasicGate(*GATEINFO_MAP[tdg], is_original_gate=True)

Single-Qubit T Dagger Gate, which produce a -pi/4 phase.

[Matrix Representation]

\[ Tdg = \begin{bmatrix} 1 & 0 \\ 0 & \frac{1}{\sqrt{2}} - \frac{i}{\sqrt{2}} \\ \end{bmatrix} \]

[How to apply]

T_dagger | circuit(0)
T_dagger & 0 | circuit

[Graph Representation]

      ┌─────┐
q0: ──┤ tdg ├──
      └─────┘

[QASM Representation]

tdg q[0]

QuICT.core.gate.Phase module-attribute

Phase = BasicGate(*GATEINFO_MAP[phase], is_original_gate=True)

Single-Qubit Rotation Gate about Z axis.

[Matrix Representation]

\[ Phase(\lambda) = \begin{bmatrix} 1 & 0 \\ 0 & e^{i\lambda} \\ \end{bmatrix} \]

[How to apply]

Phase(pi) | circuit(0)
Phase(pi) & 0 | circuit

[Graph Representation]

      ┌───────────┐
q0: ──┤ phase(pi) ├──
      └───────────┘

[QASM Representation]

phase(pi) q[0]

QuICT.core.gate.GPhase module-attribute

GPhase = BasicGate(*GATEINFO_MAP[gphase], is_original_gate=True)

Global Phase Gate.

[Matrix Representation]

\[ GPhase(\lambda) = \begin{bmatrix} e^{i\lambda} & 0 \\ 0 & e^{i\lambda} \\ \end{bmatrix} \]

[How to apply]

GPhase(pi) | circuit(0)
GPhase(pi) & 0 | circuit

[Graph Representation]

      ┌────────────┐
q0: ──┤ gphase(pi) ├──
      └────────────┘

[QASM Representation]

gphase(pi) q[0]

QuICT.core.gate.RXY module-attribute

RXY = BasicGate(*GATEINFO_MAP[rxy], is_original_gate=True)

QuICT.core.gate.XY module-attribute

XY = BasicGate(*GATEINFO_MAP[xy], is_original_gate=True)

QuICT.core.gate.XY2P module-attribute

XY2P = BasicGate(*GATEINFO_MAP[xy2p], is_original_gate=True)

QuICT.core.gate.XY2M module-attribute

XY2M = BasicGate(*GATEINFO_MAP[xy2m], is_original_gate=True)

QuICT.core.gate.CZ module-attribute

CZ = BasicGate(*GATEINFO_MAP[cz], is_original_gate=True)

Controlled Z Gate.

[Matrix Representation]

\[ CZ_{q0,q1} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & -1 \\ \end{bmatrix} \]

[How to apply]

CZ | circuit([0, 1])
CZ & [0, 1] | circuit

[Graph Representation]

    q0:  ────■────
             |
           ┌────┐
    q1:  ──┤ cz ├──
           └────┘

[QASM Representation]

cz q[0], q[1]

QuICT.core.gate.CX module-attribute

CX = BasicGate(*GATEINFO_MAP[cx], is_original_gate=True)

Controlled X Gate.

[Matrix Representation]

\[ CX_{q0,q1} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \\ \end{bmatrix} \]

[How to apply]

CX | circuit([0, 1])
CX & [0, 1] | circuit

[Graph Representation]

    q0:  ────■────
             |
           ┌────┐
    q1:  ──┤ cx ├──
           └────┘

[QASM Representation]

cx q[0], q[1]

QuICT.core.gate.CY module-attribute

CY = BasicGate(*GATEINFO_MAP[cy], is_original_gate=True)

Controlled Y Gate.

[Matrix Representation]

\[ CY_{q0,q1} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & -i \\ 0 & 0 & i & 0 \\ \end{bmatrix} \]

[How to apply]

CY | circuit([0, 1])
CY & [0, 1] | circuit

[Graph Representation]

    q0:  ────■────
             |
           ┌────┐
    q1:  ──┤ cy ├──
           └────┘

[QASM Representation]

cy q[0], q[1]

QuICT.core.gate.CH module-attribute

CH = BasicGate(*GATEINFO_MAP[ch], is_original_gate=True)

Controlled H Gate.

[Matrix Representation]

\[ CH_{q0,q1} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & \frac{1}{\sqrt{2}} & \frac{1}{\sqrt{2}} \\ 0 & 0 & \frac{1}{\sqrt{2}} & \frac{-1}{\sqrt{2}} \\ \end{bmatrix} \]

[How to apply]

CH | circuit([0, 1])
CH & [0, 1] | circuit

[Graph Representation]

    q0:  ────■────
             |
           ┌────┐
    q1:  ──┤ ch ├──
           └────┘

[QASM Representation]

ch q[0], q[1]

QuICT.core.gate.CRy module-attribute

CRy = BasicGate(*GATEINFO_MAP[cry], is_original_gate=True)

Controlled Ry Gate.

[Matrix Representation]

\[ CRy_{q0,q1}(\lambda) = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & \cos(\frac{\lambda}{2}) & -\sin(\frac{\lambda}{2}) \\ 0 & 0 & \sin(\frac{\lambda}{2}) & \cos(\frac{\lambda}{2}) \\ \end{bmatrix} \]

[How to apply]

CRy(pi) | circuit([0, 1])
CRy(pi) & [0, 1] | circuit

[Graph Representation]

    q0:  ─────■─────
              |
           ┌─────┐
    q1:  ──┤ cry ├──
           └─────┘

[QASM Representation]

cry(pi) q[0], q[1]

QuICT.core.gate.CRz module-attribute

CRz = BasicGate(*GATEINFO_MAP[crz], is_original_gate=True)

Controlled Rz Gate.

[Matrix Representation]

\[ CRz_{q0,q1}(\lambda) = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & e^{\frac{-i\lambda}{2}} & 0 \\ 0 & 0 & 0 & e^{\frac{i\lambda}{2}} \\ \end{bmatrix} \]

[How to apply]

CRz(pi) | circuit([0, 1])
CRz(pi) & [0, 1] | circuit

[Graph Representation]

    q0:  ─────■─────
              |
           ┌─────┐
    q1:  ──┤ crz ├──
           └─────┘

[QASM Representation]

crz(pi) q[0], q[1]

QuICT.core.gate.CU1 module-attribute

CU1 = BasicGate(*GATEINFO_MAP[cu1], is_original_gate=True)

Controlled U1 Gate.

[Matrix Representation]

\[ CU1_{q0,q1}(\lambda) = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & e^{i\lambda} \\ \end{bmatrix} \]

[How to apply]

CU1(pi) | circuit([0, 1])
CU1(pi) & [0, 1] | circuit

[Graph Representation]

    q0:  ─────■─────
              |
           ┌─────┐
    q1:  ──┤ cu1 ├──
           └─────┘

[QASM Representation]

cu1(pi) q[0], q[1]

QuICT.core.gate.CU3 module-attribute

CU3 = BasicGate(*GATEINFO_MAP[cu3], is_original_gate=True)

Controlled U3 Gate.

[Matrix Representation]

\[ CU3_{q0,q1}(\theta, \sigma, \lambda) = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & \cos(\frac{\theta}{2}) & -\sin(\frac{\theta}{2}) e^{i\lambda} \\ 0 & 0 & \sin(\frac{\theta}{2}) e^{i\sigma} & \cos(\frac{\theta}{2}) e^{i(\lambda + \sigma)} \\ \end{bmatrix} \]

[How to apply]

CU3(pi, 0, 1) | circuit([0, 1])
CU3(pi, 0, 1) & [0, 1] | circuit

[Graph Representation]

    q0:  ─────■─────
              |
           ┌─────┐
    q1:  ──┤ cu3 ├──
           └─────┘

[QASM Representation]

cu3(pi, 0, 1) q[0], q[1]

QuICT.core.gate.FSim module-attribute

FSim = BasicGate(*GATEINFO_MAP[fsim], is_original_gate=True)

Fermions Simulation Quantum Gate.

[Matrix Representation]

\[ FSim_{q0,q1}(\theta, \lambda) = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & \cos(\theta) & -i\sin(\theta) & 0 \\ 0 & -i\sin(\theta) & \cos(\theta) & 0 \\ 0 & 0 & 0 & e^{-i\lambda} \\ \end{bmatrix} \]

[How to apply]

FSim(pi, 0) | circuit([0, 1])
FSim(pi, 0) & [0, 1] | circuit

[Graph Representation]

           ┌──────────────┐
    q0:  ──┤0             ├──
           |  FSim(pi, 0) |
    q1:  ──┤1             ├──
           └──────────────┘

[QASM Representation]

fsim(pi, 0) q[0], q[1]

QuICT.core.gate.ECR module-attribute

ECR = BasicGate(*GATEINFO_MAP[ecr], is_original_gate=True)

ECR Quantum Gate.

[Matrix Representation]

\[ ECR_{q0,q1} = \frac{1}{\sqrt{2}} \begin{bmatrix} 0 & 0 & 1 & i \\ 0 & 0 & i & 1 \\ 1 & -i & 0 & 0 \\ -i & 1 & 0 & 0 \\ \end{bmatrix} \]

[How to apply]

ECR | circuit([0, 1])
ECR & [0, 1] | circuit

[Graph Representation]

           ┌──────┐
    q0:  ──┤0     ├──
           |  ECR |
    q1:  ──┤1     ├──
           └──────┘

[QASM Representation]

ecr q[0], q[1]

QuICT.core.gate.Rxx module-attribute

Rxx = BasicGate(*GATEINFO_MAP[rxx], is_original_gate=True)

Double-Qubits X \(\otimes\) X Gate.

[Matrix Representation]

\[ Rxx_{q0,q1}(\lambda) = \begin{bmatrix} \cos(\frac{\lambda}{2}) & 0 & 0 & -i\sin(\frac{\lambda}{2}) \\ 0 & \cos(\frac{\lambda}{2}) & -i\sin(\frac{\lambda}{2}) & 0 \\ 0 & -i\sin(\frac{\lambda}{2}) & \cos(\frac{\lambda}{2}) & 0 \\ -i\sin(\frac{\lambda}{2}) & 0 & 0 & \cos(\frac{\lambda}{2}) \\ \end{bmatrix} \]

[How to apply]

Rxx(pi) | circuit([0, 1])
Rxx(pi) & [0, 1] | circuit

[Graph Representation]

           ┌───────────┐
    q0:  ──┤0          ├──
           |  rxx(pi)  |
    q1:  ──┤1          ├──
           └───────────┘

[QASM Representation]

rxx(pi) q[0], q[1]

QuICT.core.gate.Ryy module-attribute

Ryy = BasicGate(*GATEINFO_MAP[ryy], is_original_gate=True)

Double-Qubits Y \(\otimes\) Y Gate.

[Matrix Representation]

\[ Ryy_{q0,q1}(\lambda) = \begin{bmatrix} \cos(\frac{\lambda}{2}) & 0 & 0 & i\sin(\frac{\lambda}{2}) \\ 0 & \cos(\frac{\lambda}{2}) & -i\sin(\frac{\lambda}{2}) & 0 \\ 0 & -i\sin(\frac{\lambda}{2}) & \cos(\frac{\lambda}{2}) & 0 \\ i\sin(\frac{\lambda}{2}) & 0 & 0 & \cos(\frac{\lambda}{2}) \\ \end{bmatrix} \]

[How to apply]

Ryy(pi) | circuit([0, 1])
Ryy(pi) & [0, 1] | circuit

[Graph Representation]

           ┌───────────┐
    q0:  ──┤0          ├──
           |  ryy(pi)  |
    q1:  ──┤1          ├──
           └───────────┘

[QASM Representation]

ryy(pi) q[0], q[1]

QuICT.core.gate.Rzz module-attribute

Rzz = BasicGate(*GATEINFO_MAP[rzz], is_original_gate=True)

Double-Qubits Z \(\otimes\) Z Gate.

[Matrix Representation]

\[ Rzz_{q0,q1}(\lambda) = \begin{bmatrix} e^{\frac{-i\lambda}{2}} & 0 & 0 & 0 \\ 0 & e^{\frac{i\lambda}{2}} & 0 & 0 \\ 0 & 0 & e^{\frac{i\lambda}{2}} & 0 \\ 0 & 0 & 0 & e^{\frac{-i\lambda}{2}} \\ \end{bmatrix} \]

[How to apply]

Rzz(pi) | circuit([0, 1])
Rzz(pi) & [0, 1] | circuit

[Graph Representation]

           ┌───────────┐
    q0:  ──┤0          ├──
           |  rzz(pi)  |
    q1:  ──┤1          ├──
           └───────────┘

[QASM Representation]

rzz(pi) q[0], q[1]

QuICT.core.gate.Rzx module-attribute

Rzx = BasicGate(*GATEINFO_MAP[rzx], is_original_gate=True)

Double-Qubits Z \(\otimes\) X Gate.

[Matrix Representation]

\[ Rzx_{q0,q1}(\lambda) = \begin{bmatrix} \cos(\frac{\lambda}{2}) & -i\sin(\frac{\lambda}{2}) & 0 & 0 \\ -i\sin(\frac{\lambda}{2}) & \cos(\frac{\lambda}{2}) & 0 & 0 \\ 0 & 0 & \cos(\frac{\lambda}{2}) & i\sin(\frac{\lambda}{2}) \\ 0 & 0 & i\sin(\frac{\lambda}{2}) & \cos(\frac{\lambda}{2}) \\ \end{bmatrix} \]

[How to apply]

Rzx(pi) | circuit([0, 1])
Rzx(pi) & [0, 1] | circuit

[Graph Representation]

           ┌───────────┐
    q0:  ──┤0          ├──
           |  rzx(pi)  |
    q1:  ──┤1          ├──
           └───────────┘

[QASM Representation]

rzx(pi) q[0], q[1]

QuICT.core.gate.Measure module-attribute

Measure = BasicGate(*GATEINFO_MAP[measure], is_original_gate=True)

The Quantum Measurement Gate.

[How to apply]

Measure | circuit(0)
Measure & 0 | circuit

[Graph Representation]

       ┌───┐
     ──┤ M ├──
       └───┘

[QASM Representation]

measure q[0] -> c[0]

QuICT.core.gate.MeasureX module-attribute

MeasureX = BasicGate(*GATEINFO_MAP[measurex], is_original_gate=True)

The Pauli X Measurement Gate.

[How to apply]

MeasureX | circuit(0)
MeasureX & 0 | circuit

[Graph Representation][not support]

       ┌────┐
     ──┤ Mx ├──
       └────┘

[QASM Representation][not support]

measurex q[0] -> c[0]

QuICT.core.gate.MeasureY module-attribute

MeasureY = BasicGate(*GATEINFO_MAP[measurey], is_original_gate=True)

The Quantum Measurement Gate.

[How to apply]

MeasureY | circuit(0)
MeasureY & 0 | circuit

[Graph Representation][not support]

       ┌────┐
     ──┤ My ├──
       └────┘

[QASM Representation][not support]

measurey q[0] -> c[0]

QuICT.core.gate.Reset module-attribute

Reset = BasicGate(*GATEINFO_MAP[reset], is_original_gate=True)

The Quantum Reset Gate.

[How to apply]

Reset | circuit(0)
Reset & 0 | circuit

[Graph Representation]

    ──┤0>──

[QASM Representation]

reset q[0]

QuICT.core.gate.Barrier module-attribute

Barrier = BasicGate(*GATEINFO_MAP[barrier], is_original_gate=True)

The Barrier Gate.

[How to apply]

Barrier | circuit(0)
Barrier & 0 | circuit

[Graph Representation]

        
    ────░────
        

[QASM Representation]

barrier q[0]

QuICT.core.gate.Swap module-attribute

Swap = BasicGate(*GATEINFO_MAP[swap], is_original_gate=True)

Swap Gate.

[Matrix Representation]

\[ Swap_{q0,q1} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ \end{bmatrix} \]

[How to apply]

Swap | circuit([0, 1])
Swap & [0, 1] | circuit

[Graph Representation]

    q0:  ─────X─────
              |
    q1:  ─────X─────

[QASM Representation]

swap q[0], q[1]

QuICT.core.gate.iSwap module-attribute

iSwap = BasicGate(*GATEINFO_MAP[iswap], is_original_gate=True)

iSwap Gate, a double-qubit XX + YY Gate.

[Matrix Representation]

\[ iSwap_{q0,q1} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & i & 0 \\ 0 & i & 0 & 0 \\ 0 & 0 & 0 & 1 \\ \end{bmatrix} \]

[How to apply]

iSwap | circuit([0, 1])
iSwap & [0, 1] | circuit

[Graph Representation]

           ┌───────────┐
    q0:  ──┤0          ├──
           |   iswap   |
    q1:  ──┤1          ├──
           └───────────┘

[QASM Representation]

iswap q[0], q[1]

QuICT.core.gate.iSwap_dagger module-attribute

iSwap_dagger = BasicGate(*GATEINFO_MAP[iswapdg], is_original_gate=True)

iSwap Dagger Gate.

[Matrix Representation]

\[ iSwapdg_{q0,q1} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & -i & 0 \\ 0 & -i & 0 & 0 \\ 0 & 0 & 0 & 1 \\ \end{bmatrix} \]

[How to apply]

iSwap_dagger | circuit([0, 1])
iSwap_dagger & [0, 1] | circuit

[Graph Representation]

           ┌───────────┐
    q0:  ──┤0          ├──
           |  iswapdg  |
    q1:  ──┤1          ├──
           └───────────┘

[QASM Representation]

iswap_dagger q[0], q[1]

QuICT.core.gate.sqiSwap module-attribute

sqiSwap = BasicGate(*GATEINFO_MAP[sqiswap], is_original_gate=True)

Swap Gate.

[Matrix Representation]

\[ sqiSwap_{q0,q1} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & \frac{1}{\sqrt{2}} & \frac{i}{\sqrt{2}} & 0 \\ 0 & \frac{i}{\sqrt{2}} & \frac{1}{\sqrt{2}} & 0 \\ 0 & 0 & 0 & 1 \\ \end{bmatrix} \]

[How to apply]

sqiSwap | circuit([0, 1])
sqiSwap & [0, 1] | circuit

[Graph Representation]

           ┌───────────┐
    q0:  ──┤0          ├──
           |  sqiswap  |
    q1:  ──┤1          ├──
           └───────────┘

[QASM Representation]

sqiswap q[0], q[1]

QuICT.core.gate.CCX module-attribute

CCX = BasicGate(*GATEINFO_MAP[ccx], is_original_gate=True)

Double-Qubit Controlled X Gate, CCX Gate.

[Matrix Representation]

\[ CCX_{q0,q1,q2} = \begin{bmatrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\ \end{bmatrix} \]

[How to apply]

CCX | circuit([0, 1, 2])
CCX & [0, 1, 2] | circuit

[Graph Representation]

    q0:  ─────■─────
              |
              |
    q1:  ─────■─────
              |
           ┌─────┐
    q2:  ──┤ ccx ├──
           └─────┘

[QASM Representation]

ccx q[0], q[1], q[2]

QuICT.core.gate.CCZ module-attribute

CCZ = BasicGate(*GATEINFO_MAP[ccz], is_original_gate=True)

Double-Qubit Controlled Z Gate, CCZ Gate.

[Matrix Representation]

\[ CCZ_{q0,q1,q2} = \begin{bmatrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & -1 \\ \end{bmatrix} \]

[How to apply]

CCZ | circuit([0, 1, 2])
CCZ & [0, 1, 2] | circuit

[Graph Representation]

    q0:  ─────■─────
              |
              |
    q1:  ─────■─────
              |
           ┌─────┐
    q2:  ──┤ ccz ├──
           └─────┘

[QASM Representation]

ccz q[0], q[1], q[2]

QuICT.core.gate.CCRz module-attribute

CCRz = BasicGate(*GATEINFO_MAP[ccrz], is_original_gate=True)

Double-Qubit Controlled Rz Gate, CCRz Gate.

[Matrix Representation]

\[ CCRz_{q0,q1,q2}(\lambda) = \begin{bmatrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & e^{\frac{-i\lambda}{2}} & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & e^{\frac{i\lambda}{2}} \\ \end{bmatrix} \]

[How to apply]

CCRz(pi) | circuit([0, 1, 2])
CCRz(pi) & [0, 1, 2] | circuit

[Graph Representation]

    q0:  ─────■──────
              |
              |
    q1:  ─────■──────
              |
           ┌──────┐
    q2:  ──┤ ccrz ├──
           └──────┘

[QASM Representation]

ccrz(pi) q[0], q[1], q[2]

QuICT.core.gate.CSwap module-attribute

CSwap = BasicGate(*GATEINFO_MAP[cswap], is_original_gate=True)

Controlled Swap Gate.

[Matrix Representation]

\[ CSwap_{q0,q1,q2} = \begin{bmatrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\ \end{bmatrix} \]

[How to apply]

CSwap | circuit([0, 1, 2])
CSwap & [0, 1, 2] | circuit

[Graph Representation]

    q0:  ──────■──────
               |
               |
    q1:  ──────X──────
               |
               |
    q2:  ──────X──────

[QASM Representation]

cswap q[0], q[1], q[2]

QuICT.core.gate.RCCX module-attribute

RCCX = BasicGate(*GATEINFO_MAP[rccx], is_original_gate=True)

Simplified Double-Qubit Controlled X Gate, or Margolus gate

[Matrix Representation]

\[ RCCX_{q0,q1,q2} = \begin{bmatrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & -1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\ \end{bmatrix} \]

[How to apply]

RCCX | circuit([0, 1, 2])
RCCX & [0, 1, 2] | circuit

[Graph Representation]

    q0:  ─────■──────
              |
              |
    q1:  ─────■──────
              |
           ┌──────┐
    q2:  ──┤ rccx ├──
           └──────┘

[QASM Representation]

rccx q[0], q[1], q[2]