loom.cliffordsim.classicalreg

Copyright 2024 Entropica Labs Pte Ltd

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

class loom.cliffordsim.classicalreg.ClassicalRegister(name, no_of_bits, bit_ids=None)[source]

Bases: object

A register that stores classical bits that can be accessed at runtime by the Engine.

Comments: Consider Big Registry Design with Smaller Classical Registers as Views. Similar design to Tableau where all quantum data is in a Tableau.

Parameters:
  • name (str) – The name of this classical register.

  • no_of_bits (int) – The number of bits the register will be initialized with.

  • bit_ids (Optional[list[str]]) – A list containing the ids of every bit in the classical register. The ids provided do not have to be uuid compatible but must be of equal length to the number of bits. If the bit ids are not provided, the bits will be initialized with randomized ids generated using uuid4.

property bit_ids: list[str]

The bit IDs of all the bits in the classical register.

property bit_reg: list[int]

The bit values of all the bits in the classical register.

create_snapshot()[source]

Creates a ClassicalRegisterSnapshot object, a snapshot of the state of the ClassicalRegister, that contains important properties of the ClassicalRegister.

The ClassicalRegisterSnapshot object can then be used to restore the state of the ClassicalRegister at the time the snapshot was created.

Return type:

ClassicalRegisterSnapshot

property id_bit_reg: dict[str, int]

A dictionary whose key, value pairs are the bit IDs and their respective bit values.

property no_of_bits: int

The total number of bits in the current classical register.

property reg: list[tuple[str, int]]

The classical register represented as a list of tuples whose first entry is the ID of the bit and the second entry is the value of the bit.

classmethod restore(cr_snapshot)[source]

This method allows us to restore the state of the ClassicalRegister with a ClassicalRegisterSnapshot Object. The method returns an initialized ClassicalRegister with the Snapshot state.

Return type:

ClassicalRegister

class loom.cliffordsim.classicalreg.ClassicalRegisterSnapshot(name, no_of_bits, reg)[source]

Bases: object

A snapshot of the classical register at a specific point in time.

name: str
no_of_bits: int
reg: list[tuple[str, int]]