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.$


1 Answer 1


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.

  • $\begingroup$ 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. $\endgroup$
    – Cameron
    Jan 20, 2019 at 22:26
  • $\begingroup$ @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. $\endgroup$ Jan 20, 2019 at 22:58
  • $\begingroup$ 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? $\endgroup$
    – Cameron
    Jan 30, 2019 at 9:24
  • 1
    $\begingroup$ @James I don't think so. Quirk multiplies matrices together; it never really adds them. $\endgroup$ Jan 30, 2019 at 9:27

Your Answer

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

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