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.
Metadata
Release files for unitaria 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| unitaria-0.2.0.tar.gz | 46.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| unitaria-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 119.4 kB
Release files / unitaria-0.2.0.tar.gz
| Download URL | unitaria-0.2.0.tar.gz |
|---|---|
| Size | 46.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dd8d680b7faf15b82187012317d97961bbb3a0f9a2e1e01fe443aa64ec768433
|
|
BLAKE2b-256 checksum How to use checksums |
df9b7e9fa3c1deadf234e6a581f2e431089009e1a6bcff0ef972e748b974e06d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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}
|
Release files / unitaria-0.2.0-py3-none-any.whl
| Download URL | unitaria-0.2.0-py3-none-any.whl |
|---|---|
| Size | 72.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3e599df20de8e7a164e9ab8279ce8c7317a82454f3d75be556613310e747a282
|
|
BLAKE2b-256 checksum How to use checksums |
9153ddabf22022d534e156deb3d2676a692789ca63c162d0b3ab37e7d49a7921
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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}
|