Skip to content

Convert a matrix product state of arbitrary bond dimension to a Qiskit circuit.

License

Notifications You must be signed in to change notification settings

qiskit-community/mps-to-circuit

Repository files navigation

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

About

Convert a matrix product state of arbitrary bond dimension to a Qiskit circuit.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages