Saving model persistently

Everything related to the development of modules in jamovi
Post Reply
JavierMG
Posts: 9
Joined: Mon Feb 24, 2025 11:30 am

Saving model persistently

Post by JavierMG »

Hi,

I'm developing a module with some ML models which are computationally expensive. Is there a way to save the model so that it doesn't have to be retrained everytime I select a new plot/results option? I have tried the self$results$.setModel with a "property" type on the results file but everytime a new plotting option is selected, it turns to NULL. I have also played with the clearWith options but it doesn't prevent retraining either. Thank you in advanced.

Cheers,

Javier
sbalci
Posts: 148
Joined: Sat Jan 06, 2018 10:25 pm
Contact:

Re: Saving model persistently

Post by sbalci »

I assume this may help:
just after computationally expensive calculation add checkpoint

# Push results and check for user changes:
private$.checkpoint()

# If you only want to poll for changes without re-pushing identical results:
private$.checkpoint(flush = FALSE)
User avatar
MAgojam
Posts: 450
Joined: Thu Jun 08, 2017 2:33 pm
Location: Parma (Italy)

Re: Saving model persistently

Post by MAgojam »

Hey @JavierMG,
you can check it out here:
https://github.com/jamovi/jmv/blob/mast ... a.b.R#L525
where we use it as @sbalci suggests.
I've also put it here:
https://github.com/jamovi/jmv/blob/mast ... np.b.R#L52

So you can take a look at the code of the jmv analysis module elements.

Cheers,
Maurizio
https://www.jamovi.org/about.html
User avatar
jonathon
Posts: 2860
Joined: Fri Jan 27, 2017 10:04 am

Re: Saving model persistently

Post by jonathon »

if you want to persist values between runs, you need to store that value in state.

analyses are completely destroyed between runs, and often don't run in the same process twice, so the only way to store and restore is to use the state system.

https://dev.jamovi.org/tuts0203-state.html#setstate()

self$results$aResultsElementWithAppropriateClearWiths$setState(state)

state <- self$results$aResultsElementWithAppropriateClearWiths$state

but you need to be mindful of how large the objects are that are going into state (see the note on the state page).

jonathon
Post Reply