QPanda-Lite. A python-native version for pyqpanda. Simple, easy, and transparent.
Project description
QPanda-lite
QPanda: Quantum Programming Architecture for NISQ Device Application
QPanda-lite should be a simple, easy, and transparent python-native version for QPanda.
Status
Developing. Unstable.
Design principles
- A clear, and tranparent way to assemble/execute a quantum program
- Support sync/async modes for execution on a quantum hardware
- Clear error hints
- Full, and better documentations
- Visualization of the quantum program
- Be able to migrate to different quantum backends
Install
OS
- Windows
- Linux (not fully tested)
- MacOS (not fully tested)
Requirements
- Python >= 3.7
Optional for quafu execution
manually install via pip :
- pyquafu (pip install pyquafu)
Optional for qiskit execution
manually install via pip :
- qiskit (pip install qiskit) and
- qiskit-ibm-provider (pip install qiskit-ibm-provider) and
- qiskit-ibmq-provider (pip install qiskit-ibmq-provider)
Optional for C++ simulator
- CMake >= 3.1
- C++ compiler (with C++ 14 support), including MSVC, gcc, clang, etc...
Build from source
A minimum version
# Clone the code
git clone https://github.com/Agony5757/QPanda-lite.git
cd QPanda-lite
# install
python setup.py install --no-cpp
For development
git clone https://github.com/Agony5757/QPanda-lite.git
cd QPanda-lite
# install
python setup.py develop
With 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 install
Build the docs
Will be released in the future.
pip
For python 3.8 to 3.10
pip install qpandalite
Tutorials
There are several ways to use QPanda-lite now.
- Circuit building
- Run circuit on several backends / dummies (classical-simulation backends)
- Circuit simulation
1. Circuit build
Refer to test/demo
from qpandalite import Circuit
c = Circuit()
c.rx(1, 0.1)
c.cnot(1, 0)
measure(0, 1, 2, 3)
print(c.circuit)
Function | Code sample | Explanation |
---|---|---|
Circuit initialization | c = qpandalite.Circuit() | |
Qubit/cbit initialization | No need to specify the number | |
Gate (like CNOT) | c.cnot(1,2) | Directly use the qubit number |
Measure | c.measure(0,1,2) | Directly use the qubit number (no support mid-circuit measurement) |
Remap | c = c.remapping({0:10, 1:11, 2:12}) | Input a python dict to indicate the mapping. It creates a new Circuit object. |
Output as str | c.circuit / c.originir | Return a python str |
2. Circuit run on Quantum Devices / Dummies
Function | Code sample | Explanation |
---|---|---|
"Import" the platform | import qpandalite.task.originq as originq | This importing is independent from "import qpandalite". Available platforms are under qpandalite.task |
Prepare the account | See qcloud_config_template | |
Task submission | taskid = 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. See Circuit 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 result | results = 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 expectation | exps = [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 OriginQ
Step 1. Create online config
Refer to qcloud_config_template/originq_template.py
- Input the necessary information (token, urls, group_size) to call create_originq_online_config
- You 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_dummy
Dummy 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 run
Refer to test/demo
2.2 Circuit run on Quafu Device
Step 1. Create online config
Refer to qcloud_config_template/quafu_template.py
- Input the necessary information (token, urls, group_size) to call create_quafu_online_config
- You 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 run
Todo.
2.3 Circuit run on IBM Device
Todo.
3. Circuit simulation
Refer to test/draft_test/originir_simulator_test.py
import qpandalite.simulator as qsim
sim = qsim.OriginIR_Simulator(reverse_key=False)
originir = '''
QINIT 72
CREG 2
RY 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)
Readthedocs
Readthedocs: https://qpanda-lite.readthedocs.io/
Build the docs
The doc is based on
cd docs
pip install -r requirements.txt
make html
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Hashes for qpandalite-0.2.0-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d6f9373fc647c8713aa4ab5f2f5c0d8b64a5468e98ee3b649f791a9234d0d006 |
|
MD5 | 2da00cc7d8d5b622352c0ac84a99f734 |
|
BLAKE2b-256 | 83e269a0f98816692044f11f15aa44b7e60c94ed44817feb6fc0849ea746c047 |
Hashes for qpandalite-0.2.0-cp311-cp311-manylinux_2_27_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd0b8f69d405e6f810b49785491063438ffdf76a2864b74067da993298d1fc69 |
|
MD5 | 497928439ad3b57daffcdb334d8b4db6 |
|
BLAKE2b-256 | 5ca5163241c4d960250e687de81ab9c2e6d402e25fe69291d9be793183d608fe |
Hashes for qpandalite-0.2.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7daa7cac66cbb20b5540a42e9f9f91d992c843ce2b9ec3f4487d8ff8d7be8f67 |
|
MD5 | 1b0d26589eb4b243e8276c526b2bc847 |
|
BLAKE2b-256 | 224a496e435cf5de4bcd3612c824b4b3bed67fd0f37dc898fdf19bf58a19f8cc |
Hashes for qpandalite-0.2.0-cp310-cp310-manylinux_2_27_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 94e5be0b93869ac19c2a2f1f6ed7b93ec1a98a97f6cf417e0cd118d940116892 |
|
MD5 | f2fa8b9a463240cfb64462d7c7b4e241 |
|
BLAKE2b-256 | d01da3bb4aae9e8b13e984ae588009341e227183e7a0c9353945a0edd0a2ca78 |
Hashes for qpandalite-0.2.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0cf2be80f209ba492916007ffbc4a289011a975a0a9698c2c2637b5ce0b24fc2 |
|
MD5 | 1dca2b16e65d35b168b9993a6f3bb10d |
|
BLAKE2b-256 | 1092bd23ed00a576f3fce895f44c323449ae19d372202169842c532c1c5ecd7c |
Hashes for qpandalite-0.2.0-cp39-cp39-manylinux_2_27_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b5673a2038ce883eec15af0b3497c8dfb1d6d8f018ac4d0123079d6819bcbb5 |
|
MD5 | 0d037ff075bdf57af24d1e0eb568768c |
|
BLAKE2b-256 | a4ef5555838623e34e5fc8395b2c86412b4115dab1a186a83272b5d81aa89e91 |
Hashes for qpandalite-0.2.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b8a4b435a1dd870c725ce4f9557b64ae66fd8cc4481b8675a6c822bfb6496eff |
|
MD5 | 649ef518c2074dacbb191e9a388d8bf8 |
|
BLAKE2b-256 | 83e868bdc93ff4c08c3d4ddb683cd1c187ed9b14a62edde803391e4ca69a2662 |
Hashes for qpandalite-0.2.0-cp38-cp38-manylinux_2_27_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a2d550a3c9b2603f4c026768184c3c43eabd0b53c9ecde2692dda9bf1a527492 |
|
MD5 | 80cc1254fd8c0c5bf69e6fb15f53adf9 |
|
BLAKE2b-256 | e456ec4045863bfed4078ed4acbea206433572c0520ff1e1e31b7bb3aeef8d78 |