Skip to content

Seemingly incorrect semantics given when using mem_swap with state_result in Stim simulation #182

@CalMacCQ

Description

@CalMacCQ

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

+_Z
+X_

However if I comment out mem_swap and instead use swap_with_cx, I get

+X_
+_Z

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions