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

Add ECAdd() Bloq #1425

Merged
merged 28 commits into from
Oct 23, 2024
Merged

Add ECAdd() Bloq #1425

merged 28 commits into from
Oct 23, 2024

Conversation

fpapa250
Copy link
Contributor

Adds ECAdd bloq with classical simulation. I broke the bloq into the 6 steps shown in https://arxiv.org/abs/2306.08585. I classically simulated all steps. I put in a shimmed ModInv classical implementation (it's not montgomery mod inversion, but it still works on ECPoints not in montgomery form; I'm a little stuck on understanding what to do for R in montgomery mod inversion).

@fpapa250
Copy link
Contributor Author

Dependent on #1424. For testing purposes I put the bug fix in this branch too, but it should be merged first.

@mpharrigan mpharrigan self-requested a review October 2, 2024 21:59
Copy link
Collaborator

@mpharrigan mpharrigan left a comment

Choose a reason for hiding this comment

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

A momentus piece of work! I did not check the exact circuits but the classical testing should give us a great deal of confidence. It would give more confidence if we had matching toffoli costs (and/or defensible reasons for any differences). Some small-ish things for improvement.

qualtran/bloqs/mod_arithmetic/_shims.py Outdated Show resolved Hide resolved
qualtran/bloqs/mod_arithmetic/_shims.py Outdated Show resolved Hide resolved
qualtran/bloqs/mod_arithmetic/_shims.py Outdated Show resolved Hide resolved
qualtran/bloqs/factoring/ecc/ec_point.py Show resolved Hide resolved
qualtran/bloqs/factoring/ecc/ec_add.py Outdated Show resolved Hide resolved
qualtran/bloqs/factoring/ecc/ec_add.py Outdated Show resolved Hide resolved
qualtran/bloqs/factoring/ecc/ec_add.py Outdated Show resolved Hide resolved
qualtran/bloqs/factoring/ecc/ec_add_test.py Show resolved Hide resolved
qualtran/bloqs/factoring/ecc/ec_add_test.py Outdated Show resolved Hide resolved
qualtran/bloqs/factoring/ecc/ec_add_test.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@mpharrigan mpharrigan left a comment

Choose a reason for hiding this comment

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

it's tough to judge the right trade-offs for testing these. Left my comments. Thanks for opening and linking the other issues!

qualtran/_infra/data_types.py Outdated Show resolved Hide resolved
qualtran/_infra/data_types.py Outdated Show resolved Hide resolved
qualtran/bloqs/factoring/ecc/ec_add_test.py Show resolved Hide resolved
(0, 0),
],
)
def test_ec_add_steps_classical(n, m, a, b, x, y):
Copy link
Collaborator

Choose a reason for hiding this comment

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

the parameterization here seems a little gratuitous. do we need the outer product of all possible n x m? What are we probing with different n values? it either fits or it doesn't, no? how about picking some extremal pairs? Do we need the complete outer product of point1 x point2? Maybe cross all possible point1 with some select extremal point2's

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I pretty much halved the testing by removing a big chunk of the pairs. I did it in a way such that all 4 bugs from #1461 would still trigger if I made the frees non-dirty. Let me know if you want me to further reduce the tests. All-in-all it runs in 1 min 30 s on my pc with the slow tests running.

qualtran/_infra/data_types.py Outdated Show resolved Hide resolved
@@ -39,6 +42,20 @@ def build_call_graph(self, ssa: SympySymbolAllocator) -> BloqCountDictT:
return {Toffoli(): self.n - 2}


@frozen
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this should be a shim

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree it's easy to implement, but I think it is out of scope for this PR - it is a component of ModInv not ECAdd. I just changed it in this PR to make the Toffoli count test more accurate.

@@ -103,6 +117,29 @@ def build_call_graph(self, ssa: 'SympySymbolAllocator') -> 'BloqCountDictT':
Swap(self.n): 1,
}

def on_classical_vals(
Copy link
Contributor

Choose a reason for hiding this comment

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

why use the shim instead of the actual implementation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I only implemented enough to test that ECAdd works - when ModInverse bloq is merged I'm happy to replace the shim with that in the construction/tests.

@mpharrigan mpharrigan enabled auto-merge (squash) October 18, 2024 19:59
auto-merge was automatically disabled October 18, 2024 23:56

Head branch was pushed to by a user without write access

@mpharrigan mpharrigan merged commit e3aeee0 into quantumlib:main Oct 23, 2024
8 checks passed
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.

3 participants