Skip to main content

cavsqueeze

Tests PyPI License DOI

cavsqueeze is a Python package for simulating and measuring spin squeezing in a large group of spins (atoms, ions or defects in a crystal) that all talk to one microwave or optical resonator (a cavity). Squeezing is a way of preparing the spins so that they measure a phase or a frequency more precisely than the same number of independent spins could. The package was developed for 171Yb3+:CaWO4 (ytterbium ions in a calcium tungstate crystal) and applies to any spin ensemble coupled to a resonator.

It answers these questions:

  • How much squeezing does a given cavity and spin ensemble produce, and after how long, once the real imperfections of a solid are included: a spread of spin frequencies, decay into the cavity, thermal photons, loss of coherence, and uneven coupling?
  • What does that squeezing buy a clock or a magnetometer?
  • Given shot-by-shot data from an experiment, how much squeezing was actually there, and with what error bar?
  • How many shots does a measurement need to reach a target error bar, before it is taken, also when the shots are not Gaussian? And how large is the error bar when the detector's noise is not Gaussian?
  • What coherence time T2 and line width do my own echo and Ramsey measurements give, so that I can put them into the model? Is my echo decay exponential, as the model assumes? And do my measured data actually follow the laws the fits assume?
  • Does my detector see the projection noise of the spins, and how much noise does it add? How large is the squeezing once that noise is removed, with the error of the calibration included?
  • When does the noise of the clock laser (the Dick effect) make squeezing useless?

The solver groups spins with the same frequency and coupling into classes. Its memory and running time grow with the number of classes, not with the number of spins: the state it stores has the same size for 10^3 spins as for 10^15 (example 2 uses 10^15). The main results are checked by automated tests against exact solutions, closed formulas and an independent second solver (see How the results are checked). When an input cannot give a meaningful answer, the package stops with an error that says why, rather than returning a number that looks fine but is not.

Install

pip install cavsqueeze          # core package
pip install cavsqueeze[exact]   # adds QuTiP, needed for cavsqueeze.exact and to_qutip

To run the tests from a copy of the source:

Units and conventions are listed in the guide.

A first look

1. How much squeezing does a cavity give, and when?

import numpy as np
from cavsqueeze import from_hz, homogeneous, optimal_squeezing

# Illustrative values, not a specific device.
N = 1e10                                   # number of spins
p = from_hz(g_hz=1e6 / np.sqrt(N),         # coupling of one spin (Hz)
            kappa_hz=1e4,                  # cavity linewidth (Hz)
            Delta_hz=30e6,                 # cavity-spin detuning (Hz)
            T=0.02,                        # temperature (K)
            T2=0.15)                       # spin coherence time (s)
best = optimal_squeezing(p, homogeneous(N), 1e-6, 1e-2)
print(f"best squeezing {10 * np.log10(best['xi2']):.2f} dB "
      f"after {best['t'] * 1e6:.1f} us, contrast {best['contrast']:.4f}")
best squeezing -23.59 dB after 124.3 us, contrast 0.9992

optimal_squeezing scans the twisting time between the two limits given (here 1 us to 10 ms), with an echo pulse in the middle, and returns the time with the smallest xi2_R. It first scans a coarse grid of 12 times spaced evenly on a log scale, then a finer linear grid between the neighbors of the best coarse point. best also holds the whole scan (scan_t, scan_xi2).

More in the examples.

Where to read on

  • Examples: 15 short examples, each with the output it prints.
  • Tutorials: complete analyses, from data to a result with error bars.
  • Words, units and conventions: the terms used here, explained in plain words, and every unit and sign convention.
  • What is in the package: every function, grouped by task.
  • How the results are checked: what each test compares with and how closely, and the mistakes fixed in earlier versions.
  • Limits: when the package refuses an input and why, and what it deliberately does not do.
  • CHANGELOG: what changed in each version.

Where it comes from

The package was developed for 171Yb3+:CaWO4 and applies to any spin ensemble coupled to a resonator. The physics, the conventions and the validation are described in: T. M. Mahim, M. M. Rahman, A. S. M. Mohsin, Synchronization sets the coherence and the squeezing limit of a spin ensemble in a cavity. The paper's companion repository, yb-cawo4-cavity-squeezing, contains the scripts, datasets and figures that reproduce the paper and is archived on Zenodo; this repository is the software's home for development, releases and support.

Other sources named in the code: Kitagawa and Ueda, Phys. Rev. A 47, 5138 (1993); Wineland et al., Phys. Rev. A 46, R6797 (1992); Sorensen et al., Nature 409, 63 (2001); Itano et al., Phys. Rev. A 47, 3554 (1993); Ludlow et al., Rev. Mod. Phys. 87, 637 (2015); G. J. Dick, Proc. PTTI 1987; G. Santarelli et al., IEEE Trans. Ultrason. Ferroelectr. Freq. Control 45, 887 (1998); A. Quessada et al., J. Opt. B 5, S150 (2003); Schulte et al., Nat. Commun. 11, 5955 (2020). The stretched echo form exp(-(2 tau/T_M)^x) is the one used, for example, by M. Le Dantec et al., arXiv:2106.14974 (2021), who cite T. Bottger, C. W. Thiel, Y. Sun and R. L. Cone, Phys. Rev. B 73, 075101 (2006).

Citing, support and license

Please cite the paper if you use this code. To cite the software, use the concept DOI 10.5281/zenodo.22278034, which always resolves to the latest release. Citation metadata is in CITATION.cff.

The package is maintained by Tanvir Mahmud Mahim (BRAC University), who reviews issues and pull requests; the scientific content is developed with the co-authors of the associated paper. Bug reports, questions and pull requests are welcome through GitHub issues; see CONTRIBUTING.md for the development setup and the testing requirements. Tagged releases are published to PyPI by CI.

Licensed under Apache-2.0 (see LICENSE).

Metadata

Release files for cavsqueeze 1.21.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cavsqueeze 1.21.1
File Size Uploaded Provenance Actions
cavsqueeze-1.21.1.tar.gz 194.7 kB With provenance Details for cavsqueeze-1.21.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cavsqueeze 1.21.1
File Interpreter ABI Platform Actions
cavsqueeze-1.21.1-py3-none-any.whl Python 3 none any Details for cavsqueeze-1.21.1-py3-none-any.whl

Total release size: 282.9 kB

Release files / cavsqueeze-1.21.1.tar.gz

Download URL cavsqueeze-1.21.1.tar.gz
Size 194.7 kB
Tags Source
SHA-256 checksum
How to use checksums
4e9b6d6cf1392e2e17b69295eac97292b54f60c10d964725cbcf74cedd1cfdd7
BLAKE2b-256 checksum
How to use checksums
48842f37dfce62724b8c7dbeca48817efda5649981d197ccbe7c7aceecfb0759
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 3, 2026.

Transparency log

Release files / cavsqueeze-1.21.1-py3-none-any.whl

Download URL cavsqueeze-1.21.1-py3-none-any.whl
Size 88.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d89fbe92003250647ce53d5be32f89452441cc3c13db3faff8d839911f4fdf22
BLAKE2b-256 checksum
How to use checksums
52cf2f664df9958aa54c73369e7ed08f003bf261f76f7531fdd64c3edbd9d8d1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 3, 2026.

Transparency log

Security for cavsqueeze 1.21.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for cavsqueeze-1.21.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 3, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page