Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration to Poetry #257

Merged
merged 30 commits into from
Jul 18, 2023
Merged

Migration to Poetry #257

merged 30 commits into from
Jul 18, 2023

Conversation

ggulli
Copy link
Contributor

@ggulli ggulli commented Jul 12, 2023

Context:
This PR is responsible for migrating the dependencies management from pip to poetry. The goal is also to use Poetry for versioning, adopting as a single source of truth the version defined in the pyproject.toml file.

Description of the Change:

  • pyproject.toml and poetry.lock: these two files have been introduced to properly configure and lock the dependencies of the project. The version used by poetry for the lock file is 1.4.0.

  • requirements files: the requirements previously defined in the different requirements.txt files have been imported in pyproject.toml. The files have been removed from the project. The additional dependencies have been imported respectively under the groups dev (requirements-dev.txt) and doc (doc/requirements.txt). The versions imported are the ones previously defined in the requirements files. The only change introduced is related to a submodule of tensorflow to make it work between ARM/x86_64 architectures.

  • setup.py: the package configurations have been also imported in pyproject.toml. No change has been introduced in the different attributes such as authors, classifiers and so on. Probably some of the are out of date.

  • _version.py: some changes introduced to retrieve the package version from pyproject.toml.

  • Documentation: text changes introduced describing where poetry is now required to perform some actions. .readthedocs.yml has been also updated to build the documentation using poetry.

  • Makefile: commands to build or install the package updated to use poetry.

  • devcontainers: Dockerfile and script updated to use poetry.

  • CI: all GitHub Actions workflows have been updated to use Poetry. An additional change has been introduced in those workflows using a third party action to cancel previous runs, they now use a concurrency setting to do so.

Benefits:

  • Dependencies are now managed in a centralized location and locked.
  • Package build can be executed by Poetry.
  • Package versioning can be managed through Poetry version commands.

@codecov
Copy link

codecov bot commented Jul 12, 2023

Codecov Report

Merging #257 (a5594f8) into develop (73b2af6) will increase coverage by 0.03%.
The diff coverage is 100.00%.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #257      +/-   ##
===========================================
+ Coverage    77.69%   77.73%   +0.03%     
===========================================
  Files           53       53              
  Lines         4376     4383       +7     
===========================================
+ Hits          3400     3407       +7     
  Misses         976      976              
Impacted Files Coverage Δ
mrmustard/_version.py 100.00% <100.00%> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 73b2af6...a5594f8. Read the comment docs.

@ggulli ggulli marked this pull request as ready for review July 14, 2023 21:16
@ziofil
Copy link
Collaborator

ziofil commented Jul 14, 2023

Fantastic, thank you Gabriele!

Copy link
Collaborator

@ziofil ziofil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Collaborator

@zeyueN zeyueN left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥇 Looking great! Thanks @ggulli

Makefile Show resolved Hide resolved
.devcontainer/Dockerfile Show resolved Hide resolved
@ggulli ggulli merged commit 1f5762d into develop Jul 18, 2023
@ggulli ggulli deleted the sc-36004-migrate-to-poetry branch July 18, 2023 16:20
@ziofil ziofil mentioned this pull request Jul 26, 2023
ziofil added a commit that referenced this pull request Jul 26, 2023
# Release 0.5.0

### New features

* Optimization callback functionalities has been improved. A dedicated
`Callback` class is added which
is able to access the optimizer, the cost function, the parameters as
well as gradients, during the
optimization. In addition, multiple callbacks can be specified. This
opens up the endless possiblities
of customizing the the optimization progress with schedulers, trackers,
heuristics, tricks, etc.
  [(#219)](#219)

* Tensorboard-based optimization tracking is added as a builtin
`Callback` class: `TensorboardCallback`.
It can automatically track costs as well as all trainable parameters
during optimization in realtime.
  Tensorboard can be most conveniently viewed from VScode.
  [(#219)](#219)

  ```python
  import numpy as np
  from mrmustard.training import Optimizer, TensorboardCallback

  def cost_fn():
      ...
  
  def as_dB(cost):
      delta = np.sqrt(np.log(1 / (abs(cost) ** 2)) / (2 * np.pi))
      cost_dB = -10 * np.log10(delta**2)
      return cost_dB

  tb_cb = TensorboardCallback(cost_converter=as_dB, track_grads=True)

  opt = Optimizer(euclidean_lr = 0.001);
opt.minimize(cost_fn, max_steps=200, by_optimizing=[...],
callbacks=tb_cb)

# Logs will be stored in `tb_cb.logdir` which defaults to
`./tb_logdir/...` but can be customized.
# VScode can be used to open the Tensorboard frontend for live
monitoring.
# Or, in command line: `tensorboard --logdir={tb_cb.logdir}` and open
link in browser.
  ```

* Gaussian states support a `bargmann` method for returning the bargmann
representation.
  [(#235)](#235)

* The `ket` method of `State` now supports new keyword arguments
`max_prob` and `max_photons`.
Use them to speed-up the filling of a ket array up to a certain
probability or *total* photon number.
  [(#235)](#235)

  ```python
  from mrmustard.lab import Gaussian

# Fills the ket array up to 99% probability or up to the |0,3>, |1,2>,
|2,1>, |3,0> subspace, whichever is reached first.
# The array has the autocutoff shape, unless the cutoffs are specified
explicitly.
  ket = Gaussian(2).ket(max_prob=0.99, max_photons=3)
  ```

* Gaussian transformations support a `bargmann` method for returning the
bargmann representation.
  [(#239)](#239)

* BSGate.U now supports method='vanilla' (default) and 'schwinger'
(slower, but stable to any cutoff)
  [(#248)](#248)

### Breaking Changes

* The previous `callback` argument to `Optimizer.minimize` is now
`callbacks` since we can now pass
  multiple callbacks to it.
  [(#219)](#219)

* The `opt_history` attribute of `Optimizer` does not have the
placeholder at the beginning anymore.
  [(#235)](#235)

### Improvements

* The math module now has a submodule `lattice` for constructing
recurrence relation strategies in the Fock lattice.
There are a few predefined strategies in
`mrmustard.math.lattice.strategies`.
  [(#235)](#235)

* Gradients in the Fock lattice are now computed using the
vector-jacobian product.
This saves a lot of memory and speeds up the optimization process by
roughly 4x.
  [(#235)](#235)

* Tests of the compact_fock module now use hypothesis.
  [(#235)](#235)

* Faster implementation of the fock representation of `BSgate`, `Sgate`
and `SqueezedVacuum`, ranging from 5x to 50x.
  [(#239)](#239)

* More robust implementation of cutoffs for States.
[(#239)](#239)

* Dependencies and versioning are now managed using Poetry.
[(#257)](#257)

### Bug fixes

* Fixed a bug that would make two progress bars appear during an
optimization
  [(#235)](#235)

* The displacement of the dual of an operation had the wrong sign
  [(#239)](#239)

* When projecting a Gaussian state onto a Fock state, the upper limit of
the autocutoff now respect the Fock projection.
  [(#246)](#246)

* Fixed a bug for the algorithms that allow faster PNR sampling from
Gaussian circuits using density matrices. When the
cutoff of the first detector is equal to 1, the resulting density matrix
is now correct.

### Documentation

### Contributors
[Filippo Miatto](https://github.com/ziofil), [Zeyue
Niu](https://github.com/zeyueN),
[Robbe De Prins](https://github.com/rdprins), [Gabriele
Gullì](https://github.com/ggulli),
[Richard A. Wolf](https://github.com/ryk-wolf)
@ziofil ziofil mentioned this pull request Jul 26, 2023
sduquemesa added a commit that referenced this pull request Jul 27, 2023
# Release 0.5.0

### New features

* Optimization callback functionalities has been improved. A dedicated
`Callback` class is added which
is able to access the optimizer, the cost function, the parameters as
well as gradients, during the
optimization. In addition, multiple callbacks can be specified. This
opens up the endless possiblities
of customizing the the optimization progress with schedulers, trackers,
heuristics, tricks, etc.
  [(#219)](#219)

* Tensorboard-based optimization tracking is added as a builtin
`Callback` class: `TensorboardCallback`.
It can automatically track costs as well as all trainable parameters
during optimization in realtime.
  Tensorboard can be most conveniently viewed from VScode.
  [(#219)](#219)

  ```python
  import numpy as np
  from mrmustard.training import Optimizer, TensorboardCallback

  def cost_fn():
      ...
  
  def as_dB(cost):
      delta = np.sqrt(np.log(1 / (abs(cost) ** 2)) / (2 * np.pi))
      cost_dB = -10 * np.log10(delta**2)
      return cost_dB

  tb_cb = TensorboardCallback(cost_converter=as_dB, track_grads=True)

  opt = Optimizer(euclidean_lr = 0.001);
opt.minimize(cost_fn, max_steps=200, by_optimizing=[...],
callbacks=tb_cb)

# Logs will be stored in `tb_cb.logdir` which defaults to
`./tb_logdir/...` but can be customized.
# VScode can be used to open the Tensorboard frontend for live
monitoring.
# Or, in command line: `tensorboard --logdir={tb_cb.logdir}` and open
link in browser.
  ```

* Gaussian states support a `bargmann` method for returning the bargmann
representation.
  [(#235)](#235)

* The `ket` method of `State` now supports new keyword arguments
`max_prob` and `max_photons`.
Use them to speed-up the filling of a ket array up to a certain
probability or *total* photon number.
  [(#235)](#235)

  ```python
  from mrmustard.lab import Gaussian

# Fills the ket array up to 99% probability or up to the |0,3>, |1,2>,
|2,1>, |3,0> subspace, whichever is reached first.
# The array has the autocutoff shape, unless the cutoffs are specified
explicitly.
  ket = Gaussian(2).ket(max_prob=0.99, max_photons=3)
  ```

* Gaussian transformations support a `bargmann` method for returning the
bargmann representation.
  [(#239)](#239)

* BSGate.U now supports method='vanilla' (default) and 'schwinger'
(slower, but stable to any cutoff)
  [(#248)](#248)

### Breaking Changes

* The previous `callback` argument to `Optimizer.minimize` is now
`callbacks` since we can now pass
  multiple callbacks to it.
  [(#219)](#219)

* The `opt_history` attribute of `Optimizer` does not have the
placeholder at the beginning anymore.
  [(#235)](#235)

### Improvements

* The math module now has a submodule `lattice` for constructing
recurrence relation strategies in the Fock lattice.
There are a few predefined strategies in
`mrmustard.math.lattice.strategies`.
  [(#235)](#235)

* Gradients in the Fock lattice are now computed using the
vector-jacobian product.
This saves a lot of memory and speeds up the optimization process by
roughly 4x.
  [(#235)](#235)

* Tests of the compact_fock module now use hypothesis.
  [(#235)](#235)

* Faster implementation of the fock representation of `BSgate`, `Sgate`
and `SqueezedVacuum`, ranging from 5x to 50x.
  [(#239)](#239)

* More robust implementation of cutoffs for States.
[(#239)](#239)

* Dependencies and versioning are now managed using Poetry.
[(#257)](#257)

### Bug fixes

* Fixed a bug that would make two progress bars appear during an
optimization
  [(#235)](#235)

* The displacement of the dual of an operation had the wrong sign
  [(#239)](#239)

* When projecting a Gaussian state onto a Fock state, the upper limit of
the autocutoff now respect the Fock projection.
  [(#246)](#246)

* Fixed a bug for the algorithms that allow faster PNR sampling from
Gaussian circuits using density matrices. When the
cutoff of the first detector is equal to 1, the resulting density matrix
is now correct.

### Documentation

### Contributors
[Filippo Miatto](https://github.com/ziofil), [Zeyue
Niu](https://github.com/zeyueN),
[Robbe De Prins](https://github.com/rdprins), [Gabriele
Gullì](https://github.com/ggulli),
[Richard A. Wolf](https://github.com/ryk-wolf)

---------

Co-authored-by: Sebastián Duque Mesa <[email protected]>
Co-authored-by: JacobHast <[email protected]>
Co-authored-by: elib20 <[email protected]>
Co-authored-by: Luke Helt <[email protected]>
Co-authored-by: zeyueN <[email protected]>
Co-authored-by: Robbe De Prins <[email protected]>
Co-authored-by: Robbe De Prins (UGent-imec) <[email protected]>
Co-authored-by: Yuan <[email protected]>
Co-authored-by: Ryk <[email protected]>
Co-authored-by: Gabriele Gullì <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants