Skip to main content

Symbolic Calculation of Quantum Computation with Sympy

Project description

Qympy - Quantum Analytic Computation with Sympy

A sympy based python package for symbolic calculation of $n$-qubit quantum state. See GitHub: https://github.com/r08222011/Qympy


Installation

Simply run, see Qympy

pip install qympy

Get Started

1. Circuit Initialization Common circuits ansatz can be found in /src/qympy/quantum_circuit. To build a circuit from beginning, use sp_circuit.Circuit. The basic use of Circuit is same as Qiskit. For example:

from qympy.quantum_circuit.sp_circuit import Circuit

qc = Circuit(3)   # initialize a 3-qubit quantum circuit
qc.h(0)           # Hadamard gate on 0th qubit
qc.ry("x", 0)     # y-rotation on 0th qubit with theta = x
qc.rxx("y", 1, 2) # xx-rotation on 1st and 2nd qubits with theta = y
qc.cx(0,1)        # CNOT on 1st and 2nd qubits
qc.cz(1,2)        # CZ on 1st and 2nd qubits

2. Draw the circuit We now have initialized a quantum circuit. To see the circuit we built, we can use Circuit.draw(). This method use qiskit.circuit.QuantumCircuit.draw with draw('mpl') as default. For example:

qc.draw("mpl")

plot

3. Evolve and measure the circuit The last step for getting the analytic expression is to call the method Circuit.evolve_state(). This will calculate the final state with the gates applied. After evolving the quantum state, we can measure the quantum state with X, Y, Z basis with a single certain qubit. For example:

qc.evolve()
print(sp.latex(qc.measure(2, "Z")))
qc.measure(2, "Z")

Note, you can see the prettier expression with jupyter.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qympy-1.2.0.tar.gz (7.9 kB view hashes)

Uploaded Source

Built Distribution

qympy-1.2.0-py3-none-any.whl (8.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page