Skip to main content

PyPI package based on the LoGIC repo for simulating loss effected gaussian interferometers.

Project description

Lossy Gaussian Interferometer Computation - LoGIC

DOI

Lightweight tools for propagating Gaussian states through programmable interferometers that allows simulation of internal, balanced photon loss. It wraps the interferometer package with a small GaussianDevice helper, plus ready-to-run demos for beam splitter networks or matrix files.

This project was developed to produce the data of Figure 7 in D'Achille et al. 2026 (unpublished; see Section VI Error Analysis, B Photon Loss). You can find a preprint version preprint version on the arXiv.

For details, see the demo_literature.py section in the user manual and please read the Disclaimer below.

Quick start

Install from the local source tree:

python -m venv venv
.\venv\Scripts\activate
pip install -r requirements.txt

The package can also be installed with:

pip install logic-jena

After installation, the Python API is available as:

from logic.pipeline import run_on_files

and the CLI is available as:

logic run_on_files --help

Run a basic simulation of a random squeezed input through a random beam splitter network:

python demos/demo_pipeline.py --modes 4 --eta 0.9 --topology Clements --seed 123

In the Python API, get_Vout(..., topology="embedded_reck") is also supported. This embeds a Reck decomposition into a larger Clements mesh with explicit identity beam splitters and vacuum ancilla modes, then traces out the ancillas before returning the final state. The embedded mesh size can be chosen explicitly with embedded_total_modes, and defaults to the smallest validated size 2*modes - 2.

Process covariance/symplectic matrices from demos/input_covariance_mtx and demos/interferometer_symplectic:

python demos/demo_literature.py --input-dir demos/input_covariance_mtx --eta 0.9

Results land in demos/output_covariance_mtx/ (ignored by git).

The same workflow is also available through a top-level CLI for pipeline.run_on_files(...). The wrapper supports the original .mtx directory workflow and a newer single-file workflow for .json, .pickle, .npz, .h5py, and .txt files.

python main.py run_on_files --input-dir demos/input_covariance_mtx --unitary-dir demos/interferometer_symplectic --output-dir demos/notebook_outputs --output-format wl --eta 0.9 --topology Clements --time-dependent false

Example for the single-file JSON workflow:

python main.py run_on_files --input-file tests/format_comp/inputs/series_input.json --unitary-file tests/format_comp/inputs/series_unitary.json --output-dir demos/notebook_outputs --output-format same --eta 0.9 --topology Clements --time-dependent true

In single-file mode, the covariance input is expected to contain a time series of the form {{t1, cov1}, {t2, cov2}, ...} and the unitary file may contain either one single matrix or a matching time series {{t1, U1}, {t2, U2}, ...}. Native output is written back in the same file format as the input, and output_format="wl" additionally writes a Wolfram Language export.

For .txt files, LoGIC automatically detects json style, wolfram style, or matlab style text and issues a warning because plain-text matrix files are more ambiguous than native structured formats. Unknown .txt styles raise a clear error.

API highlight

import numpy as np
from pipeline import get_Vout
from devices import random_squeezed_vacuum

n_modes = 4
U = np.eye(n_modes)  # or any unitary of shape (n_modes, n_modes)
d0, V0 = random_squeezed_vacuum(n_modes)
d_out, V_out = get_Vout(U, V0, d0=d0, eta=0.9, topology="Clements")

get_Vout validates the input covariance, decomposes the unitary with the chosen beam splitter network ("Clements", "Reck", or "embedded_reck"), applies optional loss, and returns the output mean/covariance (and the device if get_device=True).

For topology="embedded_reck", the code first computes a Reck decomposition, transforms it into an enlarged Clements-style instruction list with inserted identity beam splitters, prepends vacuum ancillas to the Gaussian input state, propagates the enlarged system, and finally traces out the ancilla modes so d_out and V_out again describe only the original logical modes. If embedded_total_modes is not provided, the code uses the smallest validated Clements mesh size 2*modes - 2.

Repository layout

Authors

Supervisors

References

  • Reck, Michael, et al. "Experimental realization of any discrete unitary operator." Physical Review Letters 73.1 (1994): 58.
  • Clements, William R., et al. "Optimal design for universal multiport interferometers." Optica 3.12 (2016): 1460-1465.
  • D'Achille, Mauro, et al. (unpublished) "Configurable photonic simulator for quantum field dynamics." arXiv preprint arXiv:2506.23838 (2025)

Notes

  • Requires Python 3.11+ and the packages listed in requirements.txt.
  • The Python API and demo CLIs support Clements, Reck, and embedded_reck.
  • run_on_files(...) supports .mtx directory mode plus single-file .json, .pickle, .npz, .h5py, and .txt workflows.
  • If you regenerate results, demos/output_covariance_mtx/ and demos/logs/ will be overwritten; commit only the inputs you care about.
  • The first PyPI prerelease version is 0.1.0rc2, corresponding to the GitHub prerelease tag v0.1.0-rc.2.

DISCLAIMER

We observed hardware-dependent numerical differences when simulating large beam splitter networks in finite precision. In particular, using the same code version of demos/demo_literature.py on different machines produced output covariance matrices whose difference had a Frobenius norm on the order of 1e-2 for the 25×25 case. Repeated runs on the same machine did not show such deviations. These differences did not materially affect the information‑theoretic analysis in D'Achille et al., for which this code was developed.

The discrepancy appears only in the lossy case. This is expected because the QR-based decomposition used to construct a beam splitter network from a target unitary is not unique. While different decompositions implement the same unitary in the lossless case, they can induce different effective loss channels, leading to different lossy outputs.

Although the PyPI interferometer package is deterministic, we observed machine‑dependent variation in its decomposition results, which likely explains the cross‑machine discrepancies. We have not yet identified a reliable fix or the specific routines within interferometer that cause this problem. Users should therefore interpret results from unitary‑decomposition‑based simulations of non‑unitary dynamics with care.

If you have suggestions to address this issue, please contact us at alexander.naumann@uni-jena.de or robin.strahlendorf@uni-jena.de.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

logic_jena-0.1.0rc2.tar.gz (28.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

logic_jena-0.1.0rc2-py3-none-any.whl (26.1 kB view details)

Uploaded Python 3

File details

Details for the file logic_jena-0.1.0rc2.tar.gz.

File metadata

  • Download URL: logic_jena-0.1.0rc2.tar.gz
  • Upload date:
  • Size: 28.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for logic_jena-0.1.0rc2.tar.gz
Algorithm Hash digest
SHA256 af498cd35e7f24d63561ac0e5136ec55288928e5ff8ed839f8bafd13cf36ad70
MD5 2723e374555498ccd406513630e81a37
BLAKE2b-256 2577d8b38e65a941fac8569a267366d5254579192bed135346d382c47f90bb6c

See more details on using hashes here.

Provenance

The following attestation bundles were made for logic_jena-0.1.0rc2.tar.gz:

Publisher: release.yml on alexn2002/LoGIC

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file logic_jena-0.1.0rc2-py3-none-any.whl.

File metadata

  • Download URL: logic_jena-0.1.0rc2-py3-none-any.whl
  • Upload date:
  • Size: 26.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for logic_jena-0.1.0rc2-py3-none-any.whl
Algorithm Hash digest
SHA256 19b6ee6aac47bcda27ef5ea55d7b08d9afab960edbc497aa8d7ba846504d834e
MD5 3a637144309534cc1bce32e2bfa18c5e
BLAKE2b-256 10fcdd4835a1a5acfafb3ca545aac703f13d1344cbf77f7d9f57c132c088269d

See more details on using hashes here.

Provenance

The following attestation bundles were made for logic_jena-0.1.0rc2-py3-none-any.whl:

Publisher: release.yml on alexn2002/LoGIC

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page