Skip to content

not calling match_statevector on every write#911

Merged
pgbrodrick merged 3 commits into
isofit:devfrom
evan-greenbrg:multistate/match_statevector
Mar 19, 2026
Merged

not calling match_statevector on every write#911
pgbrodrick merged 3 commits into
isofit:devfrom
evan-greenbrg:multistate/match_statevector

Conversation

@evan-greenbrg

@evan-greenbrg evan-greenbrg commented Mar 12, 2026

Copy link
Copy Markdown
Collaborator

Low-hanging fruit for some potential gains.

Needs debugging and testing.

From some per-pixel profiling on the analytical line:

The highlighted field is the cumulative time. Run calls on far left is the same.

With the old match_statevector:
Screenshot 2026-03-12 at 11 09 18 AM

With these updates:
Screenshot 2026-03-12 at 11 11 05 AM

Looks like this is considerable (on the AV5 scene that we've been using as benchmark):

With change:

AOE:

INFO:2026-03-12,12:12:30 || analytical_line.py:analytical_line() | Analytical line inversions complete. 
 1121.75s total, 2209.0579 spectra/s, 34.5165 spectra/s/core

I've removed the highlights of the OE times. It looks like speed gain for OE is minor (altough there is some) compared to the AOE

Comment thread isofit/core/forward.py
x_instrument = x[self.idx_instrument]
return x_surface, x_RT, x_instrument

def match_statevector(self, full_statevector):

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

an unfortunate convenience putting this in fm. An alternative is to explicitly carry these lists in and out of scope as function args. My only concern with that is that fileio and analytical_line class workers gain two additional arguments to handle.

@pgbrodrick

Copy link
Copy Markdown
Collaborator

I tried this with the numba compilation we discussed as an alternative. Merged with the numagrid from dev, I got:

Presolve: 4.6881 spectra/s/core
Main solve: 0.7496 spectra/s/core
AOE: 22.75 spectra/s/core

In other words, right in-line with dev. I'm confirming I can match your result above - if so, then I think this can get converted and folded in.

bug fixes

Bugfix

missing self

JIT testing

JIT testing cont

Testing for match
@evan-greenbrg evan-greenbrg force-pushed the multistate/match_statevector branch from 2fca1d4 to 21fb112 Compare March 14, 2026 23:06
@github-actions

Copy link
Copy Markdown
📊 Generated results:

URL: isofit/isofit-test-results#10
SHA: df71c3b

@evan-greenbrg evan-greenbrg marked this pull request as ready for review March 16, 2026 22:02
@evan-greenbrg

evan-greenbrg commented Mar 16, 2026

Copy link
Copy Markdown
Collaborator Author

Updates concerning numba jit:

The loop syntax that is currently set up to match the statevector terms is not compatible with jit compilation:

    idx = []
    for fm_name in fm_statevec:
        for i, full_name in enumerate(full_statevec):
            if fm_name == full_name:
                idx.append(i)

The issue seems to be incompatible compilation with list(str)or np.ndarray(str) datatypes.

@evan-greenbrg

evan-greenbrg commented Mar 17, 2026

Copy link
Copy Markdown
Collaborator Author

Can reproduce across multiple scenes. Most recently an ANG scene:

This PR:

INFO:2026-03-16,17:06:25 || analytical_line.py:analytical_line() | Analytical line inversions complete.  368.34s tot
al, 2597.5996 spectra/s, 40.5875 spectra/s/core

dev:

INFO:2026-03-16,21:16:56 || analytical_line.py:analytical_line() | Analytical line inversions complete.  448.8s tota
l, 2131.9124 spectra/s, 33.3111 spectra/s/core

OE run time is not impacted:

This PR:

INFO:2026-03-16,16:56:56 || isofit.py:run() | Final totals
INFO:2026-03-16,16:56:56 || isofit.py:run() | 179.5s total
INFO:2026-03-16,16:56:56 || isofit.py:run() | 133.2502 spectra/s
INFO:2026-03-16,16:56:56 || isofit.py:run() | 2.082 spectra/s/core

dev:

INFO:2026-03-16,21:05:32 || isofit.py:run() | All Inversions complete.
INFO:2026-03-16,21:05:32 || isofit.py:run() | 185.01s total
INFO:2026-03-16,21:05:32 || isofit.py:run() | 129.2854 spectra/s
INFO:2026-03-16,21:05:32 || isofit.py:run() | 2.0201 spectra/s/core

@pgbrodrick

Copy link
Copy Markdown
Collaborator

Circling back after discussion - general agreement is that we do not see presolve or main solution speedup, but we do see a speedup in AOE. The exact speedup depends on the particulars...for AV5 (with CO2 included), we're seeing a 30% reduction, for ANG without CO2 about 25%. Either way, this is a clear win.

We do not see corresponding speed changes with numba, and there's debate about the compiler success - either way, we can accept the slight complexity increase for the clear speed win. Thanks @evan-greenbrg !

@pgbrodrick pgbrodrick merged commit 8f20be5 into isofit:dev Mar 19, 2026
35 of 48 checks passed
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.

2 participants