QuTech-Delft / OpenSquirrel

A flexible (Python-based) quantum program compiler
Apache License 2.0
5 stars 2 forks source link

Initial register management implementation #176

Closed rturrado closed 4 months ago

rturrado commented 4 months ago

Add RegisterManager class

A circuit has a register manager. A register manager only holds, for the moment, a (virtual) qubit and bit register size and names. The bit register size is set to that of the qubit register.

Add Mapping class

A mapping is a dictionary from a (virtual) qubit register to a physical qubit register. Mapping correctness is a class invariant. I.e., it is checked during the construction of the mapping.

Change relabel code into _QubitRemapper

_QubitRemapper implements SquirrelIRVisitor to update the qubit indices according to a Mapping.

Update circuit.map

Remove maq_qubits free function and rename circuit.map_qubits to circuit.map (to be consistent with circuit.decompose and so on). A mapper is created with a valid mapping and then returns its mapping through get_mapping(). circuit.map invokes remap_ir with a given mapper.get_mapping(), and remap_ir uses an SquirrelIRVisitor to update the qubit indices.

Remove SquirrelIR's number of qubits and qubit register name

This information is accessed through the circuit's register manager.

Move _QubitReindexer code to reindexer/qubit_reindexer.py.

Rename check_valid_replacement to check_gate_replacement. Rename get_matrix_after_qubit_remapping to get_circuit_matrix(get_reindexed_circuit()). Rename qubit_mappings to qubit_indices.

Add tests for _QubitReindexer and _QubitRemapper.

Rename parser/libqasm/libqasm_ir_creator.py to parser/libqasm/parser.py.