-
Notifications
You must be signed in to change notification settings - Fork 71
Hamming weight phasing with configurable number of ancilla #1450
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
Open
dobbse42
wants to merge
19
commits into
quantumlib:main
Choose a base branch
from
dobbse42:main
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
19 commits
Select commit
Hold shift + click to select a range
570dd47
added HammingWeightPhasingWithConfigurableAncilla and a temp test fil…
dobbse42 fbe76e8
Merge branch 'main' into main
dobbse42 431bc6d
Finished HammingWeightPhasingWithConfigurableAncilla.build_composite_…
dobbse42 c808bfd
Merge branch 'quantumlib:main' into main
dobbse42 4d84d9d
Merge branch 'main' of https://github.com/dobbse42/Qualtran_hamphase
dobbse42 e484cc0
Completed implementation of HammingWeightPhasingWithConfigurableAncil…
dobbse42 6970437
Merge branch 'main' into main
dobbse42 a8e4ccb
Merge branch 'main' into main
tanujkhattar a7397ac
Merge branch 'main' into main
dobbse42 d344afe
removed extraneous test file
dobbse42 6e16a1c
Merge branch 'main' of https://github.com/dobbse42/Qualtran_hamphase
dobbse42 c0601f1
implemented anurudh's counter suggestion in HWPhasing_with_configurab…
dobbse42 a64283b
fixed syntax error on prior commit
dobbse42 ac77b95
Merge branch 'main' into main
dobbse42 57c87ea
Added input validation
dobbse42 f64e8a3
Merge branch 'main' of https://github.com/dobbse42/Qualtran_hamphase
dobbse42 f5e0a7d
changed to using QECGatesCost and GateCounts for testing and swapped …
dobbse42 414a306
Implemented suggested code style changes and more detailed documentation
dobbse42 a0126a2
Separated HammingWeightPhasingWithConfigurableAncilla decomposition/f…
dobbse42 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,3 +1,3 @@ | ||
# Copyright 2023 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
|
@@ -23,6 +23,7 @@ | |
from qualtran.bloqs.rotations.hamming_weight_phasing import ( | ||
HammingWeightPhasing, | ||
HammingWeightPhasingViaPhaseGradient, | ||
HammingWeightPhasingWithConfigurableAncilla, | ||
) | ||
from qualtran.bloqs.rotations.phase_gradient import PhaseGradientState | ||
from qualtran.cirq_interop.testing import GateHelper | ||
|
@@ -31,6 +32,12 @@ | |
generalize_rotation_angle, | ||
ignore_split_join, | ||
) | ||
from qualtran.resource_counting import ( | ||
QECGatesCost, | ||
GateCounts, | ||
get_cost_value, | ||
) | ||
|
||
from qualtran.symbolics import SymbolicInt | ||
|
||
if TYPE_CHECKING: | ||
|
@@ -127,3 +134,39 @@ | |
naive_total_t = naive_hwp_t_complexity.t_incl_rotations(eps=eps / n.bit_length()) | ||
|
||
assert total_t < naive_total_t | ||
|
||
@pytest.mark.parametrize('n, ancillasize', [(n, ancillasize) for n in range(3, 9) for ancillasize in range(1, n-1)]) | ||
@pytest.mark.parametrize('theta', [1 / 10, 1 / 5, 1 / 7, np.pi / 2]) | ||
def test_hamming_weight_phasing_with_configurable_ancilla(n: int, ancillasize: int, theta: float): | ||
gate = HammingWeightPhasingWithConfigurableAncilla(n, ancillasize, theta) | ||
qlt_testing.assert_valid_bloq_decomposition(gate) | ||
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. these should be seperate tests def test_hamming_weight_phasing_with_configurable_ancilla_has_valid_decomposition():
...
def test_hamming_weight_phasing_with_configurable_ancilla_has_valid_bloq_counts():
...
# etc |
||
qlt_testing.assert_equivalent_bloq_counts( | ||
gate, [ignore_split_join, cirq_to_bloqs, generalize_rotation_angle] | ||
) | ||
|
||
gh = GateHelper(gate) | ||
sim = cirq.Simulator(dtype=np.complex128) | ||
initial_state = cirq.testing.random_superposition(dim=2**n, random_state=12345) | ||
state_prep = cirq.Circuit(cirq.StatePreparationChannel(initial_state).on(*gh.quregs['x'])) | ||
brute_force_phasing = cirq.Circuit(state_prep, (cirq.Z**theta).on_each(*gh.quregs['x'])) | ||
expected_final_state = sim.simulate(brute_force_phasing).final_state_vector | ||
|
||
hw_phasing = cirq.Circuit(state_prep, HammingWeightPhasingWithConfigurableAncilla(n, ancillasize, theta).on(*gh.quregs['x'])) | ||
hw_final_state = sim.simulate(hw_phasing).final_state_vector | ||
assert np.allclose(expected_final_state, hw_final_state, atol=1e-7) | ||
|
||
|
||
@pytest.mark.parametrize('n, ancillasize', [(n, ancillasize) for n in range(3, 9) for ancillasize in range(1, n-1)]) | ||
@pytest.mark.parametrize('theta', [1 / 10, 1 / 5, 1 / 7, np.pi / 2]) | ||
def test_hamming_weight_phasing_with_configurable_ancilla_bloq_counts(n: int, ancillasize: int, theta: float): | ||
gate = HammingWeightPhasingWithConfigurableAncilla(n, ancillasize, theta) | ||
remainder = n % (ancillasize+1) | ||
|
||
# assert gate.t_complexity().rotations == (-(-n // (ancillasize+1))-1) * (ancillasize+1).bit_length() + remainder.bit_length() # exact, fails for remainder = 0. | ||
# Outdated method of doing gatecount tests. Also tests T-count rather than Toffoli count. | ||
# assert gate.t_complexity().rotations <= (-(-n // (ancillasize+1))) * (ancillasize+1).bit_length() + remainder.bit_length() # upper bound | ||
# assert gate.t_complexity().t <= 4 * (ancillasize) * -(-n // (ancillasize+1) | ||
|
||
gc = get_cost_value(gate, QECGatesCost()) | ||
assert gc.rotation <= (-(-n // (ancillasize+1))) * (ancillasize+1).bit_length() + remainder.bit_length() | ||
assert gc.toffoli + gc.and_bloq + gc.cswap <= ancillasize * -(-n // (ancillasize+1)) |
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.
can you add a citation for the source of the construction?