Skip to content

PML-385: generator seed for Latent space of theQGAN - #291

Open
CassNot wants to merge 3 commits into
merlinquantum:release/0.4.1from
CassNot:PML-385-seed-qgan
Open

PML-385: generator seed for Latent space of theQGAN#291
CassNot wants to merge 3 commits into
merlinquantum:release/0.4.1from
CassNot:PML-385-seed-qgan

Conversation

@CassNot

@CassNot CassNot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds support for passing a dedicated torch.Generator to PhotonicGenerator.sample_latent() and PhotonicGenerator.generate()
This enables reproducible latent batches without advancing PyTorch’s global random-number generator
Backward compatibility is ensured.

Related Issue

PML-385

Type of change

  • Bug fix
  • New feature
  • Documentation update
  • Refactor / Cleanup
  • Performance improvement
  • CI / Build / Tooling
  • Breaking change (requires migration notes)

Proposed changes

Added the generator parameter to:

  • LatentDistribution.sample()
  • NormalLatent.sample()
  • PhotonicGenerator.sample_latent()
  • PhotonicGenerator.generate()

Preserved compatibility with custom latent distributions implemented before the new parameter existed.
Added tests covering:

  • Reproducibility with an explicit generator.
  • Preservation of global RNG state.
  • Generator support through generate().
  • Backward compatibility with legacy latent distributions.

Updated the QGAN documentation and photonic QGAN reproduction notes.

How to test / How to run

  1. Command lines
pytest tests/models/test_photonic_generator.py

Documentation

  • User docs updated (Sphinx)
  • Examples / notebooks updated
  • Docstrings updated
  • Updated the API

Checklist

  • PR title includes Jira issue key (e.g., PML-126)
  • "Related Jira ticket" section includes the Jira issue key (no URL)
  • Code formatted (ruff format)
  • Lint passes (ruff)
  • Static typing passes (mypy) if applicable
  • Unit tests added/updated (pytest)
  • Tests pass locally (pytest)
  • Tests pass on GPU (pytest)
  • Test coverage not decreased significantly
  • Docs build locally if affected (sphinx)
  • With this command: SPHINXOPTS="-W --keep-going -n" make -C docs clean html the docs are built without any warning or errors.
  • New public classes/methods/packages are added in the API following the methodology presented in other files.
  • Dependencies updated (if needed) and pinned appropriately
  • PR description explains what changed and how to validate it

@CassNot CassNot added this to the v0.4.1 milestone Jul 30, 2026
@CassNot CassNot added the bugfix label Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant