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, .txt, and .wl 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}, ...}. By default, output_format="same" preserves the input file type. You can also request any supported output format explicitly: .json, .pickle, .npz, .h5py, .txt, or .wl. In .mtx directory mode, output_format can be .mtx or any of those aggregated single-file formats.

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. If a file has a .json suffix but begins with Wolfram-style braces, LoGIC automatically falls back to the Wolfram parser and warns that .wl or .txt would be a better suffix.

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 current PyPI prerelease version is 0.1.0rc4, corresponding to the GitHub prerelease tag v0.1.0-rc.4.

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.0rc4.tar.gz (32.2 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.0rc4-py3-none-any.whl (28.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for logic_jena-0.1.0rc4.tar.gz
Algorithm Hash digest
SHA256 1ce81af7234749e4861dba2619e888ea314e548bca9a2fb4e60583717cd7003c
MD5 3914b7ad0e5e6ed64c5da43951674363
BLAKE2b-256 7e13717a760023472ece299bef3eb8c91019b167adfc66c5d26ea219238885d3

See more details on using hashes here.

Provenance

The following attestation bundles were made for logic_jena-0.1.0rc4.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.0rc4-py3-none-any.whl.

File metadata

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

File hashes

Hashes for logic_jena-0.1.0rc4-py3-none-any.whl
Algorithm Hash digest
SHA256 f22c9d039be032fc3663981cc6d284ab33b12979cdf8c9f1cf684f4c3e510c74
MD5 43ce2fe1fad951bf9e8e9da953019b88
BLAKE2b-256 b7e6f216cc069c1f40dee5c10c78e2d9bb4f66ba803579f747a93bb122df7dbe

See more details on using hashes here.

Provenance

The following attestation bundles were made for logic_jena-0.1.0rc4-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