quasim


Namequasim JSON
Version 0.2.1 PyPI version JSON
download
home_pageNone
SummaryEfficient simulation of quantum computing circuits.
upload_time2024-07-15 14:58:25
maintainerNone
docs_urlNone
authorChristoph Stein
requires_python>=3.9
licenseThe MIT License (MIT) Copyright © 2024 Christoph Stein Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords quantum quantum computing quantum computing simulator simulation simulator quantum circuit simulator quantum circuit
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # QuaSim: Qua(ntum Simulation made) Sim(ple)

[QuaSim](https://github.com/westoun/quasim) is a Python library for
simulating quantum circuits. It was created partly as a learning project,
partly out of necessity.
For my master thesis, I required a quantum circuit simulator that was easy
to set up, had low overhead, and was comparatively faster than [Qiskit](https://www.ibm.com/quantum/qiskit)
on the amount of qubits that my experiments required.

| qubit_num\simulator | qiskit 0.45.1 | quasim 0.1.0 | quasim 0.2.0 |
| :-----------------: | -------------:| ------------:| ------------:|
| 3                   | 15.06s        | 3.15s        | 2.71s        | 
| 4                   | 15.20s        | 4.43s        | 3.83s        | 
| 5                   | 15.06s        | 5.03s        | 3.76s        | 
| 6                   | 14.16s        | 7.76s        | 4.69s        | 
| 7                   | 14.36s        | 13.60s       | 6.32s        | 
| 8                   | 15.28s        | 30.61s       | 8.75s        | 


**Table 1:** Execution time on 1000 randomly generated circuits with 40 gates each.

Aside from a low degree of overhead and dependencies (numpy only), QuaSim's speed gain
comes down to the way it detects and handles entanglement, since entanglement is the
reason why quantum circuits experience exponential resource growth when simulated
on classical computers.

Unless a qubit has been entangled with other qubits through the use of a controlled gate,
QuaSim stores and evolves its state independently from all other qubits.
Once two qubits become entangled, they form a joined qubit group, which is then stored and
evolved independently from the remaining qubits in the system.
Joined states are only used when they cannot be avoided.
At each time step, a completely unentangled circuit would only need to keep
track of N qubit states, instead of $2^N$ state combinations and, hence, would
only require gate matrices of dimension $2\times2$ instead of $2^N\times2^N$.

For a more foundational introduction to the mathematics and intuition of quantum
circuit simulation, I recommend [Aws Albarghouthi's](https://pages.cs.wisc.edu/~aws/)
great article ["A Quantum Circuit Simulator in 27 Lines of Python"](https://barghouthi.github.io/2021/08/05/quantum/).

## Installation

Use the package manager [pip](https://pip.pypa.io/en/stable/) to install quasim.

```bash
pip install quasim
```

## Usage

```python
from quasim import QuaSim, Circuit
from quasim.gates import H, CX, X

circuit = Circuit(2)
circuit.apply(H(target_qubit=0))
circuit.apply(CX(control_qubit=0, target_qubit=1))

simulator = QuaSim()
simulator.evaluate_circuit(circuit)

print(circuit.state)
print(circuit.probabilities)
print(circuit.probability_dict)
```

## Benchmarking

The benchmarking folder contains code that compares the performance of
QuaSim to [Qiskit](https://www.ibm.com/quantum/qiskit), a popular framework
in the context of quantum computing.
It compares both approaches in terms of execution time and simulation results.
Before executing any of the scripts,
make sure you have all the required requirements installed as specified in
benchmark/requirements.txt.

## Contributing

Pull requests are welcome. For major changes, please open an issue first
to discuss what you would like to change.

## License

[MIT](https://choosealicense.com/licenses/mit/)

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "quasim",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "quantum, quantum computing, quantum computing simulator, simulation, simulator, quantum circuit simulator, quantum circuit",
    "author": "Christoph Stein",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/d3/cc/c284d6e63bfbac2dda175f46d930bb826f501562eddb168dcef554600963/quasim-0.2.1.tar.gz",
    "platform": null,
    "description": "# QuaSim: Qua(ntum Simulation made) Sim(ple)\n\n[QuaSim](https://github.com/westoun/quasim) is a Python library for\nsimulating quantum circuits. It was created partly as a learning project,\npartly out of necessity.\nFor my master thesis, I required a quantum circuit simulator that was easy\nto set up, had low overhead, and was comparatively faster than [Qiskit](https://www.ibm.com/quantum/qiskit)\non the amount of qubits that my experiments required.\n\n| qubit_num\\simulator | qiskit 0.45.1 | quasim 0.1.0 | quasim 0.2.0 |\n| :-----------------: | -------------:| ------------:| ------------:|\n| 3                   | 15.06s        | 3.15s        | 2.71s        | \n| 4                   | 15.20s        | 4.43s        | 3.83s        | \n| 5                   | 15.06s        | 5.03s        | 3.76s        | \n| 6                   | 14.16s        | 7.76s        | 4.69s        | \n| 7                   | 14.36s        | 13.60s       | 6.32s        | \n| 8                   | 15.28s        | 30.61s       | 8.75s        | \n\n\n**Table 1:** Execution time on 1000 randomly generated circuits with 40 gates each.\n\nAside from a low degree of overhead and dependencies (numpy only), QuaSim's speed gain\ncomes down to the way it detects and handles entanglement, since entanglement is the\nreason why quantum circuits experience exponential resource growth when simulated\non classical computers.\n\nUnless a qubit has been entangled with other qubits through the use of a controlled gate,\nQuaSim stores and evolves its state independently from all other qubits.\nOnce two qubits become entangled, they form a joined qubit group, which is then stored and\nevolved independently from the remaining qubits in the system.\nJoined states are only used when they cannot be avoided.\nAt each time step, a completely unentangled circuit would only need to keep\ntrack of N qubit states, instead of $2^N$ state combinations and, hence, would\nonly require gate matrices of dimension $2\\times2$ instead of $2^N\\times2^N$.\n\nFor a more foundational introduction to the mathematics and intuition of quantum\ncircuit simulation, I recommend [Aws Albarghouthi's](https://pages.cs.wisc.edu/~aws/)\ngreat article [\"A Quantum Circuit Simulator in 27 Lines of Python\"](https://barghouthi.github.io/2021/08/05/quantum/).\n\n## Installation\n\nUse the package manager [pip](https://pip.pypa.io/en/stable/) to install quasim.\n\n```bash\npip install quasim\n```\n\n## Usage\n\n```python\nfrom quasim import QuaSim, Circuit\nfrom quasim.gates import H, CX, X\n\ncircuit = Circuit(2)\ncircuit.apply(H(target_qubit=0))\ncircuit.apply(CX(control_qubit=0, target_qubit=1))\n\nsimulator = QuaSim()\nsimulator.evaluate_circuit(circuit)\n\nprint(circuit.state)\nprint(circuit.probabilities)\nprint(circuit.probability_dict)\n```\n\n## Benchmarking\n\nThe benchmarking folder contains code that compares the performance of\nQuaSim to [Qiskit](https://www.ibm.com/quantum/qiskit), a popular framework\nin the context of quantum computing.\nIt compares both approaches in terms of execution time and simulation results.\nBefore executing any of the scripts,\nmake sure you have all the required requirements installed as specified in\nbenchmark/requirements.txt.\n\n## Contributing\n\nPull requests are welcome. For major changes, please open an issue first\nto discuss what you would like to change.\n\n## License\n\n[MIT](https://choosealicense.com/licenses/mit/)\n",
    "bugtrack_url": null,
    "license": "The MIT License (MIT) Copyright \u00a9 2024 Christoph Stein  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \u201cSoftware\u201d), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \u201cAS IS\u201d, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "Efficient simulation of quantum computing circuits.",
    "version": "0.2.1",
    "project_urls": {
        "Homepage": "https://github.com/westoun/quasim",
        "Issues": "https://github.com/westoun/quasim/issues"
    },
    "split_keywords": [
        "quantum",
        " quantum computing",
        " quantum computing simulator",
        " simulation",
        " simulator",
        " quantum circuit simulator",
        " quantum circuit"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "043b307a128defa26bff5dfd955c7a5f9e725ca270955cf4574744e0e4045f5a",
                "md5": "a742e34b13f3b2151378b90238eb861a",
                "sha256": "31eebdca9597800ccffbedb274264aa66d9af8da34b8b1d5f9beb818ddb7bde0"
            },
            "downloads": -1,
            "filename": "quasim-0.2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a742e34b13f3b2151378b90238eb861a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 14466,
            "upload_time": "2024-07-15T14:57:18",
            "upload_time_iso_8601": "2024-07-15T14:57:18.375282Z",
            "url": "https://files.pythonhosted.org/packages/04/3b/307a128defa26bff5dfd955c7a5f9e725ca270955cf4574744e0e4045f5a/quasim-0.2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d3ccc284d6e63bfbac2dda175f46d930bb826f501562eddb168dcef554600963",
                "md5": "58efb9e324fb1ba0608b6d41b264fde7",
                "sha256": "0f2823e94c4564af01f02af31dd05594b73e576e960ab9e69bcce9043fad9e9a"
            },
            "downloads": -1,
            "filename": "quasim-0.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "58efb9e324fb1ba0608b6d41b264fde7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 12926,
            "upload_time": "2024-07-15T14:58:25",
            "upload_time_iso_8601": "2024-07-15T14:58:25.142201Z",
            "url": "https://files.pythonhosted.org/packages/d3/cc/c284d6e63bfbac2dda175f46d930bb826f501562eddb168dcef554600963/quasim-0.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-15 14:58:25",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "westoun",
    "github_project": "quasim",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "quasim"
}
        
Elapsed time: 0.58331s