{"id":28637342,"url":"https://github.com/strilanc/python-chp-stabilizer-simulator","last_synced_at":"2026-03-15T23:04:31.536Z","repository":{"id":62562091,"uuid":"188953326","full_name":"Strilanc/python-chp-stabilizer-simulator","owner":"Strilanc","description":"Simple python implementation of Scott Aaronson et al's CHP simulator.","archived":false,"fork":false,"pushed_at":"2019-07-03T22:05:08.000Z","size":20,"stargazers_count":19,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-22T05:46:40.166Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Strilanc.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-05-28T04:23:25.000Z","updated_at":"2024-12-03T08:16:48.000Z","dependencies_parsed_at":"2022-11-03T15:30:48.308Z","dependency_job_id":null,"html_url":"https://github.com/Strilanc/python-chp-stabilizer-simulator","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/Strilanc/python-chp-stabilizer-simulator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Strilanc%2Fpython-chp-stabilizer-simulator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Strilanc%2Fpython-chp-stabilizer-simulator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Strilanc%2Fpython-chp-stabilizer-simulator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Strilanc%2Fpython-chp-stabilizer-simulator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Strilanc","download_url":"https://codeload.github.com/Strilanc/python-chp-stabilizer-simulator/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Strilanc%2Fpython-chp-stabilizer-simulator/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259518828,"owners_count":22870304,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-12T18:10:33.377Z","updated_at":"2026-03-15T23:04:26.492Z","avatar_url":"https://github.com/Strilanc.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"Python CHP Stabilizer Simulator\n-------------------------------\n\nA simple reference python implementation of Scott Aaronson and Daniel Gottesman's CHP simulator\nas defined in\n`their 2004 paper \"Improved Simulation of Stabilizer Circuits\" \u003chttps://arxiv.org/abs/quant-ph/0406196\u003e`__.\nThis simulator is capable of simulating quantum stabilizer circuits in polynomial time and space.\nSpecifically, it uses ``O(q^2*m + q*c)`` time and ``O(q^2)`` space where\n``q`` is the number of qubits,\n``m`` is the number of measurements,\nand ``c`` is the number of Hadamard/CNOT/Phase gates.\n\nInstallation\n------------\n\nThe ``chp_sim`` package is available on pypi and can be installed using ``pip``:\n\n.. code-block:: bash\n\n    python -m pip install chp_sim\n\nAlternatively, you can just copy paste the ``chp_sim`` directory of the github\nrepository into your project.\nThe only runtime dependency is ``numpy``.\n\nUsage\n-----\n\nHere is an example of simulating\n`a circuit \u003chttps://algassert.com/quirk#circuit=%7B%22cols%22%3A%5B%5B1%2C1%2C%22H%22%5D%2C%5B%22X%22%2C1%2C%22%E2%80%A2%22%5D%2C%5B1%2C%22X%22%2C%22%E2%80%A2%22%5D%2C%5B%22Z%5E%C2%BD%22%2C%22Z%5E%C2%BD%22%5D%2C%5B%22H%22%2C%22H%22%2C%22H%22%5D%2C%5B%22Measure%22%2C%22Measure%22%2C%22Measure%22%5D%2C%5B%22Chance3%22%5D%5D%7D\u003e`__:\n\n.. code-block:: python\n\n    import chp_sim\n    sim = chp_sim.ChpSimulator(num_qubits=3)\n\n    # Desired circuit:\n    # 0: -------X-------S---H---M---\n    #           |\n    # 1: -------|---X---S---H---M---\n    #           |   |\n    # 2: ---H---@---@-------H---M---\n\n    sim.hadamard(2)\n    sim.cnot(2, 0)\n    sim.cnot(2, 1)\n    sim.phase(0)\n    sim.phase(1)\n    sim.hadamard(0)\n    sim.hadamard(1)\n    sim.hadamard(2)\n\n    # Show internal simulator state.\n    print(sim, '\\n')\n    # prints:\n    #   -Y..\n    #   -.Y.\n    #   +..X\n    #   ----\n    #   +X.X\n    #   +.XX\n    #   +YYZ\n\n    # Perform measurements\n    v0 = sim.measure(0)\n    v1 = sim.measure(1)\n    v2 = sim.measure(2)\n    print(v0)\n    print(v1)\n    print(v2)\n    # prints [note: one of four possible results for this circuit]:\n    #   True (random)\n    #   False (random)\n    #   False (determined)\n\n    # Check pattern the outputs should satisfy.\n    assert not v0.determined\n    assert not v1.determined\n    assert v2.determined\n    assert bool(v0) ^ bool(v1) ^ bool(v2)\n\n\nPackaging\n---------\n\n(Notes to self on how to release a new version.)\n\n1. Edit the source code as needed and run tests.\n\n    .. code-block:: bash\n\n        pytest\n\n2. Build the wheel.\n\n    .. code-block:: bash\n\n        python3 setup.py -q bdist_wheel\n        ls dist\n\n3. Upload to test pypi.\n\n    .. code-block:: bash\n\n        twine upload dist/*.whl --repository-url=https://test.pypi.org/legacy/ --username=\"${TEST_TWINE_USERNAME}\" --password=\"${TEST_TWINE_PASSWORD}\"\n\n4. Verify the test package works.\n\n    .. code-block:: bash\n\n        mkvirtualenv test --python=/usr/bin/python3\n        pip install numpy\n        pip install chp_sim --index-url=https://test.pypi.org/simple/\n        python -c \"import chp_sim; print(chp_sim.__version__); print(chp_sim.ChpSimulator(4))\"\n\n5. Upload to prod pypi.\n\n    .. code-block:: bash\n\n        twine upload dist/*.whl --username=\"${PROD_TWINE_USERNAME}\" --password=\"${PROD_TWINE_PASSWORD}\"\n\n6. Verify the prod package works.\n\n    .. code-block:: bash\n\n        mkvirtualenv test --python=/usr/bin/python3\n        pip install chp_sim\n        python -c \"import chp_sim; print(chp_sim.__version__); print(chp_sim.ChpSimulator(4))\"\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstrilanc%2Fpython-chp-stabilizer-simulator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstrilanc%2Fpython-chp-stabilizer-simulator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstrilanc%2Fpython-chp-stabilizer-simulator/lists"}