After applying some compiler passes in pytket, I get gates like rx(3.5*pi). Is there a pass that simply shortens the angles by multiples of 2 pi, so that I get rx(1.5*pi) instead?

  • 1
    $\begingroup$ Hi there. There's no specific pytket pass but if you like I can perhaps share how to write a pytket CustomPass to accomplish this. Out of curiosity, did you have a particular use for this in mind? Or would you just prefer to reduce the angles modulo 2*pi for tidiness? $\endgroup$
    – Callum
    May 10, 2023 at 21:19
  • $\begingroup$ Thanks for your comment. There is no specific reason other than a cleaner look of the created QASM code. I think it will not be difficult to write a CustomPass for this, just wanted to check if there is already a solution I did not find in the documentation. $\endgroup$
    – Phil
    May 11, 2023 at 7:57

1 Answer 1


Based on Callums feedback I wrote a function for a CustomPass.

def shorten_rotations(circ: Circuit) -> Circuit:
    circ_prime = Circuit(circ.n_qubits, circ.n_bits)
    for cmd in circ.get_commands():
        if cmd.op.type in (OpType.Rx, OpType.Ry, OpType.Rz):
            params_prime = cmd.op.params
            params_prime[0] = params_prime[0] % 2
            circ_prime.add_gate(cmd.op.type, params_prime, cmd.qubits)
        elif cmd.op.type == OpType.Measure:
            circ_prime.Measure(cmd.qubits[0].index[0], cmd.bits[0].index[0])
            circ_prime.add_gate(cmd.op.type, cmd.op.params, cmd.qubits)
    return circ_prime
  • 1
    $\begingroup$ Nice one, looks good to me :) $\endgroup$
    – Callum
    May 11, 2023 at 10:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.