Skip to main content

Quantum Entanglement in Python

Project description

Quantum Entanglement in Python

CircleCI GitHub release Documentation Status Updates Python 3 pypi download


The releases of pyqentangle 2.x.x is incompatible with previous releases.

The releases of pyqentangle 3.x.x is incompatible with previous releases.

Since release 3.1.0, the support for Python 2.7 and 3.5 has been decomissioned. Since release 3.3.0, support for Python 3.6 is diminished, but that for Python 3.11 is added.


This package can be installed using pip.

>>> pip install -U pyqentangle

To use it, enter

>>> import pyqentangle
>>> import numpy as np

Schmidt Decomposition for Discrete Bipartite States

We first express the bipartite state in terms of a tensor. For example, if the state is |01>+|10>, then express it as

>>> tensor = np.array([[0., np.sqrt(0.5)], [np.sqrt(0.5), 0.]])

To perform the Schmidt decompostion, just enter:

>>> pyqentangle.schmidt_decomposition(tensor)
[(0.7071067811865476, array([ 0., -1.]), array([-1., -0.])),
 (0.7071067811865476, array([-1.,  0.]), array([-0., -1.]))]

For each tuple in the returned list, the first element is the Schmidt coefficients, the second the component for first subsystem, and the third the component for the second subsystem.

Schmidt Decomposition for Continuous Bipartite States

We can perform Schmidt decomposition on continuous systems too. For example, define the following normalized wavefunction:

>>> fcn = lambda x1, x2: np.exp(-0.5 * (x1 + x2) ** 2) * np.exp(-(x1 - x2) ** 2) * np.sqrt(np.sqrt(8.) / np.pi)

Then perform the Schmidt decomposition,

>>> modes = pyqentangle.continuous_schmidt_decomposition(biwavefcn, -10., 10., -10., 10., keep=10)

where it describes the ranges of x1 and x2 respectively, and keep=10 specifies only top 10 Schmidt modes are kept. Then we can read the Schmidt coefficients:

>>> list(map(lambda dec: dec[0], modes))

The second and the third elements in each tuple in the list decompositions are lambda functions for the modes of susbsystems A and B respectively. The Schmidt functions can be plotted:

>>> xarray = np.linspace(-10., 10., 100)

    plt.subplot(3, 2, 1)
    plt.plot(xarray, modes[0][1](xarray))
    plt.subplot(3, 2, 2)
    plt.plot(xarray, modes[0][2](xarray))

    plt.subplot(3, 2, 3)
    plt.plot(xarray, modes[1][1](xarray))
    plt.subplot(3, 2, 4)
    plt.plot(xarray, modes[1][2](xarray))

    plt.subplot(3, 2, 5)
    plt.plot(xarray, modes[2][1](xarray))
    plt.subplot(3, 2, 6)
    plt.plot(xarray, modes[2][2](xarray))


Useful Links


  • Artur Ekert, Peter L. Knight, "Entangled quantum systems and the Schmidt decomposition", Am. J. Phys. 63, 415 (1995).


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

pyqentangle-3.3.1.tar.gz (68.1 kB view hashes)

Uploaded source

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