1
$\begingroup$

I am trying to simulate random Clifford circuit. I can use stim.Tableau.random(n) to generate it, but don't know how to convert into stim.Circuit() form. It seems current v1.9 does not have to_circuit() function.

$\endgroup$

1 Answer 1

2
$\begingroup$

Since stim v1.10 you can use stim.Tableau.to_circuit to convert a tableau to a circuit. It won't be the maximum efficiency circuit, but it will be a correct circuit. An example:

import stim
tableau = stim.Tableau.random(4)
print(repr(tableau))

circuit = tableau.to_circuit(method="elimination")
print(circuit.diagram())

assert stim.Tableau.from_circuit(circuit) == tableau

The random tableau that came out when I ran the code:

stim.Tableau.from_conjugated_generators(
    xs=[
        stim.PauliString("+YYX_"),
        stim.PauliString("-Y_XZ"),
        stim.PauliString("+XZXY"),
        stim.PauliString("+Z_Y_"),
    ],
    zs=[
        stim.PauliString("+YYZX"),
        stim.PauliString("+XYZY"),
        stim.PauliString("-ZYY_"),
        stim.PauliString("-XX_X"),
    ],
)

And the generated circuit:

q0: -X-@-X-S-H-@-@-@---X-X-X-------------------------------H-S-S-----H-S-S-
     | | |     | | |   | | |
q1: -@-X-@---S-X-|-|-H-@-|-|-X-@-X-S-H-S-@-----------------H---S-S---H-----
                 | |     | | | | |       |
q2: -------------X-|-----@-|-|-|-|-----H-X-X-@-X-S-H-S-X---H-----S-S-H-----
                   |       | | | |         | | |       |
q3: ---------H-----X-------@-@-X-@---------@-X-@-----H-@-S-H-H-----S-S-H---

As you can see, the "elimination" method is going out of its way to not use anything exception H, S, CX. And also it is not attempting to make a shallow circuit.

$\endgroup$
2
  • $\begingroup$ Thanks for the answer! By the way, this there any way to define a gate(so that I can append this random gate directly)? Or append circuits on specific qubits(in this case, the "gate circuit" has a smaller size than the full circuit)? $\endgroup$
    – Yucheng He
    Commented Aug 6, 2022 at 5:22
  • $\begingroup$ @YuchengHe Stim has no concept of defining a custom gate for a circuit. There's also no built-in method for transforming which qubits the circuit operates on. You'll have to write that yourself by iterating over the operations and transforming them individually. $\endgroup$ Commented Aug 6, 2022 at 5:39

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.