Linear algebra on quantum computers using block encodings
Project description
unitaria :rainbow:
unitaria is a library for working with so called "block encodings" of matrices
and vectors. These are format for performing linear algebra calculations on
quantum computers. It allows constructing quantum algorithms using a simple,
numpy-like syntax.
>>> import unitaria as ut
>>> import numpy as np
>>> result = ut.Identity(ut.Subspace.from_dim(2)) @ ut.ConstantVector(np.array([3, 4]))
>>> print(result.draw())
Mul
├── Identity{'subspace': Subspace("#")}
└── ConstantVector{'vec': array([3, 4])}
>>> result.toarray().real
array([3., 4.])
>>> result.normalization
np.float64(5.0)
>>> result.circuit()
Circuit(_tq_circuit=circuit:
GlobalPhase(target=(), control=(), parameter=0.0)
Ry(target=(0,), parameter=1.854590436003224)
, n_qubits=1)
Getting started
The best way to install this library is using pip:
pip install unitaria
This installs everything needed to work with unitaria, including the
simulation backend qulacs. Additional backends compatible with tequila,
which is used for communcating with the backends, can also be installed, see
tequila.
unitaria aims to be as intuitive as possible. Most operators do exactly what
you would expect them to. To construct a tridiagonal matrix, you can, e.g., write
import unitaria as ut
N = 3
inc = ut.Increment(bits=N)
laplace = (2 * ut.Identity(dim=2**N) - inc - inc.adjoint())[:-1, :-1]
If you are not sure how to construct a matrix or vector, you can use the
ConstantMatrix or ConstantVector functions.
import unitaria as ut
import numpy as np
v = ut.ConstantVector(np.array([1, 2, 3]))
A = ut.ConstantMatrix(np.array([[1, 2], [3, 4]]))
Note, however, that this will typically not yield efficient quantum circuits.
For a list of all implemented matrices, vectors, and operations check
out the documentation. Additional examples are available under
/examples.
Contributing
We welcome contributions to unitaria. Check out the Contributing guildlines for details.
Development
To install this library locally, clone this repository and run
pip install --editable .
To run the test suite you can then execute
pytest
To build the documentation, some additional dependencies are required, which can be installed using
pip install --group docs --editable .
Then navigate to the /docs folder and run
rm -r generated
make html
If you get the error locale.Error: unsupported locale setting, try adding the environment variable LC_ALL=C.UTF-8:
LC_ALL=C.UTF-8 make html
Python versions
unitaria requires at least Python version 3.12, and follows Numpy's deprecation policy,
i.e. at least Python 3.13 will be required starting April 2027.
Versioning
Unitaria follows SemVer conventions.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file unitaria-0.2.0.tar.gz.
File metadata
- Download URL: unitaria-0.2.0.tar.gz
- Upload date:
- Size: 46.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dd8d680b7faf15b82187012317d97961bbb3a0f9a2e1e01fe443aa64ec768433
|
|
| MD5 |
16a46f953bf9cc5e109469683fccb8f3
|
|
| BLAKE2b-256 |
df9b7e9fa3c1deadf234e6a581f2e431089009e1a6bcff0ef972e748b974e06d
|
File details
Details for the file unitaria-0.2.0-py3-none-any.whl.
File metadata
- Download URL: unitaria-0.2.0-py3-none-any.whl
- Upload date:
- Size: 72.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3e599df20de8e7a164e9ab8279ce8c7317a82454f3d75be556613310e747a282
|
|
| MD5 |
b48ba9d212cf2c65c0ef3cb2520b5ddd
|
|
| BLAKE2b-256 |
9153ddabf22022d534e156deb3d2676a692789ca63c162d0b3ab37e7d49a7921
|