Skip to main content

Taichi-Q

Quantum Computation Simulator Engine Based on Taichi (available for both GPU and CPU)

This is a Hackathon Project, Project Introduction available here

Intallation (only support windows right now)

  • From PyPI
pip install taichi-q
pip3 install taichi-q

Usage

Import the Packages

# Required
from taichi_q import Engine, Gate

# Optional
import numpy as np
import taichi as ti

Setup Simulator Engine

Warning!! Simulator Engine could only be initialized once.

For CPU

eng=Engine(num_qubits=3,state_init=0,device='cpu')

For GPU

eng=Engine(num_qubits=3,state_init=0,device='gpu')

Initialize Qubits

  • All $|0\rangle$ or $|1\rangle$
eng=Engine(num_qubits=3, state_init=0, device='cpu')
eng=Engine(num_qubits=3, state_init=1, device='cpu')
  • Choose $|0\rangle$ or $|1\rangle$ of each qubit with list/tuple/ndarray
eng=Engine(num_qubits=3, state_init=[0,1,0], device='gpu')
eng=Engine(num_qubits=3, state_init=(0,1,0), device='gpu')
eng=Engine(num_qubits=3, state_init=np.array([0,1,0]), device='gpu')
  • Set complex qubit state with np.array(dtype=complex)
eng = Engine(
    num_qubits=3,
    state_init=[[-1/np.sqrt(2), j/np.sqrt(2)], [1, 0], [0, 1]],
    device='cpu')

Quantum Gate Operators

Quantum Gates could be found in taichi_q.gates. Support $H(), X(), Y(), Z(), S(), T(), swap()$ $U(\theta, \phi, \lambda), R_x(\theta), R_y(\theta), R_z(\theta)$ $QFT(n), iQFT(n)$, and all controlled gates.

  • Apply single-qubit gate to target qubit (e.g. H)
eng.Ops(Gate.H(), [0])
  • Apply muti-qubit gate to target qubits (e.g. swap)
eng.Ops(Gate.swap(), [0,1])
  • Apply controlled-qubit gate to target qubits (e.g. CNOT=CX)
eng.Ops(Gate.X(), [0], [1])
  • If you want to print Operated Gate, Tgt and Ctl on the terminal
eng.Ops(Gate.QFT(4), [0,1,2,3], [4], print_output=True)

# Output:
# OPS: QFT  Tgt: [0,1,2,3]   Ctl [4]

Measure the result of a qubit

Notice! Measure is an irreversible process. State of the measured qubit would collapsed into $|0\rangle$ or $|1\rangle$

q0_result=eng.Measure(0)

Check the state of all qubits without measuring any qubit

Notice! This is a cheating method from simulator. It's not available for real quantum computer.

Check the state of all qubits is useful for quantum computation algorithm design and debug.

  • Print all qubit states
eng.State_Check(print_state=True)

# Output:
# Q: (0, 0, 0)   State:[+0.0000+0.0000j]   P:0.0000
# Q: (0, 0, 1)   State:[+0.0000+0.0000j]   P:0.0000
# Q: (0, 1, 0)   State:[+0.0000+0.0000j]   P:0.0000
# Q: (0, 1, 1)   State:[+0.0000+0.0000j]   P:0.0000
# Q: (1, 0, 0)   State:[+0.0000+0.0000j]   P:0.0000
# Q: (1, 0, 1)   State:[+0.0000+0.0000j]   P:0.0000
# Q: (1, 1, 0)   State:[-0.4472+0.0000j]   P:0.2000
# Q: (1, 1, 1)   State:[+0.0000+0.8944j]   P:0.8000
  • Display Box-plot of qubit state probability
eng.State_Check(plot_state=True)

boxplot

Print Quantum Circuit

Quantum Gates and its order are recorded by the engine, and could be displayed on the terminal.

eng.circuit_print()

# Output:
# Q0 →|' ' ' ' '■' 'H' 'M' ' ' ' ' '■'|→ Q0
# Q1 →|'H' '■' 'X' ' ' ' ' 'M' '■' ' '|→ Q1
# Q2 →|' ' 'X' ' ' ' ' ' ' ' ' 'X' 'Z'|→ Q2

Visualize Quantum Circuit (with ti.GUI)

The circuit visualization provides a more elegant approach for circuit visualization, based on ti.GUI.

eng.circuit_visualize()

visualize

Examples

Development

Welcome any contribution!

License

Apach-2.0

Metadata

Release files for taichi-q 0.0.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for taichi-q 0.0.10
File Size Uploaded Provenance Actions
taichi_q-0.0.10.tar.gz 15.1 kB Without provenance Details for taichi_q-0.0.10.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for taichi-q 0.0.10
File Interpreter ABI Platform Actions
taichi_q-0.0.10-py3-none-any.whl Python 3 none any Details for taichi_q-0.0.10-py3-none-any.whl

Total release size: 31.6 kB

Release files / taichi_q-0.0.10.tar.gz

Download URL taichi_q-0.0.10.tar.gz
Size 15.1 kB
Tags Source
SHA-256 checksum
How to use checksums
88c8e76edbca792ba2d59875b14436495c5b0b858b68ec536b204e242ef33157
BLAKE2b-256 checksum
How to use checksums
4a939f984514fadb44e9ca12fe61a072d20727886390cc08d333206a62ed3b43
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.12

Release files / taichi_q-0.0.10-py3-none-any.whl

Download URL taichi_q-0.0.10-py3-none-any.whl
Size 16.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2595e2e314cb155b61c949df768f46abfd60a3191e836d23afcdc1c367075ec7
BLAKE2b-256 checksum
How to use checksums
8bc118a1211a06aead12234fe60f574e27de58c939edb1366446d206ed15aeba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.12

Security for taichi-q 0.0.10

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page