Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

restrict classical action of certain arithmetic bloqs #1518

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

NoureldinYosri
Copy link
Contributor

@NoureldinYosri NoureldinYosri commented Jan 8, 2025

  • SubtractFrom.on_classical_values was using math.fmod which fails in the case of overflow ... using simulation.classical_sim.add_ints instead
  • bloqs for modular arithmetic assume that their inputs are in the correct range $[0, \mod)$ ... fixing the classical action is easy for them ... but the decompositions/constructions will fail on those inputs since they were not designed to handle them.

fixes #1515

@NoureldinYosri NoureldinYosri marked this pull request as ready for review January 9, 2025 00:59
Comment on lines 90 to 92
if x < self.mod and y < self.mod:
y = (x + y) % self.mod
return {'x': x, 'y': y}
Copy link
Contributor

Choose a reason for hiding this comment

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

should we instead raise a ValueError for out-of-bounds inputs? (similar to e.g. BQUInt.assert_valid_classical_val).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

depends on how you define the bloq ... if we want the bloq to be unitary then the classical action is correct and we don't need to raise an error

however constructions assume valid range ... I don't feel strongly towards either ... although I'm a bit leaning towards raising an error to match the construction

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd prefer that the classical action raises an error. The tensors-from-classical-action function would need to handle this, of course

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect on_classical_vals overrides for non classical bloqs
3 participants