# Creating a time dependent custom gate in Quirk

I have created a $$16\times 16$$ unitary operator using a Hamiltonian by finding its exponential

$$U=\exp(-iH\delta t)$$

If I set $$\delta t=1$$ then I can take this matrix and input it into quirk using the custom gate maker.

Some gates have the option to rotate wrt time. These are the "spinning" gates $$Z^t$$ etc, which performs the rotation $$R_Z(\theta=2\pi t)$$

Is there some way to generalize this spinning to any unitary matrix with a time component?

I feel there must be a way to do it by adjusting $$U$$. Perhaps by rotating all qubits by some angle and then applying a modified $$U$$? But I'm not sure if it's possible since we'd need to do something like $$U'|a\rangle=U^a|0\rangle.$$

## migrated from physics.stackexchange.comJan 20 at 19:50

This question came from our site for active researchers, academics and students of physics.

The only way to make a time-dependent custom gate is to decompose the desired unitary into a circuit using the built-in time-dependent gates (typically $$X$$, $$Y$$ or $$Z^t$$), then make a custom circuit gate using that circuit. (Assuming you're not willing to implement the gate by editing the source code.)

The reason I didn't add support for e.g. using the variable $$t$$ in a custom matrix or rotation gate is that I'm worried that storing the equation could result in very unfortunate backward compatibility constraints (e.g. future versions needing to reproduce existing parsing bugs to keep circuit links from breaking or changing behavior). Also, it doesn't play well with the "ensure unitary" option.

• Ah great okay. Are you aware of a script that decomposes a unitary matrix into XYZ and cNOT for example? If not I could probably have a go at making one. – James Jan 20 at 22:26
• @James It depends on the properties of the matrix. If it's just an arbitrary one then the resulting circuit will be gigantic no matter what. – Craig Gidney Jan 20 at 22:58
• I've managed to cut my unitary matrix into two, i.e. U(t)=A+B(t), where B is a time-dependent sub-circuit I can create with quirk. A is a non-unitary, but constant matrix. Is there some way I can create a superposition of these two gates, within the constraints of the program? – James Jan 30 at 9:24
• @James I don't think so. Quirk multiplies matrices together; it never really adds them. – Craig Gidney Jan 30 at 9:27