This is the specific gate I want to implement using pytket: corresponding Wikipedia page

Wikipedia entry of Phase shift gate

I tried:

from pytket import Circuit
circ = Circuit(1)

But I got the following error:

pytket._tket.circuit.Circuit' object has no attribute 'U1'


1 Answer 1


I see that you did figure out that pytket supports the U1(angle) gate which is another name for the P(angle) gate.

To add this gate you need the OpType enum. This is sometimes the case with less common gates. pytket OpType enum

from pytket import Circuit, OpType
from sympy import Symbol
from pytket.utils import circuit_to_symbolic_unitary

angle = Symbol('a')
circ = Circuit(1)
circ.add_gate(OpType.U1, angle, [0])


screen shot of code

  • $\begingroup$ Thank you!! Exactly what I was looking for! $\endgroup$
    – mapper
    Nov 10, 2022 at 17:17

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.