Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial register management implementation #176

Merged
merged 16 commits into from
May 8, 2024

Conversation

rturrado
Copy link
Contributor

@rturrado rturrado commented May 1, 2024

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.

…ter-management-implementation

# Conflicts:
#	pyproject.toml
A circuit has a register manager.
A register manager holds:
- a (virtual) qubit and bit register size and names,
- a mapping.

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.

Remove relabel code.
Qubits always hold their (virtual) qubit index.
A circuit, through its register manager, holds the current mapping.
Writers can get the physical qubit index for a given qubit through the register manager.

Remove IR's number of qubits and qubit register name.
This information is accessed through the circuit's register manager.
@rturrado rturrado requested review from juanboschero and S-Linde May 1, 2024 08:51
@rturrado rturrado linked an issue May 1, 2024 that may be closed by this pull request
rturrado added 2 commits May 1, 2024 12:06
…ation

# Conflicts:
#	opensquirrel/mapper/general_mapper.py
#	opensquirrel/mapper/simple_mappers.py
#	opensquirrel/utils/check_passes/check_mapper.py
TODO: check get_matrix_after_qubit_remapping.
- Can this code be updated to use the new Mapping class?
- Check qubit_remapper, _QubitReIndexer.
juanboschero
juanboschero previously approved these changes May 2, 2024
opensquirrel/circuit.py Outdated Show resolved Hide resolved
opensquirrel/mapper/general_mapper.py Show resolved Hide resolved
opensquirrel/register_manager.py Outdated Show resolved Hide resolved
opensquirrel/register_manager.py Show resolved Hide resolved
TODO: check get_matrix_after_qubit_remapping.
- Can this code be updated to use the new Mapping class?
- Check qubit_remapper, _QubitReIndexer.
TODO: check get_matrix_after_qubit_remapping.
- Can this code be updated to use the new Mapping class?
- Check qubit_remapper, _QubitReIndexer.
juanboschero
juanboschero previously approved these changes May 2, 2024
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.
Change qubit_reindexer to work with indices instead of qubits.
rturrado added 2 commits May 3, 2024 12:03
Update _QubitReindexer to be usable with a whole circuit.
Update Circuit.map to perform reindexation according to mapper.get_mapping().
Fix Measure.accept.
opensquirrel/mapper/mapping.py Show resolved Hide resolved
opensquirrel/squirrel_ir.py Show resolved Hide resolved
rturrado added 2 commits May 7, 2024 17:54
circuit.map always remaps the IR.
Add test_qubit_remapper.py.
Add test_qubit_reindexer.py.
…ation

# Conflicts:
#	opensquirrel/circuit_builder.py
#	opensquirrel/exporter/quantify_scheduler_exporter.py
#	test/exporter/test_quantify_scheduler_exporter.py
#	test/test_circuit_builder.py
#	test/test_integration.py
#	test/test_writer.py
@rturrado rturrado requested a review from juanboschero May 7, 2024 16:28
…isitor methods.

Removed _QubitReindexer.comment method.
@rturrado rturrado merged commit dac4f35 into develop May 8, 2024
11 of 17 checks passed
@rturrado rturrado deleted the 167-initial-register-management-implementation branch June 4, 2024 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Initial register management implementation
2 participants