# Start
The QuaLeSim(Quantum Lego Simulator) is an adapted version of DQCSim. For quantum circuit simulation, you can simulate QUIET-s and QCIS instruction by it.
And what's more, now the QuaLeSim is integrated into the backend of Quingo, you can use it directly after installing quingoc and quingo-runtime. More inforemations is available in [[#Install]]
# Install
> The QuaLeSim now is only for Linux platform.
1. 环境准备:
- Linux platform with `python>=3.7`
- Rust # if you don't have rust, make sure you have `'curl'` to install rust in the setup.py .
2. 安装说明:
- 目前已经将 qualesim 及其相关插件上传至 PYPI,可以选择下面两种方式安装:
1. 一键安装qualesim 及其相关插件:
- `pip install qualesim[TEQUILA]`
- 注:tequila目前尚未开源,tequila不会默认安装。
- 若需要使用Tequila模拟器,可以在`qualesim`之后加`[TEQUILA]`来安装
2. 单独安装各个模块插件:
- `pip install qualesim` # 安装qualesim本体
- `pip install qualesim-tequila` # 安装 tequila 后端,tequila尚未开源,需要单独安装
# Quick Start
Quick Start is for users use the Simulator directly or use it with quingo-runtime. Some examples are available below.
1. For independent users:
- The Simulator can simulate QUIET-s and QCIS instructions, you can use it directly:
```python
from qualesim.plugin import *
from qualesim.host import *
sim = Simulator(stderr_verbosity=Loglevel.INFO)
sim.with_frontend("<path-to-qcis-file>", verbosity=Loglevel.INFO)
# sim.with_frontend("<path-to-qi-file>", verbosity=Loglevel.INFO)
# Loglevel is for output information for DEBUG/INFO/OFF
# If you only want the simulation output, please set it OFF
sim.with_backend("quantumsim", verbosity=Loglevel.INFO)
# sim.with_backend("tequila", verbosity=Loglevel.INFO)
# now we have DQCsim-Tequila and DQCsim-QuantumSim backend for Simulator
sim.simulate()
res = sim.run(measure_mod="state_vector", num_shots=10)
# Start the simulation with different exe mod,
# measure_mod="one_shot" and num_shots=int /
# "state_vector"
# the output should be
sim.stop()
final_state = dict()
final_state = res["res"]
print(final_state)
```
- the output is :
```python
measure_mod="state_vector":
res1(M Q1, M Q2) = {'classical': {'Q1': 1, 'Q2': 1}, 'quantum': (['Q3'], [0j, (1+0j)])}
# classical is qubit measured, quantum is qubit unmeasured with state vector.
res2() = {'classical': {}, 'quantum': (['Q1', 'Q2', 'Q3'], [(0.7071067811865472+0j), 0j, 0j, 0j, 0j, 0j, 0j, (0.7071067811865478+0j)])}
measure_mod="one_shot", num_shots=10:
# classical is classical value, quantum is qubit measured. and they are one to one correspondence
res(measure(q1)->c1, measure(q2)->c2) = {'quantum': [['q1', 'q2'], [[0, 0], [0, 0], [1, 1], [0, 0], [0, 0], [1, 1], [0, 0], [0, 0], [1, 1], [1, 1]]], 'classical': [{'c1': [0], 'c2': [0]}, {'c1': [0], 'c2': [0]}, {'c1': [1], 'c2': [1]}, {'c1': [0], 'c2': [0]}, {'c1': [0], 'c2': [0]}, {'c1': [1], 'c2': [1]}, {'c1': [0], 'c2': [0]}, {'c1': [0], 'c2': [0]}, {'c1': [1], 'c2': [1]}, {'c1': [1], 'c2': [1]}]}
```
2. For Quingo Users
- You should follow the [[#Install|extern: quingoc & quingo-runtime installation]] to install it.
```python
from quingo import *
import qututor.global_config as gc
from quingo.backend.qisa import Qisa
# input quingo file and simulate qu func
qu_file = gc.quingo_dir / "ghz.qu"
circ_name = "GHZ_state"
# set the qisa, and it is the output instructions QUIET,
# you can change to Qisa.QCIS or others.
task = Quingo_task(
qu_file,
circ_name,
qisa=Qisa.QUIET,
)
num_shots = 10
cfg = ExeConfig(ExeMode.SimFinalResult, num_shots)
num_qubits = 3
# now backend BackendType.QUANTUM_SIM, BackendType.DQCSIM_TEQUILA
# BackendType.DQCSIM_QUANTUMSIM, BackendType.SYMQC is available.
# method 1
qasm_fn = compile(task, params=(num_qubits,))
res = execute(qasm_fn, BackendType.QUANTUM_SIM, cfg)
# method 2
# res = call(task, (num_qubits,), BackendType.DQCSIM_TEQUILA, cfg)
print("res: ", res)
```
- the output is :
```python
measure_mod="state_vector":
res1(M Q1, M Q2) = {'classical': {'Q1': 1, 'Q2': 1}, 'quantum': (['Q3'], [0j, (1+0j)])}
# classical is qubit measured, quantum is qubit unmeasured with state vector.
res2() = {'classical': {}, 'quantum': (['Q1', 'Q2', 'Q3'], [(0.7071067811865472+0j), 0j, 0j, 0j, 0j, 0j, 0j, (0.7071067811865478+0j)])}
measure_mod="one_shot", num_shots=10:
# quingo-runtime only have quantum values.
res(measure(q1)->c1, measure(q2)->c2) =(['q1', 'q2'], [[0, 0], [0, 0], [1, 1], [0, 0], [0, 0], [1, 1], [0, 0], [0, 0], [1, 1], [1, 1]])
```
# FAQ
1. for install
1. your environment donot have rust?
- you can install rust yourself by the [Rust 程序设计语言 (rust-lang.org)](https://www.rust-lang.org/zh-CN/)
- or just make sure you have command `"curl"`, the setup will help you install it automatic.
2. if you have llvm in your platform, the setup install maybe very slow.
- the problem is to be solved.
3. install about quingoc
- please refer to [docs/DeveloperGuide.md · Quingo/quingo-compiler - Gitee.com](https://gitee.com/quingo/quingo-compiler/blob/enh/I7U2U5/refactor_frontend/docs/DeveloperGuide.md)
2. for use
1. when you first use it, there would be a problem `核心已转储`
- it is the dqcsim's problem and is to be solved.
Raw data
{
"_id": null,
"home_page": "https://gitee.com/quingo/qualesim.git",
"name": "qualesim",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": null,
"author": "Dingdong Liu",
"author_email": "dingdongliu@quanta.org.cn",
"download_url": null,
"platform": "linux",
"description": "# Start\nThe QuaLeSim(Quantum Lego Simulator) is an adapted version of DQCSim. For quantum circuit simulation, you can simulate QUIET-s and QCIS instruction by it.\nAnd what's more, now the QuaLeSim is integrated into the backend of Quingo, you can use it directly after installing quingoc and quingo-runtime. More inforemations is available in [[#Install]]\n\n# Install\n> The QuaLeSim now is only for Linux platform.\n\n1. \u73af\u5883\u51c6\u5907\uff1a\n\t- Linux platform with `python>=3.7`\n\t- Rust # if you don't have rust, make sure you have `'curl'` to install rust in the setup.py .\n2. \u5b89\u88c5\u8bf4\u660e\uff1a\n\t- \u76ee\u524d\u5df2\u7ecf\u5c06 qualesim \u53ca\u5176\u76f8\u5173\u63d2\u4ef6\u4e0a\u4f20\u81f3 PYPI\uff0c\u53ef\u4ee5\u9009\u62e9\u4e0b\u9762\u4e24\u79cd\u65b9\u5f0f\u5b89\u88c5\uff1a\n\t1. \u4e00\u952e\u5b89\u88c5qualesim \u53ca\u5176\u76f8\u5173\u63d2\u4ef6\uff1a\n\t\t- `pip install qualesim[TEQUILA]`\n\t\t- \u6ce8\uff1atequila\u76ee\u524d\u5c1a\u672a\u5f00\u6e90\uff0ctequila\u4e0d\u4f1a\u9ed8\u8ba4\u5b89\u88c5\u3002\n \t\t- \u82e5\u9700\u8981\u4f7f\u7528Tequila\u6a21\u62df\u5668\uff0c\u53ef\u4ee5\u5728`qualesim`\u4e4b\u540e\u52a0`[TEQUILA]`\u6765\u5b89\u88c5\n\t2. \u5355\u72ec\u5b89\u88c5\u5404\u4e2a\u6a21\u5757\u63d2\u4ef6\uff1a\n\t\t- `pip install qualesim` # \u5b89\u88c5qualesim\u672c\u4f53\n\t\t- `pip install qualesim-tequila` # \u5b89\u88c5 tequila \u540e\u7aef\uff0ctequila\u5c1a\u672a\u5f00\u6e90\uff0c\u9700\u8981\u5355\u72ec\u5b89\u88c5\n\n# Quick Start\nQuick Start is for users use the Simulator directly or use it with quingo-runtime. Some examples are available below.\n\n1. For independent users:\n\t- The Simulator can simulate QUIET-s and QCIS instructions, you can use it directly:\n\n```python\nfrom qualesim.plugin import *\nfrom qualesim.host import *\nsim = Simulator(stderr_verbosity=Loglevel.INFO)\n\nsim.with_frontend(\"<path-to-qcis-file>\", verbosity=Loglevel.INFO)\n# sim.with_frontend(\"<path-to-qi-file>\", verbosity=Loglevel.INFO)\n# Loglevel is for output information for DEBUG/INFO/OFF\n# If you only want the simulation output, please set it OFF\n\nsim.with_backend(\"quantumsim\", verbosity=Loglevel.INFO)\n# sim.with_backend(\"tequila\", verbosity=Loglevel.INFO)\n# now we have DQCsim-Tequila and DQCsim-QuantumSim backend for Simulator\n\nsim.simulate()\nres = sim.run(measure_mod=\"state_vector\", num_shots=10)\n# Start the simulation with different exe mod,\n# measure_mod=\"one_shot\" and num_shots=int /\n# \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \"state_vector\"\n# the output should be\n\nsim.stop()\nfinal_state = dict()\nfinal_state = res[\"res\"]\nprint(final_state)\n```\n- the output is :\n```python\nmeasure_mod=\"state_vector\":\nres1(M Q1, M Q2) = {'classical': {'Q1': 1, 'Q2': 1}, 'quantum': (['Q3'], [0j, (1+0j)])}\n# classical is qubit measured, quantum is qubit unmeasured with state vector.\nres2() = {'classical': {}, 'quantum': (['Q1', 'Q2', 'Q3'], [(0.7071067811865472+0j), 0j, 0j, 0j, 0j, 0j, 0j, (0.7071067811865478+0j)])}\n\nmeasure_mod=\"one_shot\", num_shots=10:\n# classical is classical value, quantum is qubit measured. and they are one to one correspondence\nres(measure(q1)->c1, measure(q2)->c2) = {'quantum': [['q1', 'q2'], [[0, 0], [0, 0], [1, 1], [0, 0], [0, 0], [1, 1], [0, 0], [0, 0], [1, 1], [1, 1]]], 'classical': [{'c1': [0], 'c2': [0]}, {'c1': [0], 'c2': [0]}, {'c1': [1], 'c2': [1]}, {'c1': [0], 'c2': [0]}, {'c1': [0], 'c2': [0]}, {'c1': [1], 'c2': [1]}, {'c1': [0], 'c2': [0]}, {'c1': [0], 'c2': [0]}, {'c1': [1], 'c2': [1]}, {'c1': [1], 'c2': [1]}]}\n```\n\n\n2. For Quingo Users\n\t- You should follow the [[#Install|extern: quingoc & quingo-runtime installation]] to install it.\n```python\nfrom quingo import *\nimport qututor.global_config as gc\nfrom quingo.backend.qisa import Qisa\n\n# input quingo file and simulate qu func\nqu_file = gc.quingo_dir / \"ghz.qu\"\ncirc_name = \"GHZ_state\"\n\n# set the qisa, and it is the output instructions QUIET,\n# you can change to Qisa.QCIS or others.\ntask = Quingo_task(\n qu_file,\n circ_name,\n qisa=Qisa.QUIET,\n)\n\nnum_shots = 10\ncfg = ExeConfig(ExeMode.SimFinalResult, num_shots)\nnum_qubits = 3\n\n# now backend BackendType.QUANTUM_SIM, BackendType.DQCSIM_TEQUILA\n# BackendType.DQCSIM_QUANTUMSIM, BackendType.SYMQC is available.\n# method 1\nqasm_fn = compile(task, params=(num_qubits,))\nres = execute(qasm_fn, BackendType.QUANTUM_SIM, cfg)\n\n# method 2\n# res = call(task, (num_qubits,), BackendType.DQCSIM_TEQUILA, cfg)\n\nprint(\"res: \", res)\n```\n- the output is :\n```python\nmeasure_mod=\"state_vector\":\nres1(M Q1, M Q2) = {'classical': {'Q1': 1, 'Q2': 1}, 'quantum': (['Q3'], [0j, (1+0j)])}\n# classical is qubit measured, quantum is qubit unmeasured with state vector.\nres2() = {'classical': {}, 'quantum': (['Q1', 'Q2', 'Q3'], [(0.7071067811865472+0j), 0j, 0j, 0j, 0j, 0j, 0j, (0.7071067811865478+0j)])}\n\nmeasure_mod=\"one_shot\", num_shots=10:\n# quingo-runtime only have quantum values.\nres(measure(q1)->c1, measure(q2)->c2) =(['q1', 'q2'], [[0, 0], [0, 0], [1, 1], [0, 0], [0, 0], [1, 1], [0, 0], [0, 0], [1, 1], [1, 1]])\n```\n\n# FAQ\n1. for install\n\t1. your environment donot have rust?\n\t\t- you can install rust yourself by the [Rust \u7a0b\u5e8f\u8bbe\u8ba1\u8bed\u8a00 (rust-lang.org)](https://www.rust-lang.org/zh-CN/)\n\t\t- or just make sure you have command `\"curl\"`, the setup will help you install it automatic.\n\t2. if you have llvm in your platform, the setup install maybe very slow.\n\t\t- the problem is to be solved.\n\t3. install about quingoc\n\t\t- please refer to [docs/DeveloperGuide.md \u00b7 Quingo/quingo-compiler - Gitee.com](https://gitee.com/quingo/quingo-compiler/blob/enh/I7U2U5/refactor_frontend/docs/DeveloperGuide.md)\n2. for use\n\t1. when you first use it, there would be a problem `\u6838\u5fc3\u5df2\u8f6c\u50a8`\n\t\t- it is the dqcsim's problem and is to be solved.\n\n",
"bugtrack_url": null,
"license": "Apache-2.0",
"summary": "Quingo Simulator Backend QuaLeSim",
"version": "1.0.2",
"project_urls": {
"Bug Tracker": "https://gitee.com/quingo/qualesim.git",
"Documentation": "https://gitee.com/quingo/qualesim.git",
"Homepage": "https://gitee.com/quingo/qualesim.git",
"Source Code": "https://gitee.com/quingo/qualesim.git"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "1bd5062b2283b2def4ef7fe02e506576d48314ec7d15c6a561cea835c1f0daec",
"md5": "7c5fc8725fa42621e5d60e188a671937",
"sha256": "a4442e494481613ac8423f4e26e8dddf22d36c952bbef132b429eafd98307923"
},
"downloads": -1,
"filename": "qualesim-1.0.2-cp310-cp310-manylinux2014_x86_64.whl",
"has_sig": false,
"md5_digest": "7c5fc8725fa42621e5d60e188a671937",
"packagetype": "bdist_wheel",
"python_version": "cp310",
"requires_python": null,
"size": 11671810,
"upload_time": "2024-04-24T01:37:25",
"upload_time_iso_8601": "2024-04-24T01:37:25.332302Z",
"url": "https://files.pythonhosted.org/packages/1b/d5/062b2283b2def4ef7fe02e506576d48314ec7d15c6a561cea835c1f0daec/qualesim-1.0.2-cp310-cp310-manylinux2014_x86_64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "586a538c2b468a04e10ed5a20f81bd3c85418b6ceb7ee4f24a07f86c955665f7",
"md5": "057adcbe918fb9e3f05b55050a8abc26",
"sha256": "f4895b646b2cd207d3cf6dde5864ba63ffa597d5a93d0a2a65c08c297e04febe"
},
"downloads": -1,
"filename": "qualesim-1.0.2-cp311-cp311-manylinux2014_x86_64.whl",
"has_sig": false,
"md5_digest": "057adcbe918fb9e3f05b55050a8abc26",
"packagetype": "bdist_wheel",
"python_version": "cp311",
"requires_python": null,
"size": 11681435,
"upload_time": "2024-04-24T01:37:29",
"upload_time_iso_8601": "2024-04-24T01:37:29.741095Z",
"url": "https://files.pythonhosted.org/packages/58/6a/538c2b468a04e10ed5a20f81bd3c85418b6ceb7ee4f24a07f86c955665f7/qualesim-1.0.2-cp311-cp311-manylinux2014_x86_64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "dca1f33cf0c05bec99ad3fc7171533907180567080347f3c884dc44f6dae7c6d",
"md5": "04c541444d55ddd082c65b84ed199959",
"sha256": "d9e446c64d5241ff2c0dbb620902fb5489587ce14e63855fa28725cbffb22d9c"
},
"downloads": -1,
"filename": "qualesim-1.0.2-cp312-cp312-manylinux2014_x86_64.whl",
"has_sig": false,
"md5_digest": "04c541444d55ddd082c65b84ed199959",
"packagetype": "bdist_wheel",
"python_version": "cp312",
"requires_python": null,
"size": 11673104,
"upload_time": "2024-04-24T01:37:33",
"upload_time_iso_8601": "2024-04-24T01:37:33.208153Z",
"url": "https://files.pythonhosted.org/packages/dc/a1/f33cf0c05bec99ad3fc7171533907180567080347f3c884dc44f6dae7c6d/qualesim-1.0.2-cp312-cp312-manylinux2014_x86_64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "786228233c2f0c19ed2d7ac2f48c0f90db811cb228bae9a7ee0b0b102373b27a",
"md5": "d6a478adc22106dead2e4b7194341624",
"sha256": "82f70dd7285bcf292836993dc183499c71708161bfc573178e72f6d139cfa04f"
},
"downloads": -1,
"filename": "qualesim-1.0.2-cp37-cp37m-manylinux2014_x86_64.whl",
"has_sig": false,
"md5_digest": "d6a478adc22106dead2e4b7194341624",
"packagetype": "bdist_wheel",
"python_version": "cp37",
"requires_python": null,
"size": 11659558,
"upload_time": "2024-04-24T01:37:37",
"upload_time_iso_8601": "2024-04-24T01:37:37.167056Z",
"url": "https://files.pythonhosted.org/packages/78/62/28233c2f0c19ed2d7ac2f48c0f90db811cb228bae9a7ee0b0b102373b27a/qualesim-1.0.2-cp37-cp37m-manylinux2014_x86_64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "a69c5f4e09c830506277995577c215327f339642e79e258b01ab291e9a5755a4",
"md5": "81a97d29c96cf9f3d483a5bb451158d1",
"sha256": "bd06e0c8bdb64aaedb9f1829af9c615c29ede51b2982c0c416eae47d75c01f2b"
},
"downloads": -1,
"filename": "qualesim-1.0.2-cp38-cp38-manylinux2014_x86_64.whl",
"has_sig": false,
"md5_digest": "81a97d29c96cf9f3d483a5bb451158d1",
"packagetype": "bdist_wheel",
"python_version": "cp38",
"requires_python": null,
"size": 11664442,
"upload_time": "2024-04-24T01:37:41",
"upload_time_iso_8601": "2024-04-24T01:37:41.101452Z",
"url": "https://files.pythonhosted.org/packages/a6/9c/5f4e09c830506277995577c215327f339642e79e258b01ab291e9a5755a4/qualesim-1.0.2-cp38-cp38-manylinux2014_x86_64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "81a38081ab37e47fdac766338abae06991dba4b7dd481be63a2f881970d7046b",
"md5": "f6d2ff7191f0c4d6c80cd74392d9258e",
"sha256": "5a1fc2748f9c4c40acfb47d10d94799f762fa581e5970ec53bf4ec9974864d71"
},
"downloads": -1,
"filename": "qualesim-1.0.2-cp39-cp39-manylinux2014_x86_64.whl",
"has_sig": false,
"md5_digest": "f6d2ff7191f0c4d6c80cd74392d9258e",
"packagetype": "bdist_wheel",
"python_version": "cp39",
"requires_python": null,
"size": 11671783,
"upload_time": "2024-04-24T01:37:44",
"upload_time_iso_8601": "2024-04-24T01:37:44.483290Z",
"url": "https://files.pythonhosted.org/packages/81/a3/8081ab37e47fdac766338abae06991dba4b7dd481be63a2f881970d7046b/qualesim-1.0.2-cp39-cp39-manylinux2014_x86_64.whl",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-04-24 01:37:25",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "qualesim"
}