Operations#

Quantum operations and base operations for creating new operation classes.

Base Module#

Set of base operation classes subclassed by all quantum operations.

Contains all base classes for general quantum operations, including parametric operations, controlled operations and measurements. Also provides the utility function create_operation() for transforming circuits into operations.

class Barrier(qubits: Qubit | Sequence[Qubit] | None = None)[source]#

Bases: Operation

Class representing a barrier operation.

Parameters:

qubits – Qubits on which the barrier operation should be applied. Only required when applying a barrier operation within a circuit context.

class ControlledOperation(control: Qubit | Sequence[Qubit] | None = None, target: Qubit | Sequence[Qubit] | None = None, **kwargs)[source]#

Bases: Operation

Generic controlled operation.

Parameters:
  • control – Qubit(s) on which the target operation is controlled.

  • target – Qubit(s) on which the target operation is applied.

Keyword Arguments:

qubits – All qubits on which the operation is applied. If qubits is passed, it takes precedence over control and target, and replaces those two attributes using the operations _num_control and _num_target class attributes.

property control: tuple[Qubit] | None[source]#

Control qubit(s).

matrix[source]#

Decorator class for creating a property for a class/instance method.

Note that the mixedproperty decorator differs from the regular property decorator by supporting access to both the class (cls) and the instance (self). The latter is only available when calling the method on an instance of the class. The signature parameters are positional and assume that the first parameter is the class and the second parameter (optional) is the instance.

This property can optionally also accept parameters (either positional or keyword) when initialized. Allowed parameters are listed under ‘Args’ below.

Parameters:

self_required – Whether self is required for the property to be able to return the requested property, i.e., the function will only work when called on an instance and not on the class.

Example

class MixedpropertyExample:
    _a = "a_class"
    _b = "b_class"

    def __init__(self):
        self._b = "b_instance"
        self._c = "c_instance"

    # can be called on both instance and class and will
    # return the same result regardless
    @mixedproperty
    def a(cls):
        return cls._a

    # can be called on both instance and class and will
    # return different results (e.g., different defaults)
    @mixedproperty
    def b(cls, self):
        if self:
            return self._b
        return cls._b

    # can be called on both instance and class and will
    # return 'None' if called on class
    @mixedproperty(self_required=True)
    def c(cls, self):
        return self._c
num_control = None[source]#
num_qubits[source]#

Decorator class for creating a property for a class/instance method.

Note that the mixedproperty decorator differs from the regular property decorator by supporting access to both the class (cls) and the instance (self). The latter is only available when calling the method on an instance of the class. The signature parameters are positional and assume that the first parameter is the class and the second parameter (optional) is the instance.

This property can optionally also accept parameters (either positional or keyword) when initialized. Allowed parameters are listed under ‘Args’ below.

Parameters:

self_required – Whether self is required for the property to be able to return the requested property, i.e., the function will only work when called on an instance and not on the class.

Example

class MixedpropertyExample:
    _a = "a_class"
    _b = "b_class"

    def __init__(self):
        self._b = "b_instance"
        self._c = "c_instance"

    # can be called on both instance and class and will
    # return the same result regardless
    @mixedproperty
    def a(cls):
        return cls._a

    # can be called on both instance and class and will
    # return different results (e.g., different defaults)
    @mixedproperty
    def b(cls, self):
        if self:
            return self._b
        return cls._b

    # can be called on both instance and class and will
    # return 'None' if called on class
    @mixedproperty(self_required=True)
    def c(cls, self):
        return self._c
num_target = None[source]#
property target: tuple[Qubit] | None[source]#

Target qubit(s).

target_operation[source]#

Decorator class for creating a property for a class/instance method.

Note that the mixedproperty decorator differs from the regular property decorator by supporting access to both the class (cls) and the instance (self). The latter is only available when calling the method on an instance of the class. The signature parameters are positional and assume that the first parameter is the class and the second parameter (optional) is the instance.

This property can optionally also accept parameters (either positional or keyword) when initialized. Allowed parameters are listed under ‘Args’ below.

Parameters:

self_required – Whether self is required for the property to be able to return the requested property, i.e., the function will only work when called on an instance and not on the class.

Example

class MixedpropertyExample:
    _a = "a_class"
    _b = "b_class"

    def __init__(self):
        self._b = "b_instance"
        self._c = "c_instance"

    # can be called on both instance and class and will
    # return the same result regardless
    @mixedproperty
    def a(cls):
        return cls._a

    # can be called on both instance and class and will
    # return different results (e.g., different defaults)
    @mixedproperty
    def b(cls, self):
        if self:
            return self._b
        return cls._b

    # can be called on both instance and class and will
    # return 'None' if called on class
    @mixedproperty(self_required=True)
    def c(cls, self):
        return self._c
class Measurement(qubits: Qubit | Sequence[Qubit] | None = None)[source]#

Bases: Operation

Class representing a measurement.

Parameters:

qubits – The qubits which should be measured. Only required when applying an measurement within a circuit context.

property bits: Sequence[Bit] | None[source]#

The bits in which the measurement samples are stored.

expval(qubits: int | None = None, num_samples: int = 1000) list[float][source]#

Calculate the expectation value of a measurement.

Parameters:
  • qubit – The qubit to sample. Not required if measurement is on a single qubit.

  • num_samples – The number of samples to use when calculating the expectation value.

Returns:

The expectation values for each qubit measurement.

Return type:

list[float]

sample(qubits: Sequence[int] | None = None, num_samples: int = 1, as_bitstring: bool = False) list[int | str][source]#

Sample the measured state.

Parameters:
  • qubits – The qubits to sample. If not given, all measured qubits are sampled.

  • num_samples – The number of samples to to return.

  • as_bitstring – Whether to return the samples as bitstrings or as lists of integers (default).

Returns:

The measurement samples for each qubit.

Return type:

list[Union[int, str]]

property state: NDArray | None[source]#

The circuit state when measured.

class Operation(qubits: Qubit | Sequence[Qubit] | None = None)[source]#

Bases: object

Class representing a classical or quantum operation.

Parameters:

qubits – Qubits on which the operation should be applied. Only required when applying an operation within a circuit context.

conditional(bits: Bit | Sequence[Bit]) Operation[source]#

Sets the _cond attribute, conditioning the operation on one or more bits.

decomposition[source]#

Decorator class for creating a property for a class/instance method.

Note that the mixedproperty decorator differs from the regular property decorator by supporting access to both the class (cls) and the instance (self). The latter is only available when calling the method on an instance of the class. The signature parameters are positional and assume that the first parameter is the class and the second parameter (optional) is the instance.

This property can optionally also accept parameters (either positional or keyword) when initialized. Allowed parameters are listed under ‘Args’ below.

Parameters:

self_required – Whether self is required for the property to be able to return the requested property, i.e., the function will only work when called on an instance and not on the class.

Example

class MixedpropertyExample:
    _a = "a_class"
    _b = "b_class"

    def __init__(self):
        self._b = "b_instance"
        self._c = "c_instance"

    # can be called on both instance and class and will
    # return the same result regardless
    @mixedproperty
    def a(cls):
        return cls._a

    # can be called on both instance and class and will
    # return different results (e.g., different defaults)
    @mixedproperty
    def b(cls, self):
        if self:
            return self._b
        return cls._b

    # can be called on both instance and class and will
    # return 'None' if called on class
    @mixedproperty(self_required=True)
    def c(cls, self):
        return self._c
property is_blocked: bool[source]#

Whether the operation is blocked and should not be executed.

Note that this affects the operation only at runtime (e.g., in the simulator) and does not block the operation from being appended to the circuit. This happend when at least one conditional bit is False.

matrix = None[source]#
name = 'Operation'[source]#
num_qubits[source]#

Decorator class for creating a property for a class/instance method.

Note that the mixedproperty decorator differs from the regular property decorator by supporting access to both the class (cls) and the instance (self). The latter is only available when calling the method on an instance of the class. The signature parameters are positional and assume that the first parameter is the class and the second parameter (optional) is the instance.

This property can optionally also accept parameters (either positional or keyword) when initialized. Allowed parameters are listed under ‘Args’ below.

Parameters:

self_required – Whether self is required for the property to be able to return the requested property, i.e., the function will only work when called on an instance and not on the class.

Example

class MixedpropertyExample:
    _a = "a_class"
    _b = "b_class"

    def __init__(self):
        self._b = "b_instance"
        self._c = "c_instance"

    # can be called on both instance and class and will
    # return the same result regardless
    @mixedproperty
    def a(cls):
        return cls._a

    # can be called on both instance and class and will
    # return different results (e.g., different defaults)
    @mixedproperty
    def b(cls, self):
        if self:
            return self._b
        return cls._b

    # can be called on both instance and class and will
    # return 'None' if called on class
    @mixedproperty(self_required=True)
    def c(cls, self):
        return self._c
property qubits: tuple[Qubit, ...] | None[source]#

Qubits that the operation is applied to.

to_qasm(*args, **kwargs)[source]#

Converts the operation into an OpenQASM 2.0 string.

Must be implemented by subclass to support OpenQASM 2.0 transpilation.

Raises:

NotImplementedError – If called on a class which hasn’t implemented this method.

class ParametricOperation(parameters: Variable | complex | Sequence[Variable | complex], qubits: Qubit | Sequence[Qubit] | None = None)[source]#

Bases: Operation

Class for creating parametric operations.

Parameters:
  • qubits – Qubits on which the operation should be applied. Only required when applying an operation within a circuit context.

  • parameters – Parameters for the operation. Required when constructing the matrix representation of the operation.

eval(parameters: Sequence[complex] | None = None, inplace: bool = False) ParametricOperation[source]#

Evaluate operation with explicit parameters.

Parameters:
  • parameters – Parameters to replace operation variables with. Overrides potential variable values. If None then variable values are used (if existent).

  • inplace – Whether to evaluate the parameters on self or on a copy of self (returned).

Returns:

Either self or a copy of self.

Return type:

ParametricOperation

Raises:

ValueError – If no parameters are passed and if variable has no set value.

num_parameters[source]#

Decorator class for creating a property for a class/instance method.

Note that the mixedproperty decorator differs from the regular property decorator by supporting access to both the class (cls) and the instance (self). The latter is only available when calling the method on an instance of the class. The signature parameters are positional and assume that the first parameter is the class and the second parameter (optional) is the instance.

This property can optionally also accept parameters (either positional or keyword) when initialized. Allowed parameters are listed under ‘Args’ below.

Parameters:

self_required – Whether self is required for the property to be able to return the requested property, i.e., the function will only work when called on an instance and not on the class.

Example

class MixedpropertyExample:
    _a = "a_class"
    _b = "b_class"

    def __init__(self):
        self._b = "b_instance"
        self._c = "c_instance"

    # can be called on both instance and class and will
    # return the same result regardless
    @mixedproperty
    def a(cls):
        return cls._a

    # can be called on both instance and class and will
    # return different results (e.g., different defaults)
    @mixedproperty
    def b(cls, self):
        if self:
            return self._b
        return cls._b

    # can be called on both instance and class and will
    # return 'None' if called on class
    @mixedproperty(self_required=True)
    def c(cls, self):
        return self._c
property parameters[source]#

Parameters of the operation.

create_operation(circuit: ParametricCircuit, name: str | None = None) Type[CustomParametricOperation][source]#
create_operation(circuit: Circuit, name: str | None = None) Type[CustomOperation]

Create an operation from a circuit object.

Takes the circuit operations and creates a new custom operation class inheriting either directly or indirectly from Operation. The custrom operation will automatically implement the matrix property which constructs and stores the matrix represenation.

Parameters:
  • circuit – Circuit object out of which to create an operation.

  • name – Name for the new operation. Usually the class name of the operation. Defaults to "CustomOperation" if no other name is given.

Returns:

Class inheriting from the Operation class.

Return type:

type

Operations Module#

Quantum operations that can be applied in a circuit.

Contains all supported quantum operations along with aliases for operations that may be known by different names; e.g., Fredkin is an alias for CSWAP, and Toffoli and CCNOT are aliases for CCX.

CCNOT[source]#

alias of CCX

class CCX(qubits: Qubit | Sequence[Qubit] | None = None)[source]#

Bases: Operation

CCX (Toffoli) operation.

Parameters:

qubits – Qubits on which the operation should be applied. Only required when applying an operation within a circuit context.

matrix = array([[1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j],        [0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j],        [0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j],        [0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j],        [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j],        [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j],        [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j],        [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j]])[source]#
to_qasm(mapping: Mapping | None = None) str[source]#

Converts the CCX operation into an OpenQASM string.

Parameters:

mapping – Optional mapping between qubits and their indices in the circuit.

Returns:

OpenQASM string representation of the CCX operation.

Return type:

str

class CHadamard(control: Qubit | Sequence[Qubit] | None = None, target: Qubit | Sequence[Qubit] | None = None, **kwargs)[source]#

Bases: ControlledOperation

Controlled-Hadamard operation.

Parameters:

qubits – Qubits on which the operation should be applied. Only required when applying an operation within a circuit context.

to_qasm(mapping: Mapping | None = None) str[source]#

Converts the Controlled-Hadamard operation into an OpenQASM string.

Parameters:

mapping – Optional mapping between qubits and their indices in the circuit.

Returns:

OpenQASM string representation of the Controlled-Hadamard operation.

Return type:

str

CNOT[source]#

Controlled-NOT operation (alias for the CX operation)

class CRX(parameters: Variable | complex | Sequence[Variable | complex], control: Qubit | Sequence[Qubit] | None = None, target: Qubit | Sequence[Qubit] | None = None, **kwargs)[source]#

Bases: ParametricControlledOperation

Controlled-RX operation.

Parameters:

qubits – Qubits on which the operation should be applied. Only required when applying an operation within a circuit context.

to_qasm(mapping: Mapping | None = None) str[source]#

Converts the Controlled-RX operation into an OpenQASM string.

Parameters:

mapping – Optional mapping between qubits and their indices in the circuit.

Returns:

OpenQASM string representation of the Controlled-RX operation.

Return type:

str

class CRY(parameters: Variable | complex | Sequence[Variable | complex], control: Qubit | Sequence[Qubit] | None = None, target: Qubit | Sequence[Qubit] | None = None, **kwargs)[source]#

Bases: ParametricControlledOperation

Controlled-RY operation.

Parameters:

qubits – Qubits on which the operation should be applied. Only required when applying an operation within a circuit context.

to_qasm(mapping: Mapping | None = None) str[source]#

Converts the Controlled-RY operation into an OpenQASM string.

Parameters:

mapping – Optional mapping between qubits and their indices in the circuit.

Returns:

OpenQASM string representation of the Controlled-RY operation.

Return type:

str

class CRZ(parameters: Variable | complex | Sequence[Variable | complex], control: Qubit | Sequence[Qubit] | None = None, target: Qubit | Sequence[Qubit] | None = None, **kwargs)[source]#

Bases: ParametricControlledOperation

Controlled-RZ operation.

Parameters:

qubits – Qubits on which the operation should be applied. Only required when applying an operation within a circuit context.

to_qasm(mapping: Mapping | None = None) str[source]#

Converts the Controlled-RZ operation into an OpenQASM string.

Parameters:

mapping – Optional mapping between qubits and their indices in the circuit.

Returns:

OpenQASM string representation of the Controlled-RZ operation.

Return type:

str

class CRotation(parameters: Variable | complex | Sequence[Variable | complex], control: Qubit | Sequence[Qubit] | None = None, target: Qubit | Sequence[Qubit] | None = None, **kwargs)[source]#

Bases: ParametricControlledOperation

Controlled-Rotation operation.

Parameters:

qubits – Qubits on which the operation should be applied. Only required when applying an operation within a circuit context.

to_qasm(mapping: Mapping | None = None) str[source]#

Converts the Controlled-Rotation operation into an OpenQASM string.

Parameters:

mapping – Optional mapping between qubits and their indices in the circuit.

Returns:

OpenQASM string representation of the Controlled-Rotation operation.

Return type:

str

class CSWAP(qubits: Qubit | Sequence[Qubit] | None = None)[source]#

Bases: Operation

CSWAP (controlled SWAP) operation.

Parameters:

qubits – Qubits on which the operation should be applied. Only required when applying an operation within a circuit context.

matrix = array([[1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j],        [0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j],        [0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j],        [0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j],        [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j],        [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j],        [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j],        [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j]])[source]#
to_qasm(mapping: Mapping | None = None) str[source]#

Converts the CSWAP operation into an OpenQASM string.

Note, the CSWAP operation must be defined by decomposing into existing gates, e.g., using CNOT and Toffoli gates as follows:

gate cswap c, a, b { cx b, a; ccx c, a, b; cx b, a; }
Parameters:

mapping – Optional mapping between qubits and their indices in the circuit.

Returns:

OpenQASM string representation of the SWAP operation.

Return type:

str

class CX(control: Qubit | Sequence[Qubit] | None = None, target: Qubit | Sequence[Qubit] | None = None, **kwargs)[source]#

Bases: ControlledOperation

Controlled-X (CNOT) operation.

Parameters:
  • control – Qubit on which the target operation X is controlled.

  • target – Qubit on which the target operation X is applied.

to_qasm(mapping: Mapping | None = None) str[source]#

Converts the CX operation into an OpenQASM string.

Parameters:

mapping – Optional mapping between qubits and their indices in the circuit.

Returns:

OpenQASM string representation of the Controlled X operation.

Return type:

str

class CY(control: Qubit | Sequence[Qubit] | None = None, target: Qubit | Sequence[Qubit] | None = None, **kwargs)[source]#

Bases: ControlledOperation

Controlled-Y operation.

Parameters:

qubits – Qubits on which the operation should be applied. Only required when applying an operation within a circuit context.

to_qasm(mapping: Mapping | None = None) str[source]#

Converts the Controlled-Y operation into an OpenQASM string.

Parameters:

mapping – Optional mapping between qubits and their indices in the circuit.

Returns:

OpenQASM string representation of the Controlled-Y operation.

Return type:

str

class CZ(control: Qubit | Sequence[Qubit] | None = None, target: Qubit | Sequence[Qubit] | None = None, **kwargs)[source]#

Bases: ControlledOperation

Controlled-Z operation.

Parameters:

qubits – Qubits on which the operation should be applied. Only required when applying an operation within a circuit context.

to_qasm(mapping: Mapping | None = None) str[source]#

Converts the Controlled-Z operation into an OpenQASM string.

Parameters:

mapping – Optional mapping between qubits and their indices in the circuit.

Returns:

OpenQASM string representation of the Controlled-Z operation.

Return type:

str

Fredkin[source]#

Fredkin operation (alias for the CSWAP operation)

class Hadamard(qubits: Qubit | Sequence[Qubit] | None = None)[source]#

Bases: Operation

Hadamard operation.

Parameters:

qubits – Qubits on which the operation should be applied. Only required when applying an operation within a circuit context.

matrix = array([[ 0.70710678+0.j,  0.70710678+0.j],        [ 0.70710678+0.j, -0.70710678+0.j]])[source]#
to_qasm(mapping: Mapping | None = None) str[source]#

Converts the Hadamard operation into an OpenQASM string.

Parameters:

mapping – Optional mapping between qubits and their indices in the circuit.

Returns:

OpenQASM string representation of the Hadamard operation.

Return type:

str

class Identity(qubits: Qubit | Sequence[Qubit] | None = None)[source]#

Bases: Operation

Identity operator.

Parameters:

qubits – Qubits on which the operation should be applied. Only required when applying an operation within a circuit context.

matrix = array([[1.+0.j, 0.+0.j],        [0.+0.j, 1.+0.j]])[source]#
to_qasm(mapping: Mapping | None = None) str[source]#

Converts the identity operator into an OpenQASM string.

Parameters:

mapping – Optional mapping between qubits and their indices in the circuit.

Returns:

OpenQASM string representation of the identity operator.

Return type:

str

P[source]#

alias of S

Phase[source]#

Phase operation (aliases for the S operation)

class RX(parameters: Variable | complex | Sequence[Variable | complex], qubits: Qubit | Sequence[Qubit] | None = None)[source]#

Bases: ParametricOperation

Rotation-X operation.

Parameters:
  • qubits – Qubits on which the operation should be applied. Only required when applying an operation within a circuit context.

  • parameters – Parameters for the operation. Required when constructing the matrix representation of the operation.

matrix = None[source]#
to_qasm(mapping: Mapping | None = None) str[source]#

Converts the Rotation-X operation into an OpenQASM string.

Parameters:

mapping – Optional mapping between qubits and their indices in the circuit.

Returns:

OpenQASM string representation of the Rotation-X operation.

Return type:

str

class RY(parameters: Variable | complex | Sequence[Variable | complex], qubits: Qubit | Sequence[Qubit] | None = None)[source]#

Bases: ParametricOperation

Rotation-Y operation.

Parameters:
  • qubits – Qubits on which the operation should be applied. Only required when applying an operation within a circuit context.

  • parameters – Parameters for the operation. Required when constructing the matrix representation of the operation.

matrix = None[source]#
to_qasm(mapping: Mapping | None = None) str[source]#

Converts the Rotation-Y operation into an OpenQASM string.

Parameters:

mapping – Optional mapping between qubits and their indices in the circuit.

Returns:

OpenQASM string representation of the Rotation-Y operation.

Return type:

str

class RZ(parameters: Variable | complex | Sequence[Variable | complex], qubits: Qubit | Sequence[Qubit] | None = None)[source]#

Bases: ParametricOperation

Rotation-Z operation.

Parameters:
  • qubits – Qubits on which the operation should be applied. Only required when applying an operation within a circuit context.

  • theta – Parameter for the operation. Required when constructing the matrix representation of the operation.

matrix = None[source]#
to_qasm(mapping: Mapping | None = None) str[source]#

Converts the Rotation-Z operation into an OpenQASM string.

Parameters:

mapping – Optional mapping between qubits and their indices in the circuit.

Returns:

OpenQASM string representation of the Rotation-Z operation.

Return type:

str

class Rotation(parameters: Variable | complex | Sequence[Variable | complex], qubits: Qubit | Sequence[Qubit] | None = None)[source]#

Bases: ParametricOperation

Rotation operation.

Parameters:
  • qubits – Qubits on which the operation should be applied. Only required when applying an operation within a circuit context.

  • parameters – Parameters for the operation. Required when constructing the matrix representation of the operation.

matrix = None[source]#
to_qasm(mapping: Mapping | None = None) str[source]#

Converts the Rotation operation into an OpenQASM string.

Note, the Rotation operation must be defined by decomposing into existing gates, e.g., using RY and RZ gates as follows:

gate rot(beta, gamma, delta) { rz(beta) q[0]; ry(gamma) q[0]; rz(delta) q[0]; }
Parameters:

mapping – Optional mapping between qubits and their indices in the circuit.

Returns:

OpenQASM string representation of the Rotation operation.

Return type:

str

class S(qubits: Qubit | Sequence[Qubit] | None = None)[source]#

Bases: Operation

S (Phase) operation.

Parameters:

qubits – Qubits on which the operation should be applied. Only required when applying an operation within a circuit context.

matrix = array([[1.+0.j, 0.+0.j],        [0.+0.j, 0.+1.j]])[source]#
to_qasm(mapping: Mapping | None = None) str[source]#

Converts the S operation into an OpenQASM string.

Parameters:

mapping – Optional mapping between qubits and their indices in the circuit.

Returns:

OpenQASM string representation of the S operation.

Return type:

str

class SWAP(qubits: Qubit | Sequence[Qubit] | None = None)[source]#

Bases: Operation

SWAP operation.

Parameters:

qubits – Qubits on which the operation should be applied. Only required when applying an operation within a circuit context.

matrix = array([[1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j],        [0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j],        [0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j],        [0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j]])[source]#
to_qasm(mapping: Mapping | None = None) str[source]#

Converts the SWAP operation into an OpenQASM string.

Note, the SWAP operation must be defined by decomposing into existing gates, e.g., using CNOT gates as follows:

gate swap a, b { cx b, a; cx a, b; cx b, a; }
Parameters:

mapping – Optional mapping between qubits and their indices in the circuit.

Returns:

OpenQASM string representation of the SWAP operation.

Return type:

str

class T(qubits: Qubit | Sequence[Qubit] | None = None)[source]#

Bases: Operation

T operation.

Parameters:

qubits – Qubits on which the operation should be applied. Only required when applying an operation within a circuit context.

matrix = array([[1.        +0.j        , 0.        +0.j        ],        [0.        +0.j        , 0.70710678+0.70710678j]])[source]#
to_qasm(mapping: Mapping | None = None) str[source]#

Converts the T operation into an OpenQASM string.

Parameters:

mapping – Optional mapping between qubits and their indices in the circuit.

Returns:

OpenQASM string representation of the T operation.

Return type:

str

Toffoli[source]#

Toffoli operation (alias for the CCNOT operation)

class X(qubits: Qubit | Sequence[Qubit] | None = None)[source]#

Bases: Operation

Pauli X operator.

Parameters:

qubits – Qubits on which the operation should be applied. Only required when applying an operation within a circuit context.

matrix = array([[0.+0.j, 1.+0.j],        [1.+0.j, 0.+0.j]])[source]#
to_qasm(mapping: Mapping | None = None) str[source]#

Converts the Pauli X operator into an OpenQASM string.

Parameters:

mapping – Optional mapping between qubits and their indices in the circuit.

Returns:

OpenQASM string representation of the Pauli X operator.

Return type:

str

class Y(qubits: Qubit | Sequence[Qubit] | None = None)[source]#

Bases: Operation

Pauli Y operator.

Parameters:

qubits – Qubits on which the operation should be applied. Only required when applying an operation within a circuit context.

matrix = array([[ 0.+0.j, -0.-1.j],        [ 0.+1.j,  0.+0.j]])[source]#
to_qasm(mapping: Mapping | None = None) str[source]#

Converts the Pauli Y operator into an OpenQASM string.

Parameters:

mapping – Optional mapping between qubits and their indices in the circuit.

Returns:

OpenQASM string representation of the Pauli Y operator.

Return type:

str

class Z(qubits: Qubit | Sequence[Qubit] | None = None)[source]#

Bases: Operation

Pauli Z operator.

Parameters:

qubits – Qubits on which the operation should be applied. Only required when applying an operation within a circuit context.

matrix = array([[ 1.+0.j,  0.+0.j],        [ 0.+0.j, -1.+0.j]])[source]#
to_qasm(mapping: Mapping | None = None) str[source]#

Converts the Pauli Z operator into an OpenQASM string.

Parameters:

mapping – Optional mapping between qubits and their indices in the circuit.

Returns:

OpenQASM string representation of the Pauli Z operator.

Return type:

str