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

Lbfgs box #131

Merged
merged 26 commits into from
Feb 27, 2024
Merged

Lbfgs box #131

merged 26 commits into from
Feb 27, 2024

Conversation

schuenke
Copy link
Collaborator

@schuenke schuenke commented Dec 12, 2023

closes #115

Copy link
Contributor

github-actions bot commented Dec 12, 2023

Coverage

Coverage Report
FileStmtsMissCoverMissing
src/mrpro/algorithms
   _adam.py13838%93–103
   _lbfgs.py14843%68, 85–94
   _remove_readout_os.py30293%46, 48
src/mrpro/data
   _AccelerationFactor.py13130%15–37
   _AcqInfo.py64198%93
   _Data.py15287%58, 73
   _DcfData.py82495%34, 75, 101, 189
   _IData.py57788%44, 49, 109, 114, 122, 128, 132
   _IHeader.py58297%86, 113
   _KData.py1111289%103–104, 200, 202, 232, 237–238, 282, 284, 288, 318, 334
   _KHeader.py125993%34, 82, 120, 171, 182, 189–190, 193, 200
   _KNoise.py21957%56–69
   _KTrajectory.py63297%228, 248
   _SpatialDimension.py39587%76, 79, 86–88
   _TrajectoryDescription.py14193%37
src/mrpro/data/traj_calculators
   _KTrajectoryCalculator.py26388%37, 63, 65
   _KTrajectoryIsmrmrd.py15287%55, 62
   _KTrajectoryPulseq.py33197%72
src/mrpro/operators
   _CartesianSamplingOp.py48981%58–59, 64–65, 70–71, 95, 98, 122
   _ConstraintsOp.py58297%34, 36
   _LinearOperator.py49884%37, 72, 80, 88–90, 106, 111
   _Operator.py43198%35
   _ZeroPadOp.py15193%45
src/mrpro/utils
   _rgetattr.py3167%20
   _zero_pad_or_crop.py30680%37, 41, 64, 67, 70, 73
TOTAL171211993% 

Tests Skipped Failures Errors Time
186 0 💤 0 ❌ 0 🔥 53.347s ⏱️

@fzimmermann89
Copy link
Member

Maybe we should copy the initial value tensor?

It might be unexpected that the tensor is changed during the runtime..

@fzimmermann89
Copy link
Member

mypy fails with:

src/mrpro/operators/_ConstraintsOp.py:22: error: Bad number of arguments, expected: at least 1, given: 0  [type-arg]
src/mrpro/operators/functionals/_mse_data_discrepancy.py:21: error: Bad number of arguments, expected: at least 1, given: 0  [type-arg]

the tests fail because of #174 (not our fault, also tracked on ismrmrd python repo)

@ckolbPTB
Copy link
Collaborator

ckolbPTB commented Feb 19, 2024

mypy fails with:

src/mrpro/operators/_ConstraintsOp.py:22: error: Bad number of arguments, expected: at least 1, given: 0  [type-arg]
src/mrpro/operators/functionals/_mse_data_discrepancy.py:21: error: Bad number of arguments, expected: at least 1, given: 0  [type-arg]

Can we use something like "# type: ignore [type-arg]" here to satisfy mypy if this is due to a problem in 3rd party code?

src/mrpro/algorithms/_adam.py Outdated Show resolved Hide resolved
src/mrpro/algorithms/_adam.py Outdated Show resolved Hide resolved
src/mrpro/algorithms/_adam.py Outdated Show resolved Hide resolved
src/mrpro/operators/_ConstraintsOp.py Outdated Show resolved Hide resolved
src/mrpro/operators/_ConstraintsOp.py Outdated Show resolved Hide resolved
src/mrpro/operators/functionals/_mse_data_discrepancy.py Outdated Show resolved Hide resolved
@fzimmermann89
Copy link
Member

fzimmermann89 commented Feb 23, 2024

  • There are some typing issues I think. The operator types are not optimal, see my comments above.
    The functionals can be typed as returning only a single tensor.
  • softplus can soon take in a float in pytorch. I reported the bug in their typing (the code always worked with float) and it got fixed. maybe we can already type beta as float and set #type: ignore SOMETHING to ignore the error ..

Otherwise, I think the code makes sense. You also convinced my that it makes sense to have the with pytest.raises there as a reminder to remove it once this line does not raise an error any more.

@fzimmermann89
Copy link
Member

fzimmermann89 commented Feb 24, 2024

I addressed some of the review comments regarding the comments ( ;-) ) and added tests for what I think should be illegal bounds.

        ((1.0, -1.0), (-1.0, 1.0)),  # first one is invalid
        ((-1.0, 1.0), (1.0, -1.0)),  # second one is invalid
        ((1.0, 1.0),),   ### QUESTION: IS THIS VALID OR INVALID? ####
        ((torch.nan, 1),),
        ((-1, torch.nan),),
        ((torch.inf, -torch.inf),),

Some of these seem not to raise an exception in the constraintOp. If they are actually valid, feel free to remove them from the test.
Also, do we want to allow inf and -inf for bounds? This feels (for me) more natural to write than None for an unbounded variable.

@koflera koflera merged commit 19b264b into main Feb 27, 2024
7 checks passed
@fzimmermann89
Copy link
Member

@koflera :
Maybe clean up the commit message next time you merge a PR...

@ckolbPTB ckolbPTB deleted the lbfgs_box branch February 28, 2024 09:50
fzimmermann89 added a commit that referenced this pull request Nov 10, 2024
* NUFFT

* created NonLinearOperator template

* first lbfgs with test

* changed input of lbfgs to list of params

* lbfgs raises error for complex-valued tensors

* fixed lbfgs; added adam with sat-recov example for ellipse phantom

* fixed tests; removed warning

* addressed review points

* fixed docstring in mse class

* test

* fertig

* addressed final reviews

* fixed mypy complain

* removed pytestwarning comment

* deleted phantom and commented pytest warning

* fixed mse type hint; updated adam and lbfgs docstrings

* add test for invalid bounds and address review commnts

* rename contraintop test file

* fix error introduced by me...

* fix typo in comment

* allow neginf/posinf as bounds

---------

Co-authored-by: koflera <[email protected]>
Co-authored-by: koflera <[email protected]>
Co-authored-by: Felix <[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.

Model fitting for qMRI
4 participants