Skip to main content

Tool to convert a matrix product state to a Qiskit quantum circuit.

Project description

MPS to circuit

DOI

Toolbox for converting matrix product states to Qiskit quantum circuits.

Usage with Quimb

Assuming you have a Quimb MatrixProductState object, you can extract the individual tensors as three-dimensional NumPy arrays using the snippet below.

mps_arrays = mps.arrays

You can now convert the list of tensors to a Qiskit QuantumCircuit using the mps_to_circuit interface function, specifying the shape as $(v_L, v_R, p)$ (this is also the default argument for shape).

For example, using the "exact" method [Shoen2006]:

qc = mps_to_circuit(mps_arrays, method="exact", shape="lrp")

Or using the "approximate" method [Ran2019]:

qc = mps_to_circuit(mps_arrays, method="approximate", shape="lrp", num_layers=3)

Usage with TenPy

Assuming you have a TenPy MPS object, you can extract the individual tensors as three-dimensional NumPy arrays using the snippet below.

mps_arrays = [mps.get_B(i).to_ndarray() for i in range(L)]

You can now convert the list of tensors to a Qiskit QuantumCircuit using the mps_to_circuit interface function, specifying the shape as $(v_L, p, v_R)$.

For example, using the "exact" method [Shoen2006]:

qc = mps_to_circuit(mps_arrays, method="exact", shape="lpr")

Or using the "approximate" method [Ran2019]:

qc = mps_to_circuit(mps_arrays, method="approximate", shape="lpr", num_layers=3)

Development

Installation

This package and all dependencies can be installed using uv.

curl -LsSf https://astral.sh/uv/install.sh | sh
uv python install 3.12
uv venv --python 3.12
uv python pin 3.12
uv pip install -e .

Testing

One can test the code using pytest .

uv run pytest

Linting

One can lint the code using the Ruff Linter.

uv run ruff check

Formatting

One can format the code using the Ruff Formatter.

uv run ruff format

Code of conduct

All members of this project agree to adhere to the Qiskit Code of Conduct listed here.

Citation

If you use mps-to-circuit please cite as per the BibTeX below.

@software{mpstocircuit2025,
  author       = {D. A. Millar,
                  G. W. Pennington,
                  N. T. M. Siow and
                  S. J. Thomson},
  title        = {qiskit-community/mps-to-circuit},
  month        = feb,
  year         = 2025,
  publisher    = {Zenodo},
  doi          = {10.5281/zenodo.14920029},
  url          = {https://doi.org/10.5281/zenodo.14920029},
}

Acknowledgements

This work was supported by the Hartree National Centre for Digital Innovation, a collaboration between the Science and Technology Facilities Council and IBM.

License

Apache-2.0 license

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

mps_to_circuit-0.1.2.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mps_to_circuit-0.1.2-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

Details for the file mps_to_circuit-0.1.2.tar.gz.

File metadata

  • Download URL: mps_to_circuit-0.1.2.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.6.5

File hashes

Hashes for mps_to_circuit-0.1.2.tar.gz
Algorithm Hash digest
SHA256 fb38f44013cc9939de3128d655f7ba7149b5c9d3abefe17548020c111db64521
MD5 8737be27c4505b29e5dd5fde0e3cfecb
BLAKE2b-256 6152799003234f5d4ceac827e7b58f6dc92109e635a8d191c1f5ffdae39f66f6

See more details on using hashes here.

File details

Details for the file mps_to_circuit-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for mps_to_circuit-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8647efe676562a69e0e0d1d64def22020644f8bdf8255603f9e9bd6fe1f44eb3
MD5 58f932e8c2a2b255d9c902b2dea4a14d
BLAKE2b-256 981ee1bdaca063cb8501bd44e499184b2906eece0b599171a056eabc47937736

See more details on using hashes here.

Supported by

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