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

[CQT-293] Remove generators #412

Merged
merged 13 commits into from
Feb 6, 2025
Merged

[CQT-293] Remove generators #412

merged 13 commits into from
Feb 6, 2025

Conversation

rturrado
Copy link
Contributor

@rturrado rturrado commented Dec 19, 2024

Must read

This PR is mainly an investigation, although offering already a working implementation as a proof of concept. As such, I would advise to read first the Confluence page, and then use the PR as a companion to see the implementation changes.

Changes

This PR includes also other changes and fixes (some of which may not be detailed in the Confluence page):

  • Fix the accept implementation of the IR node classes.
  • Make try_match_replace_with_default (old try_name_anonymous_gate) work with Rx, Ry, and Rz, e.g., Rx(pi/4) 4 times gives now Rx(pi), and not an anoymous Bloch.
  • Make gate modifiers try naming an anonymous Bloch, e.g., inv.inv.X is now an X, not anonymous anymore.

Change log

  • Change default instructions from callables to IR node classes.
  • Move default instructions to IR.
  • Remove generators from IR instructions.
  • Remove ANNOTATIONS_TO_TYPE_MAP.
  • Remove instruction decorators.
  • Remove instruction_library.py.

Change default gate modifiers from callables to classes.
Move default instructions and default gate modifiers to IR.

Remove generators from IR instructions.
Remove ANNOTATIONS_TO_TYPE_MAP.
Remove instruction decorators.
Remove instruction_library.py.

Pass all tests except for test_gate_modifiers.
Pass format and ruff check --fix linters.

TODO:
- Rewrite parser.py using instruction_generator.
- Pass gate modifiers tests.
Change default gate modifiers back from IR nodes to functors.
Add inv.inv.X gate modifier test.

Pass all tests.
Pass format and ruff check --fix linters.
Rewrite test_anonymous_gate test in test_tutorial.py.

Pass all linters.
Copy link
Collaborator

@elenbaasc elenbaasc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice refactor, thanks a lot for the effort!

Mostly some minor comments.

I see indeed the slight increase in overhead, but the clarity of how the ir is built and processed is improved a lot!

docs/tutorial.md Show resolved Hide resolved
opensquirrel/circuit.py Show resolved Hide resolved
opensquirrel/ir.py Show resolved Hide resolved
opensquirrel/ir.py Outdated Show resolved Hide resolved
opensquirrel/ir.py Outdated Show resolved Hide resolved
opensquirrel/passes/exporter/cqasmv1_exporter.py Outdated Show resolved Hide resolved
opensquirrel/reindexer/qubit_reindexer.py Outdated Show resolved Hide resolved
test/test_ir.py Show resolved Hide resolved
# Conflicts:
#	opensquirrel/default_instructions.py
#	opensquirrel/ir.py
#	opensquirrel/parser/libqasm/parser.py
#	opensquirrel/passes/exporter/cqasmv1_exporter.py
#	opensquirrel/passes/merger/general_merger.py
#	opensquirrel/utils/matrix_expander.py
#	opensquirrel/writer/writer.py
#	test/docs/test_tutorial.py
#	test/test_circuit_builder.py
Rename BsrWithAngleParm to BsrAngleParam.
Remove Gate::is_anonymous property.
@rturrado rturrado requested a review from elenbaasc February 5, 2025 15:40
Copy link
Collaborator

@elenbaasc elenbaasc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks all good, thanks!

@rturrado rturrado merged commit e930a3e into develop Feb 6, 2025
15 checks passed
@rturrado rturrado deleted the CQT-293-Remove-generators branch February 6, 2025 09:37
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.

2 participants