Repository navigation
Build the matrices of a linear instrument one wavelength at a time - #54
Merged
Merged
Conversation
`AbstractLinearInstrument` assembled its forward matrix from the weights of the whole scene at once, and transposed it into the backprojection on first use. At the production grid of ESIS that fits two spectral lines on a 128 GB host, not the seven of the flight model, which would peak at about 134 GB. Both matrices are now built together with `regridding.RegridderBuilder`, in two passes over blocks of weights: the first computes each block and counts its entries, the second computes it again and places it, with its grids, in the forward matrix and in its conservative transpose. A block is every channel of one wavelength of one spectral line, so the weights of the whole scene are never held at once. - `IdealInstrument` and `OptikaInstrument` give the weights, the grids and the input weights of a block on demand (`_weights_block()`, `_grids_weights()` and `_weights_input()`). `OptikaInstrument` asks optika for the weights of the scene of the block alone. - `Operators` takes the backprojection as a field, built in the same pass, and no longer keeps the grids to transpose the forward matrix. - `_operators.piece()` and `_operators.dimensionless()` replace `_operators.regridder()`: the first turns a block of weights into the arguments of the builder, and the second makes the unit of a matrix dimensionless, or says that it cannot. - Weights the instrument cached for the named arrays are released before the matrices are built, so that they need not fit beside them. - regridding 3.8 is required, the first release with `RegridderBuilder`. Both matrices are bit for bit what `Regridder.from_weights()` and `Regridder.transpose_conservative()` give on the weights of the whole scene, once exact zeros are dropped, in float64 and float32. MART gives the same results as before, bit for bit, on the benchmark problems of the roadmap. The seven lines of ESIS at production build in 7.4 to 7.9 minutes, with a peak of 58 GB. The roadmap marks the host half of M6 done. 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 #54 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 29 29
Lines 4437 4655 +218
==========================================
+ Hits 4437 4655 +218
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:
|
The review of the matrices built a block at a time found these: - An input with one element along the wavelengths or the spectral lines, such as a point-spread function which broadcasts along them, was sliced past its end, so every block after the first had no entries, without an error. Such an input is now kept whole along that axis, as it broadcasts against the whole instrument, and a vector whose components differ in that way is broadcast to its own shape before it is sliced. - `OptikaInstrument` evaluates its whole system for each block, so a system which varies along the spectral lines, such as one with a distortion for each line, was not sliced with the scene, and the instrument fell back on the named arrays, or raised. Every block now holds whole any axis along which the system varies. - A subclass which defines the factors around the operators, but not the methods which compute its weights and their grids a block at a time, raised `NotImplementedError`, and now gets a reason. - Weights in a unit which is not dimensionless are refused from the first block, by `_operators.unit_weights()`, instead of after both passes, and `_operators.dimensionless()` raises for them. - Weights which were computed before are released only once the operators are known to be assembled, so an instrument which cannot provide them keeps its weights for the named arrays. - `_blocks()` uses `na.ndindex()`, and `_scene_block()` takes any slice which `piece()` takes. The roadmap marks #40 and #41 released in 0.6.0, and gives this pull request a row of its own. 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.
AbstractLinearInstrumentassembled its forward matrix from the weights of the whole scene at once, and transposed it into the backprojection on first use. At the production grid of ESIS that fits two spectral lines on a 128 GB host, but not the seven of the flight model, which would peak at about 134 GB.This PR builds both matrices together with
regridding.RegridderBuilder(sun-data/regridding#75, released in regridding 3.8.0), in two passes over blocks of weights:A block is every channel of one wavelength of one spectral line, so the weights of the whole scene are never held at once. This is the host half of M6 of the roadmap.
Changes
IdealInstrumentandOptikaInstrumentprovide the weights, grids and input weights of a block on demand, through_weights_block(),_grids_weights()and_weights_input().IdealInstrumentslices its coordinates and point-spread function. An input with one element along the wavelengths or the spectral lines is kept whole, since it broadcasts against every block.OptikaInstrumentasks optika for the weights of that block's part of the scene only. Every block holds whole any axis along which the optika system varies, such as a distortion for each spectral line, since the system is evaluated whole for each block.Operatorsgets the backprojection as a field, built in the same pass. It no longer keeps the grids it needed to transpose the forward matrix later._operators.piece(),_operators.unit_weights()and_operators.dimensionless()replace_operators.regridder().piece()turns a block of weights into the arguments of the builder.unit_weights()gives the unit of a block of weights, so that weights in a unit that isn't dimensionless are refused on the first block, before either pass.dimensionless()folds a dimensionless unit, such as a percentage, into the entries of a matrix.RegridderBuilder.A block per wavelength, not per line
The first version built a block for each spectral line. At production that was just as fast and peaked just as high (466 s, 54.1 GiB), but a scene of one band is then a single block. The PSF tutorial, which the docs build runs within Read the Docs' 7 GB, then peaked at 6.30 GiB, against 5.21 GiB on main. A block for each wavelength brings it down to 4.76 GiB.
Checks
New test
test__operators_at_oncechecks both matrices bit for bit againstRegridder.from_weights()andRegridder.transpose_conservative()on the weights of the whole scene, once exact zeros are dropped. It covers every case ofIdealInstrumentandOptikaInstrument, in float64 and float32.The same comparison covers a point-spread function with one element along the wavelengths and the lines, a coordinate with one element along the lines, and an optika system with a distortion or a field stop for each spectral line.
New test
test__operators_blockschecks that the weights of each block are computed twice, once in each pass, and that no weights stay cached.Other new tests check that the unit of the weights is refused after one block, that an instrument which falls back keeps its weights, and that a subclass without the block methods gets a reason.
On the benchmark problems of the roadmap, MART gives the same images, solutions, ⟨χ²⟩ and iteration counts as main, bit for bit, in float64 and float32:
At production, over two runs: seven spectral lines of the ESIS flight model at 0.75″ with 24 velocity bins, in float32. The lines were He I 584, O III 600, He II 304 in second order, O IV 608, Mg X 609, Mg X 625 and O V 630.
635 tests pass, with 100% coverage of the two changed modules, and black and ruff are clean.
The bit-for-bit match holds on sensors whose pixels form a uniform lattice, which every
OptikaInstrumentand every tutorial has. On any other sensor grid, regridding perturbs the grid with a random draw whose shape depends on the grid's, so a block's draw is not a slice of the whole scene's, and the matrices differ from the whole-scene weights by about 3e-7 in the images.Roadmap
regridding.RegridderBuilderand the measurements above, and marks Fit the distortion with a linearized merit, and align the channels esis-mission/esis#91 merged.MartInverteron sparse matrices and compiled code #40 and RunMartInverteron sparse matrices forOptikaInstrument, and add an axis for spectral lines #41 as released in 0.6.0, and gives this PR its own row.Not in this PR
🤖 Generated with Claude Code
https://claude.ai/code/session_01StcJvVHMXbjJmyFFwf4Pcn