Registers#

Registers for collecting qubits, bits and variables.

Provides performant container classes for keeping track of and handling primitive type objects (see dwave.gate.primitives for details on the supported objects).

Registers Module#

class ClassicalRegister(data: Sequence[Bit] | None = None)[source]#

Bases: Register[Bit]

Classical register to store bits.

Parameters:

data – Sequence of bits (defaults to empty).

freeze() None[source]#

Freezes the register so that no bits can be added or removed.

to_qasm(label: Hashable | None = None, idx: int | None = None) str[source]#

Converts the classical register into an OpenQASM string.

Parameters:
  • label – Optional label for the quantum register.

  • idx – Optional index number for quantum register.

Returns:

OpenQASM string representation of the circuit.

Return type:

str

class QuantumRegister(data: Sequence[Qubit] | None = None)[source]#

Bases: Register[Qubit]

Quantum register to store qubits.

Parameters:

data – Sequence of qubits (defaults to empty).

freeze() None[source]#

Freezes the register so that no qubits can be added or removed.

to_qasm(label: Hashable | None = None, idx: int | None = None) str[source]#

Converts the quantum register into an OpenQASM string.

Parameters:
  • label – Optional label for the quantum register.

  • idx – Optional index number for quantum register.

Returns:

OpenQASM string representation of the circuit.

Return type:

str

class Register(data: Sequence[Data] | None = None)[source]#

Bases: cyRegister, AbstractSet[Data], Sequence[Data]

Register to store qubits and/or classical bits.

Parameters:

data – Sequence of hashable data items (defaults to empty).

add(data: Hashable | Sequence[Hashable] | Register) None[source]#

Add one or more data items to the register.

Parameters:

data – One or more data items to add to the register.

property data: Sequence[Data][source]#

Sequence of qubits or bits.

freeze() None[source]#

Freezes the register so that no (qu)bits can be added or removed.

property frozen: bool[source]#

Whether the register is frozen and no more data can be added.

exception RegisterError[source]#

Bases: Exception

Exception to be raised when there is an error with a Register.

class SelfIncrementingRegister(data: Sequence[Variable] | None = None)[source]#

Bases: Register

Self-incrementing classical register to store parameter variables.

The self-incrementing register will automatically add variable parameters when attemting to index outside of the register scope, and then return the requested index. For example, attempting to get parameter at index 3 in a SelfIncrementingRegister of length 1 would be equal to first running Register.add([Variable("p1"), Variable("p2")]) and then returning Variable("p2").

Parameters:
  • label – Classical register label. data: Sequence of bits (defaults to empty).

  • data – Sequence of parameters or variables (defaults to empty).

freeze() None[source]#

Freezes the register so that no data can be added or removed.