-
Notifications
You must be signed in to change notification settings - Fork 1
Properly implement fidelity analysis with SCF #640
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
Merged
+667
−106
Merged
Changes from 13 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
79c692c
Somewhat working version of invoke
david-pl 02edebd
Simplify frame
david-pl c48b222
Some more cleanup work
david-pl 6142600
Implement depolarize and if-stmt
david-pl 6b08b97
Qubit loss
david-pl c440be8
WIP on for loop
david-pl a731b1d
WIP
david-pl f69d4b1
Implement SCF for fidelity analysis re-using AddressAnalysis
david-pl d4ba4de
Simplify IfElse impl
david-pl 3cb2808
Clean up asserts, constant fetching and implement missing methods for…
david-pl 26240d2
Introduce FidelityRange data class to store values
david-pl a2cb44c
Fix qasm2 impls
david-pl 9d0c67c
Update some docstrings
david-pl b422d66
Fix IfElse impl and test known branch execution
david-pl 8767fc3
Fix docstring example
david-pl 6755015
Merge branch 'main' into david/592-3-fidelity-analysis
david-pl 053e798
Merge branch 'main' into david/592-3-fidelity-analysis
weinbe58 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,5 @@ | ||
| from .analysis import FidelityAnalysis as FidelityAnalysis | ||
| from . import impls as impls | ||
| from .analysis import ( | ||
| FidelityRange as FidelityRange, | ||
| FidelityAnalysis as FidelityAnalysis, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| from kirin import interp | ||
| from kirin.analysis import ForwardFrame | ||
| from kirin.dialects import scf | ||
|
|
||
| from bloqade.analysis.address import Address | ||
|
|
||
| from .analysis import FidelityAnalysis | ||
|
|
||
|
|
||
| @scf.dialect.register(key="circuit.fidelity") | ||
| class __ScfMethods(interp.MethodTable): | ||
| @interp.impl(scf.IfElse) | ||
| def if_else( | ||
| self, interp_: FidelityAnalysis, frame: ForwardFrame[Address], stmt: scf.IfElse | ||
| ): | ||
|
|
||
| # NOTE: store a copy of the fidelities | ||
| current_gate_fidelities = interp_.gate_fidelities | ||
| current_survival_fidelities = interp_.qubit_survival_fidelities | ||
|
|
||
| # TODO: check if the condition is constant and fix the branch in that case | ||
| # run both branches | ||
| with interp_.new_frame(stmt, has_parent_access=True) as then_frame: | ||
| # NOTE: reset fidelities before stepping into the then-body | ||
| interp_.reset_fidelities() | ||
|
|
||
| interp_.frame_call_region( | ||
| then_frame, | ||
| stmt, | ||
| stmt.then_body, | ||
| *(interp_.lattice.bottom() for _ in range(len(stmt.args))), | ||
| ) | ||
| then_fids = interp_.gate_fidelities | ||
| then_survival = interp_.qubit_survival_fidelities | ||
|
|
||
| with interp_.new_frame(stmt, has_parent_access=True) as else_frame: | ||
| # NOTE: reset again before stepping into else-body | ||
| interp_.reset_fidelities() | ||
|
|
||
| interp_.frame_call_region( | ||
| else_frame, | ||
| stmt, | ||
| stmt.else_body, | ||
| *(interp_.lattice.bottom() for _ in range(len(stmt.args))), | ||
| ) | ||
|
|
||
| else_fids = interp_.gate_fidelities | ||
| else_survival = interp_.qubit_survival_fidelities | ||
|
|
||
| # NOTE: reset one last time | ||
| interp_.reset_fidelities() | ||
|
|
||
| # NOTE: now update min / max pairs accordingly | ||
| interp_.update_branched_fidelities( | ||
| interp_.gate_fidelities, current_gate_fidelities, then_fids, else_fids | ||
| ) | ||
| interp_.update_branched_fidelities( | ||
| interp_.qubit_survival_fidelities, | ||
| current_survival_fidelities, | ||
| then_survival, | ||
| else_survival, | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.