0
$\begingroup$

My goal is to run the Clifford simulation in stim where I apply Clifford gates (not neccesarily listed in the “named gates” list) e.g., random 2-qubit Clifford gates with tableau given by stim.Tableau.random(2). To do this I apply 2-qubit gates to some chosen qubits (by getting the current tableau from the simulator, appending it and resetting the simulator tableau to the new value). For testing I run the following code which simply should create a Bell state (apply H to the 0th qubit and then CNOT with control on the 0th and target on the 1st qubit):

Code:

s = stim.TableauSimulator()

s.set_num_qubits(2)

cnot=stim.Tableau.from_named_gate("CNOT")

h=stim.Tableau.from_named_gate("H")

print(np.abs(s.state_vector()))

print(s.current_inverse_tableau())

tab=s.current_inverse_tableau()

tab.append(h**(-1),[1]) #equiv to Hadamard on the 0th qubit due to little endian convention

s.set_inverse_tableau(tab)

print("H added",1) 

print(np.abs(s.state_vector()))

tab=s.current_inverse_tableau()

print(tab)

tab.append(cnot**(-1),[1, 0]) #CNOT on the 0th qubit

s.set_inverse_tableau(tab)

tab=s.current_inverse_tableau()

print("CNOT added",[1,0])

print(tab)

print(np.abs(s.state_vector()))

Output:

[1. 0. 0. 0.]

+-xz-xz-

| ++ ++

| XZ __

| __ XZ

H added to 1

[0.70710677 0.         0.70710677 0.        ]

+-xz-xz-

| ++ ++

| XZ __

| __ ZX

CNOT added to [1, 0]

+-xz-xz- #tableau modified

| ++ ++

| XZ _X

| _Z ZX

[0.70710677 0.         0.70710677 0.        ] #but state unchanged???

The above gives unexpected result of CNOT not affecting the state created in the previous step (despite the corresponding tableau changed).

I contrast it with the following expected behavior

Code:

s = stim.TableauSimulator()

s.set_num_qubits(2)

s.h(1)

print(np.abs(s.state_vector()))

s.cnot(1,0)

print(np.abs(s.state_vector()))

Output:

[1. 0. 0. 0.]

H added to 1

[0.70710677 0.         0.70710677 0.        ]

CNOT added to [1,0]

[0.70710677 0.         0.         0.70710677]

What am I missing and how to convince stim to produce a desired output in the first case as well?

$\endgroup$

1 Answer 1

1
$\begingroup$

You need to prepend the inverse operation instead of appending the operation, because it's the inverse tableau.

In stim v1.9+ you can use stim.TableauSimulator.do_tableau instead of manually applying the tableau like you're doing here.

$\endgroup$
1
  • $\begingroup$ Thanks - this makes sense and it seems to work! $\endgroup$
    – CatQubit
    Jun 17, 2022 at 20:32

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.