Package: qpandalite
QPanda-liteQPanda:QuantumProgrammingArchitecture forNISQDeviceApplicationQPanda-liteshould bea simple, easy, and transparent python-native version for QPanda.StatusDeveloping. Unstable.Design principlesA clear, and tranparent way to assemble/execute a quantum programSupport sync/async modes for execution on a quantum hardwareClear error hintsFull, and better documentationsVisualization of the quantum programBe able to migrate to different quantum backendsInstallOSWindowsLinux (not fully tested)MacOS (not fully tested)RequirementsPython >= 3.7Optional for quafu executionmanually install via pip :pyquafu (pip install pyquafu)Optional for qiskit executionmanually install via pip :qiskit (pip install qiskit) andqiskit-ibm-provider (pip install qiskit-ibm-provider) andqiskit-ibmq-provider (pip install qiskit-ibmq-provider)Optional for C++ simulatorCMake >= 3.1C++ compiler (with C++ 14 support), including MSVC, gcc, clang, etc...Build from sourceA minimum version# Clone the codegitclonehttps://github.com/Agony5757/QPanda-lite.gitcdQPanda-lite# installpythonsetup.pyinstall--no-cppFor developmentgit clone https://github.com/Agony5757/QPanda-lite.git
cd QPanda-lite

# install
python setup.py developWith C++ enabled (quantum circuit simulator written in C++, ensure that CMAKE is included in your environment variables.)git clone https://github.com/Agony5757/QPanda-lite.git
cd QPanda-lite

# install
python setup.py installBuild the docsWill be released in the future.pipFor python 3.8 to 3.10pip install qpandaliteTutorialsThere are several ways to use QPanda-lite now.Circuit buildingRun circuit on several backends / dummies (classical-simulation backends)Circuit simulation1. Circuit buildRefer totest/demofromqpandaliteimportCircuitc=Circuit()c.rx(1,0.1)c.cnot(1,0)measure(0,1,2,3)print(c.circuit)FunctionCode sampleExplanationCircuit initializationc = qpandalite.Circuit()Qubit/cbit initializationNo need to specify the numberGate (like CNOT)c.cnot(1,2)Directly use the qubit numberMeasurec.measure(0,1,2)Directly use the qubit number (no support mid-circuit measurement)Remapc = c.remapping({0:10, 1:11, 2:12})Input a python dict to indicate the mapping. It creates a new Circuit object.Output as strc.circuit / c.originirReturn a python str2. Circuit run on Quantum Devices / DummiesFunctionCode sampleExplanation"Import" the platformimport qpandalite.task.originq as originqThis importing is independent from "import qpandalite". Available platforms are under qpandalite.taskPrepare the accountSeeqcloud_config_templateTask submissiontaskid = originq.submit_task(circuits)Circuits is str or List[str]. Returned taskid can be either list or one str, depending on the number of inputting circuits. All returns are native python data structures. SeeCircuit build.Query (synchronously)results = originq.query_by_taskid_sync(taskid)Inputting the taskid by the return of submit_task. The results are always a list (even if you only submit one circuit). All returns are native python data structures.Query (asynchronously)status_and_result = originq.query_by_taskid(taskid)Inputting the taskid by the return of submit_task. This will immediately return without waiting. Use status_and_result['status'] to see if the computing is finished; use status_and_result['result'] to view results (the same with Query (synchronously), always being a list). All returns are native python data structures.Handle measurement resultresults = originq.convert_originq_result(results, style = 'keyvalue', prob_or_shots = 'prob')Convert the raw data to a more human-friendly format. Style includes "keyvalue" and "list", prob_or_shots includes "prob" and "shots". When inputting a list, the output is also a list corresponding to all inputs. All returns are native python data structures.Calculate expectationexps = [calculate_expectation(result, ['ZII', 'IZI', 'IIZ']) for result in results]Calculate the Z/I expectations accroding to the measurement results. Note that it only accepts the diagonal Hamiltonians. The hamiltonians can be a list, where the output is also a list. However, the input "result" cannot be a list.2.1 OriginQStep 1. Create online configRefer toqcloud_config_template/originq_template.pyInput the necessary information (token, urls, group_size) to call create_originq_online_configYou will have the originq_online_config.json in your current working directory (cwd).Now you can submit task to the online chip!Step 1.1 (Optional). Use originq_dummyDummy server is used to emulate the behavior of an online-avaiable quantum computing server, without really accessing the system but with your local computer to simulate the quantum circuit.Input the necessary information (available_qubits and available_topology) to call create_originq_dummy_config.If you want both mode, use create_originq_config and inputting all needed information.Step 2. Create the circuits and runRefer totest/demo2.2 Circuit run on Quafu DeviceStep 1. Create online configRefer toqcloud_config_template/quafu_template.pyInput the necessary information (token, urls, group_size) to call create_quafu_online_configYou will have the quafu_online_config.json in your cwd.Now you can submit task to the online chip!Step 2. Create the circuit and runTodo.2.3 Circuit run on IBM DeviceTodo.3. Circuit simulationRefer totest/draft_test/originir_simulator_test.pyimportqpandalite.simulatorasqsimsim=qsim.OriginIR_Simulator(reverse_key=False)originir='''QINIT 72CREG 2RY q[45],(0.9424777960769379)RY q[46],(0.9424777960769379)CZ q[45],q[46]RY q[45],(-0.25521154)RY q[46],(0.26327053)X q[46]MEASURE q[45],c[0]MEASURE q[46],c[2]MEASURE q[52],c[1]'''res=sim.simulate(originir)print(res)print(sim.state)# Expect output:# [0.23218757036469517, 0.04592184582945769, 0.0, 0.0, 0.6122094271102275, 0.10968115669561962, 0.0, 0.0]# [(0.4818584546987789+0j), (-0.21429383059121812+0j), (0.7824381298928546+0j), (0.33118145584500897+0j), 0j, 0j, 0j, 0j]Documentation (not finished)ReadthedocsReadthedocs: https://qpanda-lite.readthedocs.io/Build the docsThe doc is based oncddocs
pipinstall-rrequirements.txt
makehtml