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

Bases: dwave.gate.registers.registers.Register[dwave.gate.primitives.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: Optional[Hashable] = None, idx: Optional[int] = 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: Optional[Sequence[dwave.gate.primitives.Qubit]] = None)[source]

Bases: dwave.gate.registers.registers.Register[dwave.gate.primitives.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: Optional[Hashable] = None, idx: Optional[int] = 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: Optional[Sequence[dwave.gate.registers.registers.Data]] = None)[source]

Bases: dwave.gate.registers.cyregister.cyRegister, AbstractSet[dwave.gate.registers.registers.Data], Sequence[dwave.gate.registers.registers.Data]

Register to store qubits and/or classical bits.

Parameters

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

add(data: Union[Hashable, Sequence[Hashable], dwave.gate.registers.registers.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[dwave.gate.registers.registers.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: Optional[Sequence[dwave.gate.primitives.Variable]] = None)[source]

Bases: dwave.gate.registers.registers.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.