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

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MPS to circuit

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

Sorting imports

In order to both sort imports and format, call the Ruff linter and then the formatter:

uv run ruff check --select I --fix
uv run ruff format

Code of conduct

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

License

Apache-2.0 license

Acknowledgements

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

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

Languages