Skip to content

Add finite state projection example #1269

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

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open

Add finite state projection example #1269

wants to merge 15 commits into from

Conversation

TorkelE
Copy link
Member

@TorkelE TorkelE commented May 16, 2025

An example of how to simulate the CME using FiniteStateProjection.jl.

I trialled having a collapsed "quick-start" example at the beginning (in the same way we had the environment set up in the CRN example library doc page).

Copy link
Member

@isaacsas isaacsas left a comment

Choose a reason for hiding this comment

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

Should we add a collapsible "installation instructions" too?

Have you double checked you have the axes correct on the heatmaps? (Sometimes some libraries flip the x and y axes I recall.)

It might be nice to also make the SS heatmap by running SSAs? That would be a nice comparison to show one gets the same result.

Finally, you probably want to pass vectors that label the X and Y ticks in the heatmaps, as otherwise I think they might start plotting at 1 and not zero. (Maybe plot the initial condition to confirm it looks ok and is labeled right?)

Comment on lines 41 to 48
```math
\begin{aligned}
\frac{dp(x=0)}{dt} &= f_0(p(x=0), p(x=1), ...) \\
\frac{dp(x=1)}{dt} &= f_0(p(x=0), p(x=1), ...) \\
\frac{dp(x=2)}{dt} &= f_0(p(x=0), p(x=1), ...) \\
&\vdots\\
\end{aligned}
```
Copy link
Member

Choose a reason for hiding this comment

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

This is just wrong. In this notation the ODE rhs are all identical... I'd suggest just writing the general chemical master equation as in the math model description (or using that form but replacing vector X/x by scalars).

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you mean
image
?

My intention was basically just to sketch what it looked like in a way which clearly showed that it was infinite (although messing up the f indexing doesn't really help...)

Copy link
Member

Choose a reason for hiding this comment

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

I meant to mimic https://docs.sciml.ai/Catalyst/stable/introduction_to_catalyst/math_models_intro/#Stochastic-Chemical-Kinetics-Jump-Process-Models where I give the general formula for it (or at least cite that for the general formula for it, and then give it for something like $0 \to A \to 0$ using $P(a,t)$ if you want a simple example that is infinite.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds good. And we should definitely reference that section as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have changed to it explicitly be for a bd process (p,d) 0 <--> X, and linked the main bit about the CME.

TorkelE and others added 4 commits May 20, 2025 21:54
Co-authored-by: Sam Isaacson <isaacsas@users.noreply.github.com>
Co-authored-by: Sam Isaacson <isaacsas@users.noreply.github.com>
Co-authored-by: Sam Isaacson <isaacsas@users.noreply.github.com>
Co-authored-by: Sam Isaacson <isaacsas@users.noreply.github.com>
@TorkelE
Copy link
Member Author

TorkelE commented May 20, 2025

Should we add a collapsible "installation instructions" too?

Sounds good, will add it.

Have you double checked you have the axes correct on the heatmaps? (Sometimes some libraries flip the x and y axes I recall.)

Yes (I made a really skewed case and checked that the distribution ended up at the right side). It does flip from what one would expect. However, we probably should add an !!! warning statement explicitly pointing this out (as it is not obvious for someone just skimming the tutorial).

It might be nice to also make the SS heatmap by running SSAs? That would be a nice comparison to show one gets the same result.

Basically just running a long SSA, and plotting the distribution of all values (after some initial time interval where it approaches the steady state? That would make sense.

Finally, you probably want to pass vectors that label the X and Y ticks in the heatmaps, as otherwise I think they might start plotting at 1 and not zero. (Maybe plot the initial condition to confirm it looks ok and is labeled right?)

Definitely, I will update to do this.

@isaacsas
Copy link
Member

I was thinking to just run many simulations to a fixed (large enough) time and then calculating the distribution at that time, but you can use the time series too (but that is usually more work to properly construct the distribution from).

@TorkelE
Copy link
Member Author

TorkelE commented May 20, 2025

Sounds good. I will check the simulation time of a few 100 Gillespie simulations, and if that is not noteworthy (should be very quick) I will use that.

@isaacsas
Copy link
Member

Don't forget to only save the final value once you've determined what time things look stationary at.

@TorkelE
Copy link
Member Author

TorkelE commented May 20, 2025

will do, sounds like a good oppertunity to make this point generally (and show of a nice feature of the ensemble simulation interface).

@TorkelE
Copy link
Member Author

TorkelE commented May 21, 2025

The main example is updated and should be ready, however, an unrelated doc page has started failing. Will have to figure out why.

@TorkelE
Copy link
Member Author

TorkelE commented May 22, 2025

The error has been reported in SciML/SciMLSensitivity.jl#1212

@isaacsas
Copy link
Member

Should we comment out that doc for now to get the build here working and merged? We can open a tracking issue on it to add that tutorial back later once it is fixed.

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