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

Use tket2 angle type for quantum gate parameters #240

Closed
ss2165 opened this issue Jun 12, 2024 · 1 comment · Fixed by #467
Closed

Use tket2 angle type for quantum gate parameters #240

ss2165 opened this issue Jun 12, 2024 · 1 comment · Fixed by #467
Assignees
Labels
enhancement New feature or request

Comments

@ss2165
Copy link
Member

ss2165 commented Jun 12, 2024

No description provided.

@ss2165 ss2165 added the enhancement New feature or request label Jun 12, 2024
@ss2165 ss2165 assigned ss2165, mark-koch and cqc-alec and unassigned ss2165 and mark-koch Aug 14, 2024
@cqc-alec
Copy link
Contributor

I think there are three motivations for having an angle type distinct from float:

  1. the desire to express commonly used angles exactly;
  2. the desire to compare angles (and hence operations including them) for equality;
  3. being able to express mod-2pi equivalence as value equality.

Actually floating point is good enough to meet (1) for dyadic rationals (i.e. angles of the form (a/2^n) pi where a and n are integers). I think that the dyadic rationals are the most commonly used angles in quantum circuits, as they arise naturally in the Clifford hierarchy; however, occasionally other rationals are wanted: an example (the only one I can find) is the FSim gate, which uses an angle of 1/6. So there is an argument for being to able to express arbitrary rational multiples of pi exactly (up to some maximum size of denominator).

However, one advantage of working with dyadics rather than general rationals is that converting from float is easy: we can specify a maximum denominator and take the nearest approximation, or simply convert exactly (since the exact value of every finite float is a dyadic rational). With general rationals that is not so easy: finding the nearest rational with denominator <= b is non-trivial, so we'd actually have to specify the exact denominator, which may not be known. In the other direction, dyadic rationals would be represented correctly for denominators up to about 2^52, which is good enough for practical purposes.

I think the simplicity of the angle--float round trip is a good enough reason to restrict to dyadics, given that they account for most of the exact angles used in quantum circuits.

We can then define operations of

  • addition
  • subtraction
  • negation
  • multiplication by int
  • division by int

all of which reduce their result modulo 1. Dividing by int is the most problematic case. It is convenient to be able to write e.g. alpha/2 in guppy code when alpha is an angle; but when dividing by an int that is not a power of 2 the result may not be a dyadic rational and we may be forced to approximate with a large denominator. I think this case would be rare, however.

@ss2165 ss2165 assigned mark-koch and unassigned cqc-alec Sep 4, 2024
@ss2165 ss2165 added this to the guppylang 0.11.0 milestone Sep 11, 2024
github-merge-queue bot pushed a commit that referenced this issue Sep 11, 2024
Closes #240

BREAKING CHANGE: Quantum operations `rx`, `rz`, `phased_x`, and `zz_max`
use the `angle` type instead of floats.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants