-
Notifications
You must be signed in to change notification settings - Fork 21
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
feat: allow negative controlled global phase gate #216
Open
jcjaskula-aws
wants to merge
7
commits into
main
Choose a base branch
from
jcjaskula-aws/allow_negctrl_gphase
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d449170
ignore vscode settings
jcjaskula-aws 6dbe0a4
allow negctrl gphase
jcjaskula-aws c4f2cda
warn gphase is not supported by the service
jcjaskula-aws 6f18a9a
update test name
jcjaskula-aws 6648e27
fixes according to feedbacl
jcjaskula-aws e34143d
remove warning
jcjaskula-aws 211976b
Merge branch 'main' into jcjaskula-aws/allow_negctrl_gphase
speller26 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 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 |
---|---|---|
|
@@ -34,3 +34,4 @@ test/unit_tests/.DS_Store | |
test/unit_tests/braket/.DS_Store | ||
test/.benchmarks | ||
.DS_Store | ||
.vscode/* |
This file contains 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 |
---|---|---|
|
@@ -54,17 +54,16 @@ def is_controlled(phase: QuantumPhase) -> bool: | |
return False | ||
|
||
|
||
def convert_phase_to_gate(controlled_phase: QuantumPhase) -> QuantumGate: | ||
def convert_phase_to_gate(controlled_phase: QuantumPhase) -> Union[QuantumGate, list[QuantumGate]]: | ||
"""Convert a controlled quantum phase into a quantum gate""" | ||
ctrl_modifiers = get_ctrl_modifiers(controlled_phase.modifiers) | ||
first_ctrl_modifier = ctrl_modifiers[-1] | ||
if first_ctrl_modifier.modifier == GateModifierName.negctrl: | ||
raise ValueError("negctrl modifier undefined for gphase operation") | ||
if first_ctrl_modifier.argument.value == 1: | ||
ctrl_modifiers.pop() | ||
else: | ||
ctrl_modifiers[-1].argument.value -= 1 | ||
return QuantumGate( | ||
|
||
ctrl_phaseshift = QuantumGate( | ||
ctrl_modifiers, | ||
Identifier("U"), | ||
[ | ||
|
@@ -75,6 +74,17 @@ def convert_phase_to_gate(controlled_phase: QuantumPhase) -> QuantumGate: | |
controlled_phase.qubits, | ||
) | ||
|
||
if first_ctrl_modifier.modifier == GateModifierName.negctrl: | ||
X = QuantumGate( | ||
jcjaskula-aws marked this conversation as resolved.
Show resolved
Hide resolved
|
||
[], | ||
Identifier("x"), | ||
[], | ||
[controlled_phase.qubits[-1]], | ||
) | ||
return [X, ctrl_phaseshift, X] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm confused how this is being handled without any changes to inline_gate_def_body There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. me too. Reworked the functions that needed a change. |
||
else: | ||
return ctrl_phaseshift | ||
|
||
|
||
def get_ctrl_modifiers(modifiers: list[QuantumGateModifier]) -> list[QuantumGateModifier]: | ||
"""Get the control modifiers from a list of quantum gate modifiers""" | ||
|
This file contains 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 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 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This approach increases complexity, particularly in
inline_gate_def_body
which has a lot of logic embedded already. I wonder if we shouldn't be handling "controlled phase instructions" logic during interpretation, but rather inProgramContext.add_phase_instruction
. I guess it comes down to whether controlled phases are considered part of the spec, or up to implementation (which now we do a mix of both)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is a nice point you are raising. It is problably ok to defer later to the context construction. The BDK should anyway have the logic to handle it if necessary.