# QuaLeSim **Repository Path**: quingo/qualesim ## Basic Information - **Project Name**: QuaLeSim - **Description**: No description available - **Primary Language**: Python - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2023-09-05 - **Last Updated**: 2025-03-04 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 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("", verbosity=Loglevel.INFO) # sim.with_frontend("", 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.