Views
No views yet
1@misc{Dahya2026RepoChoiCholesky,
2 author = {Dahya, Raj},
3 title = {{Choi--Cholesky}},
4 subtitle = {{Algorithms for decomposition of CPTP-maps}},
5 publisher = {Hugging Face},
6 doi = {10.57967/hf/8114},
7 url = {https://doi.org/10.57967/hf/8114},
8 note = {{Code base available under \url{https://doi.org/10.57967/hf/8114}, Release vX.Y.Z}},
9 year = {2026}}1@misc{Dahya2026PreprintChoiCholesky,
2 author = {Dahya, Raj},
3 title = {{The Choi-Cholesky algorithm for completely positive maps}},
4 publisher = {arXiv},
5 doi = {10.48550/arXiv.2603.19444},
6 url = {https://doi.org/10.48550/arXiv.2603.19444},
7 year = {2026}}1[project]
2name = "example"
3version = "0.0.0"
4description = 'Example code base'
5authors = [
6 {name="me", email="me@users.noreply.git.com"},
7]
8urls = {homepage = 'https://git.com/me/example'}
9maintainers = [
10 {name="me", email="me@users.noreply.git.com"},
11]
12license = 'MIT'
13readme = 'README.md'
14keywords = [
15 "python",
16]
17classifiers = [
18 "Programming Language :: Python :: 3",
19]
20requires-python = ">=3.11,<3.15"
21
22dependencies = [
23 "pip>=26.0.1",
24 # third party package - replace vX.Y.Z by desired version
25 "choi-cholesky @ git+https://hf.co/raj-dahya/choi-cholesky.git@vX.Y.Z#egg=choi-cholesky",
26 # to include Rust backend
27 # "choi-cholesky[rust] @ git+https://hf.co/raj-dahya/choi-cholesky.git@vX.Y.Z#egg=choi-cholesky",
28]
29
30[dependency-groups]
31dev = [
32 "uv>=0.11.2",
33 "ruff>=0.15.8",
34 "pytest>=9.0.2",
35 "maturin>=1.12.6",
36]
37
38[build-system]
39requires = [
40 "setuptools>=82.0.1",
41 "wheel>=0.46.3",
42 "maturin>=1.12.6,<2.0",
43]
44build-backend = "setuptools.build_meta"
45
46[tool.pip]
47extra-index-url = []1import logging
2
3from choi_cholesky.algorithms.generation import *
4from choi_cholesky.algorithms.choi_cholesky import *
5from choi_cholesky.experiments.choi_cholesky import *
6
7if __name__ == "__main__":
8 # optional seed
9 seed = "1234" # or None
10
11 # set up logging
12 logging.basicConfig(
13 format="%(asctime)s $\x1b[92;1m%(name)s\x1b[0m [\x1b[1m%(levelname)s\x1b[0m] %(message)s",
14 datefmt=r"%Y-%m-%d %H:%M:%S",
15 encoding="utf-8",
16 )
17 logging.getLogger().setLevel(logging.INFO)
18
19 # create Choi matrix of random CP-map
20 C = random_cp(10, 20, seed=seed)
21 logging.info(C.shape) # (10, 10, 20, 20)
22
23 # create Choi matrix of random CPTP-map
24 C = random_cptp(10, 20, seed=seed)
25 logging.info(C.shape) # (10, 10, 20, 20)
26
27 # run Choi-Cholesky decomposition:
28 L = algorithm_choi_cholesky(C, tol=1e-6) # algorithm in paper
29 diff = tensor_diff(tensor_multiply(L, tensor_conj(L)), C)
30 print(f"‖L·L^† – C(Φ)‖ = {diff:.4g}")
31
32 L = algorithm_choi_cholesky_modified(C, tol=1e-6) # equivalent but modified version
33 diff = tensor_diff(tensor_multiply(L, tensor_conj(L)), C)
34 print(f"‖L·L^† – C(Φ)‖ = {diff:.4g}")
35
36 # run numerical experiment to empirically verify correctness of algorithm
37 verify_choi_cholesky(
38 # d1 = dim(H1), d2 = dim(H2)
39 d1=10,
40 d2=20,
41 # number of iterations in which a CP-map Φ : L^1(H1) - L^1(H2) is defined and decomposed
42 n=100,
43 # generate random CP-maps (or CPTP-maps) in each iteration
44 map="CP", # choices: "CP", "CPTP"
45 # use the Choi-Cholesky algorithm (or the modified one) in each iteration
46 algorithm="CHOI-CHOLESKY", # choices: "CHOI-CHOLESKY", "CHOI-CHOLESKY-MODIFIED"
47 # optional seed
48 seed=seed,
49 )1# create and activate virtual environment
2python3 -m venv .venv
3. .venv/bin/activate
4# install and upgrades package manager
5python3 -m pip install --upgrade pip uv
6# install depdendencies using the uv package manager
7python3 -m uv sync --compile-bytecode --no-managed-python --no-python-downloads1# create and activate virtual environment
2py -3 -m venv .venv
3. .venv/Scripts/activate
4# install and upgrades package manager
5python -m pip install --upgrade pip uv
6# install depdendencies using the uv package manager
7python -m uv sync --compile-bytecode --no-managed-python --no-python-downloads1. .venv/bin/activate # for linux/osx
2. .venv/Scripts/activate # for windows1python3 -m src.examples --help # to display help
2python3 -m src.examples version # to display version information
3python3 -m src.examples # runs the numerical experiment with default settings
4# run the numerical experiment with custom settings
5python3 -m src.examples --algorithm ... --map ... --num ... --dim1 ... --dim2 ... --seed ...just setup and modify the contents of the newly created .env file (viz. set PYTHON_PATH to the command for your system).just build to build a virtual environment + dependencies.1just run-examples --help # to display help
2just run-examples version # to display version information
3
4just run-examples # runs the numerical experiment with default settings
5just run-examples --algorithm ... --map ... --num ... --dim1 ... --dim2 ... --seed ...| Flag | Value | Description |
|---|---|---|
-a / --algorithm | (default) "CHOI-CHOLESKY" | uses the Choi–Cholesky decomposition as in the paper |
| " | "CHOI-CHOLESKY-MODIFIED" | uses a slightly optimised variant of the Choi–Cholesky decomposition to reduce floating point errors |
-m / --map | (default) "CP" | during each iteration of the verification generate (the Choi-matrix of) a random CP-map |
| " | "CPTP" | during each iteration of the verification generate (the Choi-matrix of) a random CPTP-map |
-n / --num | <integer> (default=100) | number of iterations in experiment |
--dim1 | <integer> (default=10) | dimension of the "input" Hilbert space H1 |
--dim2 | <integer> (default=20) | dimension of the "output" Hilbert space H2 |
--seed | <string> (default: null, examples: "1234", "abc", etc.) | if set, seeds the random number generator for repeatability |
1...
2dependencies = [
3 ...
4 # third party package - replace vX.Y.Z by desired version
5 "choi-cholesky[rust] @ git+https://hf.co/raj-dahya/choi-cholesky.git@vX.Y.Z#egg=choi-cholesky",
6 ...
7]
8...1import logging
2
3# import basic methods
4from choi_cholesky.models.linalg.bipartite import tensor_diff
5from choi_cholesky.models.linalg.bipartite import tensor_conj
6from choi_cholesky.models.linalg.bipartite import tensor_multiply
7
8# import critical methods from rust backend for improved efficiency
9from choi_cholesky_rust import random_cp
10from choi_cholesky_rust import random_cptp
11from choi_cholesky_rust import algorithm_choi_cholesky
12from choi_cholesky_rust import algorithm_choi_cholesky_modified
13from choi_cholesky_rust import verify_choi_cholesky
14
15if __name__ == "__main__":
16 seed = "1234"
17 # set up logging
18 logging.basicConfig(
19 format="%(asctime)s $\x1b[92;1m%(name)s\x1b[0m [\x1b[1m%(levelname)s\x1b[0m] %(message)s",
20 datefmt=r"%Y-%m-%d %H:%M:%S",
21 encoding="utf-8",
22 )
23 logging.getLogger().setLevel(logging.INFO)
24
25 # create Choi matrix of random CP-map
26 # NOTE: underlying linear algebraic operation (computation of operator norm) to ensure C is a contraction is subject to correction.
27 try:
28 C = random_cp(10, 20, seed=seed)
29 logging.info(C.shape) # (10, 10, 20, 20)
30
31 except Exception as err:
32 logging.error(err)
33
34 # create Choi matrix of random CPTP-map
35 C = random_cptp(10, 20, seed=seed)
36 logging.info(C.shape) # (10, 10, 20, 20)
37
38 # run Choi-Cholesky decomposition:
39 L = algorithm_choi_cholesky(C, tol=1e-6) # algorithm in paper
40 diff = tensor_diff(tensor_multiply(L, tensor_conj(L)), C)
41 print(f"‖L·L^† – C(Φ)‖ = {diff:.4g}")
42
43 L = algorithm_choi_cholesky_modified(C, tol=1e-6) # equivalent but modified version
44 diff = tensor_diff(tensor_multiply(L, tensor_conj(L)), C)
45 print(f"‖L·L^† – C(Φ)‖ = {diff:.4g}")
46
47 # run numerical experiment to empirically verify correctness of algorithm
48 # NOTE: using rust backend, this runs the experiments in parallel
49 verify_choi_cholesky(
50 # d1 = dim(H1), d2 = dim(H2)
51 d1=10,
52 d2=20,
53 # number of iterations in which a CP-map Φ : L^1(H1) - L^1(H2) is defined and decomposed
54 n=1000,
55 # generate random CP-maps (or CPTP-maps) in each iteration
56 map="CP", # choices: "CP", "CPTP"
57 # use the Choi-Cholesky algorithm (or the modified one) in each iteration
58 algorithm="CHOI-CHOLESKY", # choices: "CHOI-CHOLESKY", "CHOI-CHOLESKY-MODIFIED"
59 # optional seed
60 seed=seed,
61 )note can be replaced by given version or commit id used. ↩