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 overcontrol
andtarget
, 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 regularproperty
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_qubits[source]¶
Decorator class for creating a property for a class/instance method.
Note that the
mixedproperty
decorator differs from the regularproperty
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 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 regularproperty
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.
- 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
- 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 regularproperty
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.
- num_qubits[source]¶
Decorator class for creating a property for a class/instance method.
Note that the
mixedproperty
decorator differs from the regularproperty
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 ofself
(returned).
- Returns
Either
self
or a copy ofself
.- Return type
- 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 regularproperty
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
- 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
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]¶
- 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
- 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.
- 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.
- 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.
- 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
- 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
- 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.
- 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.
- 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.
- 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.
- 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.
- P[source]¶
alias of
dwave.gate.operations.operations.S
- 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.
- 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.
- 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.
- 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.
- 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
- 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.
- 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
- 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.
- 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.
- 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.
- 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.