Skip to content

Conversation

@sunxd3
Copy link

@sunxd3 sunxd3 commented Aug 20, 2025

No description provided.

@alexandrebouchard
Copy link
Member

Thanks! Triggering the CI just now...

@sunxd3
Copy link
Author

sunxd3 commented Sep 1, 2025

@alexandrebouchard could you trigger the CI again?

@alexandrebouchard
Copy link
Member

For sure! Thank you so much for your help with this. Started now, fingers crossed it passes.

@sunxd3
Copy link
Author

sunxd3 commented Oct 6, 2025

@alexandrebouchard sorry for taking a bit of time on this one. Could you add me as a contributor so CI can trigger automatically? No pressure, happy to push this forward even if not, also happy to be removed later.

@alexandrebouchard
Copy link
Member

Great idea! I discussed with the team and everyone welcomes you with open arms. You should get an invite shortly, after that let me know if we need to tweak permissions to get the CIs to run for you.

@sunxd3
Copy link
Author

sunxd3 commented Oct 9, 2025

Tests other than MPI should be passing.

The issue with MPI stems from that, JuliaBUGS.BUGSModel has a field stores a function that is Base.evaled at compile time. This function perform much better than evaluation based on the graph, but: 1. not all BUGS model can be compiled into a Julia function 2. at the moment it only computes the log joint without tempering options.

This runtime generated function raises annoying complications with MPI. I tried to resolve it by changing how BUGSModel is serialized (essentially changing this line), but it hasn't resolve the issue.

I want to come back later and try to resolve it. In the meantime, maybe @miguelbiron can give some suggestions?

@alexandrebouchard
Copy link
Member

Ah! I understand the issue. We had similar problems in early prototypes with the Stan interface (for slightly different but related reason that the pointer to the dynamic library cannot be serialized). The solution we took was to serialize essentially the information needed to reload the Stan library

function Serialization.serialize(s::AbstractSerializer, instance::StanLogPotential{M, S, D, E}) where {M, S, D, E}
Serialization.writetag(s.io, Serialization.OBJECT_TAG)
Serialization.serialize(s, StanLogPotential{M, S, D, E})
# do not serialize model as it is transient (ccall stuff)
Serialization.serialize(s, instance.stan_file)
Serialization.serialize(s, instance.data)
Serialization.serialize(s, instance.extra_information)
end
function Serialization.deserialize(s::AbstractSerializer, type::Type{StanLogPotential{M, S, D, E}}) where {M, S, D, E}
stan_file = Serialization.deserialize(s)
immutable = Serialization.deserialize(s)
extra = Serialization.deserialize(s)
return StanLogPotential(stan_file, immutable.data, extra)
end

Relatedly, we also built a generic utility to handle similar cases, not sure if it is directly useful in this case but could at least be helpful for inspiration:

"""
Use when a target contains information that cannot
be serialized, e.g. FFT plans
(https://discourse.julialang.org/t/distributing-a-function-that-uses-fftw/69564)
so that the target is constructed just in time by each MPI node.
```
# in a script.jl:
struct MyTargetFlag end
import Pigeons.instantiate_target
Pigeons.instantiate_target(flag::MyTargetFlag) = toy_mvn_target(1)
# to run
pigeons(target = Pigeons.LazyTarget(MyTargetFlag()), on = ChildProcess(dependencies = ["script.jl"]))
```
"""
struct LazyTarget{FlagType}
flag::FlagType
end

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