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

Simplify circuit first before rebase #971

Open
yao-cqc opened this issue Aug 15, 2023 · 3 comments
Open

Simplify circuit first before rebase #971

yao-cqc opened this issue Aug 15, 2023 · 3 comments
Labels
enhancement New feature or request stale

Comments

@yao-cqc
Copy link
Contributor

yao-cqc commented Aug 15, 2023

from pytket.circuit import Circuit
from pytket.passes import SynthesiseTK, CommuteThroughMultis, RemoveRedundancies
c = Circuit(2).Rz(0.3,0).CX(0,1).Rz(-0.3,0).CX(0,1)
SynthesiseTK().apply(c)
# [TK1(0.5, 0.5, 3.5) q[0]; TK1(0, 3, 3) q[1]; TK2(0.5, 0, 0) q[0], q[1]; TK2(0.5, 0, 0) q[0], q[1]; TK1(0.5, 0.5, 0.5) q[0]; TK1(0, 0, 1) q[1]; ]

But original c should be easily reduced to identity with:

CommuteThroughMultis().apply(c)
RemoveRedundancies().apply(c)

The problem is that SynthesiseTK (i.e. synthesise_tk) does the TK2 rebase first, which makes it harder for the subsequent optimisations to work. Same thing applies to synthesise_tket.

I think this behaviour might have a considerable impact on performance since these rebase passes are often ran first. For example, SynthesiseTK in FullPeepholeOptimise and the pytket-quantinuum level 1 pass.

@yao-cqc yao-cqc added the enhancement New feature or request label Aug 15, 2023
@sjdilkes
Copy link
Contributor

sjdilkes commented Aug 15, 2023

I've found similar issues with compiling to TK2 as a target. As an example, SynthesiseTK or the common pytket-quantinuum passes aren't able to clock that XXPhase(a,0,1).YYPhase(b,0,1).ZZPhase(c,0,1) == TK2(a,b,c,0,1).
Or, running FullPeepholeOptimise on YYPhase(b,0,1) returns a TK2(b,0,0,0,1) with a bunch of TK1 wrappers, rather than TK2(0,b,0,0,1). In the FullPeepholeOptimise case, it loses track when converting circuits to CX & TK1 when calling CliffordSimp and is unable to notice and recover the reduced gates.

I agree with the observation that these scenarios could be considerably impacting gate count performance. I'm wondering how far we can get with a new pass that:

  1. Is able to merge TK1 with TK2 by changing the basis of rotations in TK2
  2. Is able to merge TK2 with TK2

@yao-cqc
Copy link
Contributor Author

yao-cqc commented Aug 16, 2023

Not sure how far we can get, but the pass you suggested is definitely worth to have.

Copy link

github-actions bot commented Jun 9, 2024

This issue has been automatically marked as stale.

@github-actions github-actions bot added the stale label Jun 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request stale
Projects
None yet
Development

No branches or pull requests

2 participants