Unless I'm missing something, mem_swap should have the same semantics as "A swap performed with three cnots". I've found an example for which this does not seem to be the case.
from guppylang import guppy
from guppylang.std.debug import state_result
from guppylang.std.quantum import discard_array, qubit, cx, h
from guppylang.std.builtins import mem_swap, array
from selene_sim import Stim, build
seed = 123
@guppy
def swap_with_cx(q0: qubit, q1: qubit) -> None:
cx(q0, q1)
cx(q1, q0)
cx(q0, q1)
@guppy
def main() -> None:
qs = array(qubit() for _ in range(2))
h(qs[1])
#swap_with_cx(qs[0], qs[1])
mem_swap(qs[0], qs[1])
state_result("RESULT", qs)
discard_array(qs)
instance = build(main.compile())
seeded_stim_instance = Stim(random_seed=seed)
output = instance.run(simulator=seeded_stim_instance, n_qubits=2)
states_dict = seeded_stim_instance.extract_states_dict(output)
stab_list = states_dict["RESULT"].get_reduced_stabilizers()
print(stab_list) # print out the tableau
If I do the swap with mem_swap, I get...
However if I comment out mem_swap and instead use swap_with_cx, I get
Unless I'm missing something,
mem_swapshould have the same semantics as "A swap performed with three cnots". I've found an example for which this does not seem to be the case.If I do the swap with
mem_swap, I get...However if I comment out
mem_swapand instead useswap_with_cx, I get