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?
Asked
Active
Viewed 85 times
1 Answers
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])
else:
circ_prime.add_gate(cmd.op.type, cmd.op.params, cmd.qubits)
return circ_prime
Phil
- 135
- 4