Skip to content

Non-deterministic behaviour with fixed seed #89

@cqc-alec

Description

@cqc-alec

Version: 0.6.0.dev6

The following code uses an error model to simulate a Bell circuit, with a fixed seed. It gives non-deterministic results.

from pecos.error_models.generic_error_model import GenericErrorModel
from pecos.engines.hybrid_engine import HybridEngine

phir = """{
    "format": "PHIR/JSON",
    "version": "0.1.0",
    "ops":
    [
        {
            "data": "qvar_define",
            "data_type": "qubits",
            "variable": "q",
            "size": 2
        },
        {
            "data": "cvar_define",
            "data_type": "i64",
            "variable": "c",
            "size": 2
        },
        {
            "qop": "H",
            "angles": null,
            "args":
            [
                [
                    "q",
                    0
                ]
            ]
        },
        {
            "qop": "CX",
            "angles": null,
            "args":
            [
                [
                    [
                        "q",
                        0
                    ],
                    [
                        "q",
                        1
                    ]
                ]
            ]
        },
        {
            "qop": "Measure",
            "returns":
            [
                [
                    "c",
                    0
                ]
            ],
            "args":
            [
                [
                    "q",
                    0
                ]
            ]
        },
        {
            "qop": "Measure",
            "returns":
            [
                [
                    "c",
                    1
                ]
            ],
            "args":
            [
                [
                    "q",
                    1
                ]
            ]
        }
    ]
}
"""

error_model = GenericErrorModel(
    error_params={
        "p1": 2e-1,
        "p2": 2e-1,
        "p_meas": 2e-1,
        "p_init": 1e-1,
        "p1_error_model": {
            "X": 0.25,
            "Y": 0.25,
            "Z": 0.25,
            "L": 0.25,
        },
    },
)
engine = HybridEngine(error_model=error_model)
engine.use_seed(7)
results = engine.run(phir, shots=100)
print(sum(x == "11" for x in results["c"]))

May output 24, 25, 26, 27 etc.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions