Repository navigation
Warn when MartInverter runs on the methods of the instrument, and why - #52
Merged
Merged
Conversation
`MartInverter` runs on the sparse matrices of the instrument when it
can, and otherwise on the `image` and `backproject` methods of the
instrument, without a word. The methods are much slower: on the model
of the 2019 flight of ESIS, four iterations took 1.0 s on the matrices
and 17.7 s on the methods, and on the MART tutorial of esis an
iteration takes 0.13 s on the matrices and 10.3 s on the methods. An
inversion which leaves the matrices, for a reason which nothing says,
can look like one which hangs.
It now warns when it runs on the methods, with the reason that it
cannot run on the matrices, such as
This inversion runs on the `image` and `backproject` methods of the
instrument, which is slower than on its sparse matrices: the
instrument provides none, since its sensor responds differently
from pixel to pixel.
Each place which gives up on the matrices gives its reason, in place
of `None`. The inverter gives one for a subclass which replaces a
merit function, for images which are not a stack of frames, and for
images or a guess which cannot be expressed as plain arrays. The
instrument gives one for whatever of it cannot be expressed as its
matrices: its weights, the vertices of its grids, its quantum yield or
the response of its sensor, its read noise. `_operators_reason` hands
it on.
The reason that an array cannot be expressed as a plain array, such as
"has the axis 'time', which is not one of ('channel', 'x')", comes from
`unaligned`, the twin of `aligned` among the helpers of the operators.
The warning is a `UserWarning`, which points at the call of the
inverter. The error which refuses single precision where the matrices
cannot be used gives the same reason, in place of a list of the
reasons it could be.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01StcJvVHMXbjJmyFFwf4Pcn
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #52 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 29 29
Lines 4292 4437 +145
==========================================
+ Hits 4292 4437 +145
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Follows the review of the pull request. `aligned` makes its checks through `unaligned`, so what `unaligned` says of an array is why `aligned` refused it, and the two cannot drift apart. `vertices` gives the reason that a component of a grid cannot be expressed as a plain array, so an instrument whose scene is in a unit which cannot be converted to that of its sensor says so, where it was said to have a grid with an axis of its own. `_operators_reason` takes `None` for the precision that the matrices are kept in, as `_operators` does, and gives the reason of that precision, where it gave "it does not define any". `MartInverter` refuses `dtype=None`, which `numpy.dtype` takes for double precision, and which reached `_operators` as the precision kept. The warning comes as soon as the inversion is known to leave the matrices, before the backprojection of the first frame on the methods of the instrument, which can take long for a large one. The error for images with more than one element along an axis of the instrument or of the scene gives the reason that the inversion left the matrices, where it said that the instrument cannot be expressed as them, which is not the reason for images with an axis of the scene. The reason of a sensor whose ratio of the variance to the signal strays too far keeps the digits of a tolerance below a tenth of a percent, and the tests which count the warnings of an inversion count those of the inverter alone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01StcJvVHMXbjJmyFFwf4Pcn
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
MartInverternow warns when an inversion runs on theimageandbackprojectmethods of the instrument, in place of its sparse matrices, and says why:An inversion which runs on the matrices gives no warning.
Why
The inverter leaves the matrices for the methods without a word, and the methods are much slower: on the model of the 2019 flight of ESIS, four iterations took 1.0 s on the matrices and 17.7 s on the methods, and on the MART tutorial of esis an iteration takes 0.13 s on the matrices and 10.3 s on the methods.
An inversion which leaves the matrices, for a reason which nothing says, can look like one which hangs, and the reason is often a detail of the instrument or of the guess which is easy to change once it is known.
Changes
None:MartInverter._arrays: a subclass which replaces a merit function, images which are not a stack of frames, and images or a guess which cannot be expressed as plain arrays, such as a guess in units of energy for matrices which do not take one,AbstractLinearInstrument._operators_new,IdealInstrument._factorsandOptikaInstrument._factors: whatever of the instrument cannot be expressed as its matrices, such as weights with an axis of their own, a grid in a unit which cannot be converted to that of the sensor, a quantum yield which varies with wavelength, or a sensor whose response varies from pixel to pixel or is not proportional to the light.AbstractInstrument._operators_reasongives the reason that an instrument provides no matrices, in a precision, or in the one they are kept in. An instrument which cannot provide them keeps its reason where it would keep them, so the reason costs nothing once they have been asked for.unaligned, among the helpers of the operators: the reason thatalignedcannot express a named array as a plain array, such ashas the axis 'time', which is not one of ('channel', 'x').alignedmakes its checks through it, so the two cannot drift apart.verticesgives the reason of the component of a grid which cannot be expressed.MartInverter.__call__gives the warning, as aUserWarningwhich points at the call of the inverter, as soon as the inversion is known to run on the methods, before any work on them.MartInverterrefusesdtype=None, whichnumpy.dtypetakes for double precision and_operatorsfor the precision kept.The warning is a
UserWarning. A category of its own would let a caller silence it alone, but it would be a new public name of the package, so it is left out here.Review
The review of this pull request found that the reason of the precision kept was lost for
dtype=None, that the reason of the vertices of a grid named one cause for several, that the warning came after the backprojection of a frame on the methods, and that the error for images which are not frames blamed the instrument.The second commit fixes those.
Tests
The tests of each place which gives up on the matrices now check the reason it gives:
IdealInstrumentand ofOptikaInstrument, for every instrument which provides none, check_operators_reason, and that an instrument which provides them gives none,test_aligned_unsupportedchecks whatunalignedsays of each array whichalignedcannot express, andtest_unalignedthat it says nothing of one which it can,MartInverteron the methods of the instrument check the warning and its reason, for each reason which the inverter or the instrument can give, and the tests of single precision check the reason in the error.Four tests are new:
test_optika_operators_response_axis: the reason of an instrument whose sensor responds along an axis of its own,test__call__operators_silent: an inversion on the matrices gives no warning,test__call__operators_undefined: an instrument which defines no matrices is inverted on its methods, with a warning which says so, and the warning of the limit of the iterations still follows it,test__call__axis_scene_many: images with more than one element along an axis of the scene are refused, with the reason that they cannot run on the matrices.Run with this warning turned into an error, so that no inversion gives it where a test does not expect it, 598 tests pass, with every line covered.
🤖 Generated with Claude Code
https://claude.ai/code/session_01StcJvVHMXbjJmyFFwf4Pcn