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

Implement decomposition of ECAddR, ECWindowAddR, and ECAdd bloqs #1406

Closed
wants to merge 12 commits into from

Conversation

fpapa250
Copy link
Contributor

Implements decomposition of ECAddR and ECPhaseEstimateR to match that of https://arxiv.org/abs/2306.08585.

Removes MeasureQFT() bloq in favor of an actual QFT() bloq and a shimmed in Measure() bloq.

@mpharrigan
Copy link
Collaborator

tests?

@fpapa250
Copy link
Contributor Author

tests?

I added a classical simulation test for ECAddR(). Any recommendations on what tests I should add for ECPhaseEstimateR()?

Also, for the call graph should I include the XorK() bloqs in the counts? I notice you don't include the IntState counts and this is kind of a roundabout way of initializing an intstate in a controlled manor. I can add call graph tests once that is sorted (and once I fix the .controlled() bug on the call graph).

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.

Let's also add a concrete bloq example for ECAdd, which I think will trigger the decomposition bug (?) You can also use this bloq_example to write a minimal unit test that you can indeed bloq.call_classically(...) although you won't be able to assert anything particularly insightful about the results

@@ -33,6 +37,8 @@ class ECAdd(Bloq):
Args:
n: The bitsize of the two registers storing the elliptic curve point
mod: The modulus of the field in which we do the addition.
curve_a: The $a$ coefficient of an elliptic curve given in the standard form of
Copy link
Collaborator

Choose a reason for hiding this comment

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

does this actually affect the decomposition?

This is a little confusing. In litinski they use (x, y) + (a, b) for the curve points and c1, c2 for the curve coefficients. Other references use (x1, y1) + (x2, y2) and a, b for the curve points. Maybe we should switch to using this second scheme.

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 no longer need curve_a for the classical simulation, I can get it from a, b, and lambda_r. I think a and b for the curve coefficients is much more clear than c1, c2. I can swap from (x,y) + (a,b) to (x1,y1) + (x2,y2), but I think (x, y) + (a, b) is easier to understand. I think since we use curve_a instead of just a it is clear that it is different. I'll defer judgement to you on the naming convention and I can change it if you think that's better.

Copy link
Collaborator

Choose a reason for hiding this comment

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

point taken on curve_a but we'll probably want to write latex expressions in some places and then $a$ will be ambiguous.

qualtran/bloqs/factoring/ecc/ec_add_r.py Outdated Show resolved Hide resolved
qualtran/bloqs/factoring/ecc/ec_add_r.py Outdated Show resolved Hide resolved
@@ -67,6 +85,41 @@ def signature(self) -> 'Signature':
[Register('ctrl', QBit()), Register('x', QUInt(self.n)), Register('y', QUInt(self.n))]
)

def build_composite_bloq(
Copy link
Collaborator

Choose a reason for hiding this comment

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

where does this decomposition come from? it does not match the references.

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'm a little confused myself on whether ECAddR and ECWindowAddR are necessary distinctions. Is ECAddR not just supposed to be a single window ECWindowAddR? In that case we can make it one bloq with a var window_size that changes decomposition. Otherwise I couldn't find a special decomposition for the ECAddR circuit so I put what I imagined it would be (initialize a,b from R.x,R.y; ECPointAdd; uninitialize a,b;).

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we chatted in person, but the Roetteler / q# reference has a different circuit for this. What do you want to do here? I think we discussed having the "main call graph" go via ECWindowAddR. We'll keep the reference to the special circuit for adding a constant (without additional register allocation) but not use it

qualtran/bloqs/factoring/ecc/ec_phase_estimate_r.py Outdated Show resolved Hide resolved
@fpapa250
Copy link
Contributor Author

@mpharrigan I'll spend some time today finishing the PR (more tests and fix the call graph for ECAdd). I was wondering if you think ECAdd should be split into sub-bloqs since the decomposition is long and messy?

@fpapa250 fpapa250 changed the title Implement decomposition of ECAddR and improve decomposition of ECPhaseEstimateR. Implement decomposition of ECAddR, ECWindowAddR, and ECAdd bloqs Sep 17, 2024
@NoureldinYosri
Copy link
Contributor

@fpapa250 can you break down this PR into smaller pieces? e.g. "Add Equals", "support serialization of ECPoint", ...etc

@mpharrigan
Copy link
Collaborator

Can you please link all the sub-PRs that you broke this into for the historical record

@mpharrigan mpharrigan marked this pull request as draft October 15, 2024 22:41
@fpapa250
Copy link
Contributor Author

Broke into the following PRs:
#1411
#1412
#1424
#1425

Will make separate new PR for ECWindowAddR

@fpapa250
Copy link
Contributor Author

fpapa250 commented Nov 5, 2024

One more PR:

#1477

Now that they are all merged this PR can be closed as all of it's pieces are merged.

@fpapa250 fpapa250 closed this Nov 5, 2024
@mpharrigan
Copy link
Collaborator

wooooo

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