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: Optional[Union[dwave.gate.primitives.Qubit, Sequence[dwave.gate.primitives.Qubit]]] = None)[source]

Bases: dwave.gate.operations.base.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: Optional[Union[dwave.gate.primitives.Qubit, Sequence[dwave.gate.primitives.Qubit]]] = None, target: Optional[Union[dwave.gate.primitives.Qubit, Sequence[dwave.gate.primitives.Qubit]]] = None, **kwargs)[source]

Bases: dwave.gate.operations.base.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: Optional[Tuple[dwave.gate.primitives.Qubit]][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: Optional[Tuple[dwave.gate.primitives.Qubit]][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: Optional[Union[dwave.gate.primitives.Qubit, Sequence[dwave.gate.primitives.Qubit]]] = None)[source]

Bases: dwave.gate.operations.base.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: Optional[Sequence[dwave.gate.primitives.Bit]][source]

The bits in which the measurement samples are stored.

expval(qubits: Optional[int] = 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: Optional[Sequence[int]] = None, num_samples: int = 1, as_bitstring: bool = False) List[Union[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: Optional[NDArray][source]

The circuit state when measured.

class Operation(qubits: Optional[Union[dwave.gate.primitives.Qubit, Sequence[dwave.gate.primitives.Qubit]]] = 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: Union[dwave.gate.primitives.Bit, Sequence[dwave.gate.primitives.Bit]]) dwave.gate.operations.base.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: Optional[Tuple[dwave.gate.primitives.Qubit, ...]][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: Union[dwave.gate.primitives.Variable, complex, Sequence[Union[dwave.gate.primitives.Variable, complex]]], qubits: Optional[Union[dwave.gate.primitives.Qubit, Sequence[dwave.gate.primitives.Qubit]]] = None)[source]

Bases: dwave.gate.operations.base.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: Optional[Sequence[complex]] = None, in_place: bool = False) dwave.gate.operations.base.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).

  • in_place – 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: dwave.gate.circuit.ParametricCircuit, name: Optional[str] = None) Type[dwave.gate.operations.base.CustomParametricOperation][source]
create_operation(circuit: dwave.gate.circuit.Circuit, name: Optional[str] = None) Type[dwave.gate.operations.base.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 dwave.gate.operations.operations.CCX

class CCX(qubits: Optional[Union[dwave.gate.primitives.Qubit, Sequence[dwave.gate.primitives.Qubit]]] = None)[source]

Bases: dwave.gate.operations.base.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: Optional[Mapping] = 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: Optional[Union[dwave.gate.primitives.Qubit, Sequence[dwave.gate.primitives.Qubit]]] = None, target: Optional[Union[dwave.gate.primitives.Qubit, Sequence[dwave.gate.primitives.Qubit]]] = None, **kwargs)[source]

Bases: dwave.gate.operations.base.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: Optional[Mapping] = 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: Union[dwave.gate.primitives.Variable, complex, Sequence[Union[dwave.gate.primitives.Variable, complex]]], control: Optional[Union[dwave.gate.primitives.Qubit, Sequence[dwave.gate.primitives.Qubit]]] = None, target: Optional[Union[dwave.gate.primitives.Qubit, Sequence[dwave.gate.primitives.Qubit]]] = None, **kwargs)[source]

Bases: dwave.gate.operations.base.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: Optional[Mapping] = 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: Union[dwave.gate.primitives.Variable, complex, Sequence[Union[dwave.gate.primitives.Variable, complex]]], control: Optional[Union[dwave.gate.primitives.Qubit, Sequence[dwave.gate.primitives.Qubit]]] = None, target: Optional[Union[dwave.gate.primitives.Qubit, Sequence[dwave.gate.primitives.Qubit]]] = None, **kwargs)[source]

Bases: dwave.gate.operations.base.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: Optional[Mapping] = 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: Union[dwave.gate.primitives.Variable, complex, Sequence[Union[dwave.gate.primitives.Variable, complex]]], control: Optional[Union[dwave.gate.primitives.Qubit, Sequence[dwave.gate.primitives.Qubit]]] = None, target: Optional[Union[dwave.gate.primitives.Qubit, Sequence[dwave.gate.primitives.Qubit]]] = None, **kwargs)[source]

Bases: dwave.gate.operations.base.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: Optional[Mapping] = 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: Union[dwave.gate.primitives.Variable, complex, Sequence[Union[dwave.gate.primitives.Variable, complex]]], control: Optional[Union[dwave.gate.primitives.Qubit, Sequence[dwave.gate.primitives.Qubit]]] = None, target: Optional[Union[dwave.gate.primitives.Qubit, Sequence[dwave.gate.primitives.Qubit]]] = None, **kwargs)[source]

Bases: dwave.gate.operations.base.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: Optional[Mapping] = 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: Optional[Union[dwave.gate.primitives.Qubit, Sequence[dwave.gate.primitives.Qubit]]] = None)[source]

Bases: dwave.gate.operations.base.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: Optional[Mapping] = 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: Optional[Union[dwave.gate.primitives.Qubit, Sequence[dwave.gate.primitives.Qubit]]] = None, target: Optional[Union[dwave.gate.primitives.Qubit, Sequence[dwave.gate.primitives.Qubit]]] = None, **kwargs)[source]

Bases: dwave.gate.operations.base.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: Optional[Mapping] = 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: Optional[Union[dwave.gate.primitives.Qubit, Sequence[dwave.gate.primitives.Qubit]]] = None, target: Optional[Union[dwave.gate.primitives.Qubit, Sequence[dwave.gate.primitives.Qubit]]] = None, **kwargs)[source]

Bases: dwave.gate.operations.base.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: Optional[Mapping] = 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: Optional[Union[dwave.gate.primitives.Qubit, Sequence[dwave.gate.primitives.Qubit]]] = None, target: Optional[Union[dwave.gate.primitives.Qubit, Sequence[dwave.gate.primitives.Qubit]]] = None, **kwargs)[source]

Bases: dwave.gate.operations.base.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: Optional[Mapping] = 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: Optional[Union[dwave.gate.primitives.Qubit, Sequence[dwave.gate.primitives.Qubit]]] = None)[source]

Bases: dwave.gate.operations.base.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: Optional[Mapping] = 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: Optional[Union[dwave.gate.primitives.Qubit, Sequence[dwave.gate.primitives.Qubit]]] = None)[source]

Bases: dwave.gate.operations.base.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: Optional[Mapping] = 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 dwave.gate.operations.operations.S

Phase[source]

Phase operation (aliases for the S operation)

class RX(parameters: Union[dwave.gate.primitives.Variable, complex, Sequence[Union[dwave.gate.primitives.Variable, complex]]], qubits: Optional[Union[dwave.gate.primitives.Qubit, Sequence[dwave.gate.primitives.Qubit]]] = None)[source]

Bases: dwave.gate.operations.base.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: Optional[Mapping] = 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: Union[dwave.gate.primitives.Variable, complex, Sequence[Union[dwave.gate.primitives.Variable, complex]]], qubits: Optional[Union[dwave.gate.primitives.Qubit, Sequence[dwave.gate.primitives.Qubit]]] = None)[source]

Bases: dwave.gate.operations.base.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: Optional[Mapping] = 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: Union[dwave.gate.primitives.Variable, complex, Sequence[Union[dwave.gate.primitives.Variable, complex]]], qubits: Optional[Union[dwave.gate.primitives.Qubit, Sequence[dwave.gate.primitives.Qubit]]] = None)[source]

Bases: dwave.gate.operations.base.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: Optional[Mapping] = 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: Union[dwave.gate.primitives.Variable, complex, Sequence[Union[dwave.gate.primitives.Variable, complex]]], qubits: Optional[Union[dwave.gate.primitives.Qubit, Sequence[dwave.gate.primitives.Qubit]]] = None)[source]

Bases: dwave.gate.operations.base.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: Optional[Mapping] = 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: Optional[Union[dwave.gate.primitives.Qubit, Sequence[dwave.gate.primitives.Qubit]]] = None)[source]

Bases: dwave.gate.operations.base.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: Optional[Mapping] = 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: Optional[Union[dwave.gate.primitives.Qubit, Sequence[dwave.gate.primitives.Qubit]]] = None)[source]

Bases: dwave.gate.operations.base.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: Optional[Mapping] = 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: Optional[Union[dwave.gate.primitives.Qubit, Sequence[dwave.gate.primitives.Qubit]]] = None)[source]

Bases: dwave.gate.operations.base.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: Optional[Mapping] = 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: Optional[Union[dwave.gate.primitives.Qubit, Sequence[dwave.gate.primitives.Qubit]]] = None)[source]

Bases: dwave.gate.operations.base.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: Optional[Mapping] = 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: Optional[Union[dwave.gate.primitives.Qubit, Sequence[dwave.gate.primitives.Qubit]]] = None)[source]

Bases: dwave.gate.operations.base.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: Optional[Mapping] = 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: Optional[Union[dwave.gate.primitives.Qubit, Sequence[dwave.gate.primitives.Qubit]]] = None)[source]

Bases: dwave.gate.operations.base.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: Optional[Mapping] = 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