{"id":22882510,"url":"https://github.com/cqcl/simplex","last_synced_at":"2025-05-07T04:48:29.510Z","repository":{"id":62583486,"uuid":"437048091","full_name":"CQCL/simplex","owner":"CQCL","description":"A fast simulator for Clifford circuits","archived":false,"fork":false,"pushed_at":"2024-01-15T10:50:10.000Z","size":88,"stargazers_count":5,"open_issues_count":2,"forks_count":1,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-05-07T04:48:23.029Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C++","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/CQCL.png","metadata":{"files":{"readme":"README.md","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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2021-12-10T16:44:13.000Z","updated_at":"2025-02-19T02:08:55.000Z","dependencies_parsed_at":"2024-01-15T12:46:56.867Z","dependency_job_id":null,"html_url":"https://github.com/CQCL/simplex","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CQCL%2Fsimplex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CQCL%2Fsimplex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CQCL%2Fsimplex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CQCL%2Fsimplex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CQCL","download_url":"https://codeload.github.com/CQCL/simplex/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252816523,"owners_count":21808702,"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":"2024-12-13T18:18:02.916Z","updated_at":"2025-05-07T04:48:29.486Z","avatar_url":"https://github.com/CQCL.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Simplex\n\nThis software implements the methods described in [BH21][1] for simulating\nClifford circuits.\n\n## Reference implementation\n\nA reference implementation in Python is in the `reference` directory. The\nimplementation is in `simplex.py`. It requires `numpy` and `bidict`:\n\n```shell\npip install numpy bidict\n```\n\nTo run the unit tests:\n\n```shell\ncd reference\n./test-simplex\n```\n\nThere is an option to perform some additional internal state validation during\ntesting:\n\n```shell\ncd reference\n./test-simplex --validate\n```\n\nHowever, this requires that `sagemath` be installed on your system and that sage\nscripts be executable with `/usr/bin/python`. (It uses sage for a matrix rank\ncomputation.) It also slows down the tests considerably.\n\n### API\n\nThe main class is the `Simplex` class, defined and documented in `simplex.py`.\nExample usage:\n\n```python\nfrom simplex import Simplex\nS = Simplex(2) # 2 qubits, initially in the all-zero state\nS.H(0) # apply a Hadamard on qubit 0\nS.CX(0,1) # apply a CNOT between qubits 0 and 1\nb0 = S.MeasZ(0) # measure qubit 0 in the Z basis, return 0 or 1\nb1 = S.MeasZ(1) # measure qubit 1 in the Z basis, return 0 or 1\nassert b0 == b1 # it's a Bell state\nassert not S.is_deterministic() # at least one non-deterministic measurement has been performed\n```\n\nBy default, non-deterministic measurements use a PRNG to decide the result.\nHowever, for reproduciblility and testing you may specify \"coins\" by passing an\nextra argument to the measure  operation. For example:\n\n```python\nb0 = S.MeasZ(0, coin=0)\nassert b0 == 0\n```\n\nNote that `is_deterministic()` will still return `False` regardless of whether a\ncoin was actually specified.\n\n## C++ implementation\n\nThe C++ implementation is in the `simplex` directory. It is built using `cmake`. To build the library and the unit tests:\n\n```shell\ncd simplex\nmkdir build\ncd build\ncmake ..\ncmake --build .\n```\n\nThen to run the tests:\n\n```shell\n./test/simplex-test\n```\n\n### Optimization for sparsity\n\nThere are two implementations, one (the default) optimized for sparse circuits\n(and hence sparse matrices), the other not. If you are working with dense\ncircuits, then the dense-matrix-based implementation may be faster. To build\nthis, simply set the `SIMPLEX_DENSE` option when running `cmake`. From the\n`build` directory:\n\n```shell\nrm -f CMakeCache.txt\ncmake .. -DSIMPLEX_DENSE=ON\ncmake --build .\n```\n\n### API\n\nThe C++ API is similar to the API of the Python reference implementation.\n\n```cpp\n#include \u003csimplex.hpp\u003e\n\nSimplex S(2);\nS.H(0);\nS.CX(0, 1);\n```\n\nMeasurements return integer values 0 or 1. There is also the same optional\nargument to the measure operations for specifying coins:\n\n```cpp\nint b0 = S.MeasY(0, 1); // b0 will be 1\nint b1 = S.MeasZ(1);\n```\n\nThe internal state can be viewed by means of the `operator\u003c\u003c` method:\n\n```cpp\n#include \u003ciostream\u003e\n// ...\nstd::cout \u003c\u003c S;\n```\n\nThis will print out the matrices _A_ and _Q_, the vector _b_, and the mapping\n_p_ as described in [BH21][1].\n\n## Python module\n\nThe C++ implementation is wrapped in a Python module, `pysimplex`. The binding\ncode is in the `simplex/pysimplex` directory. To build and install this module:\n\n```shell\ncd simplex\npip install .\n```\n\nThe API is similar to that of the reference and C++ implementations. For\nexample:\n\n```python\nfrom pysimplex import Simplex\nS = Simplex(3)\nS.H(0).CX(0, 1).CX(1, 2)\nprint(S.MeasZ(0))\nprint(S.MeasZ(1))\n```\n\nTo see the internal state, use `print(S)`.\n\n### Initialization from Stim files\n\nIt is possible to initialize a `Simplex` from a file in [Stim format](https://github.com/quantumlib/Stim/blob/main/doc/file_format_stim_circuit.md) by\npassing a file path and (optionally) an integer seed. For example:\n\n```python\nS = Simplex(\"./test-circuits/random_circuit_64.stim\", seed=1)\n```\n\nMost but not all Stim instructions are supported. There is little leniency in\nthe parser.\n\n### Installation from pypi\n\nTo install the current stable version from pypi, simply:\n\n```shell\npip install pysimplex\n```\n\nThe package is available for Linux, MacOS and Windows, and for Python versions\n3.10, 3.11 and 3.12.\n\n[1]: https://arxiv.org/abs/2109.08629\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcqcl%2Fsimplex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcqcl%2Fsimplex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcqcl%2Fsimplex/lists"}