Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect simulation of circuit containing initial conditional R1XY #81

Open
cqc-alec opened this issue Oct 2, 2024 · 1 comment
Open
Labels
bug Something isn't working

Comments

@cqc-alec
Copy link

cqc-alec commented Oct 2, 2024

The PHIR pasted below expresses the following logic:

  1. Initialize one qubit register "q", classical registers "a" and "t", all of size 1.
  2. If t[0] == 0, apply R1XY(0.6366197723675814*pi, 0) to q[0].
  3. Apply R1XY(3.3633802276324185*pi, 0) to q[0].
  4. Measure q[0] to a[0].

Since t[0] == 0 initially, and 0.6366197723675814 + 3.3633802276324185 = 4, both R1XY gates should be applied and should cancel, so the final measurement in a[0] should be zero.

However, when run 100 times with the statevector simulator the result is a mixture of 0s and 1s.

The angles used here are (in radians) 2 and 4*pi - 2. When 1.9 and 4*pi - 1.9 are used, the results are as expected (all zero).

from pecos.engines.hybrid_engine import HybridEngine

def test():
    phir = """
{
    "format": "PHIR/JSON",
    "version": "0.1.0",
    "metadata":
    {
        "source": "pytket-phir v0.8.1"
    },
    "ops":
    [
        {
            "data": "qvar_define",
            "data_type": "qubits",
            "variable": "q",
            "size": 1
        },
        {
            "data": "cvar_define",
            "data_type": "i64",
            "variable": "a",
            "size": 1
        },
        {
            "data": "cvar_define",
            "data_type": "i64",
            "variable": "t",
            "size": 1
        },
        {
            "block": "if",
            "condition":
            {
                "cop": "==",
                "args":
                [
                    [
                        "t",
                        0
                    ],
                    0
                ]
            },
            "true_branch":
            [
                {
                    "qop": "R1XY",
                    "angles":
                    [
                        [
                            0.6366197723675814,
                            0.0
                        ],
                        "pi"
                    ],
                    "args":
                    [
                        [
                            "q",
                            0
                        ]
                    ]
                }
            ]
        },
        {
            "qop": "R1XY",
            "angles":
            [
                [
                    3.3633802276324185,
                    0.0
                ],
                "pi"
            ],
            "args":
            [
                [
                    "q",
                    0
                ]
            ]
        },
        {
            "qop": "Measure",
            "returns":
            [
                [
                    "a",
                    0
                ]
            ],
            "args":
            [
                [
                    "q",
                    0
                ]
            ]
        }
    ]
}
"""
    engine = HybridEngine(qsim="state-vector")
    results = engine.run(phir, shots=100)
    print(results)
@ciaranra ciaranra added the bug Something isn't working label Oct 7, 2024
@erinaldiq
Copy link

Can this be looked at?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants