# Standalone object oriented simulator implementation not working with joblib

**URL:** <https://brian.discourse.group/t/standalone-object-oriented-simulator-implementation-not-working-with-joblib/1464>\
**Category:** Support\
**Tags:** cpp\_standalone, parallel\
**Created:** [16 June 2025 10:02 UTC](https://brian.discourse.group/t/standalone-object-oriented-simulator-implementation-not-working-with-joblib/1464 "2025-06-16T10:02:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![danielmk](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/danielmk/32/661_2.png) [@danielmk](https://brian.discourse.group/u/danielmk)\
**Post date:** [16 June 2025 10:02 UTC](https://brian.discourse.group/t/standalone-object-oriented-simulator-implementation-not-working-with-joblib/1464/1 "2025-06-16T10:02:40Z")

</div>

# Description of problem

I have a functioning standalone simulator but it does not work with joblib because my simulator is implemented in an object oriented way. I am trying to figure out how to make it work without completely changing the implementation. [I am aware of this example](https://brian2.readthedocs.io/en/2.7.1/examples/multiprocessing.03_standalone_joblib.html) and I basically need the object oriented version of it.

# Minimal code to reproduce problem

I can’t provide minimal code but this pseudo code should illustrate the issue:  
The simulator runs like this:

```auto
simulator = Simulator()

parameters = [1, 2, 3]

result = simulator.run(parameters)

```

Internally, `Simulator()` creates and compiles the network and `simulator.run(parameters)` parses the parameters and uses `b2.device.run(run_args=run_args)` to run the simulation. This works generally well but causes problems with joblib. As I understand it, the fundamental issue is that each job needs its own compiled version of the code. So `Simulator()` needs to create not one but `n_job` simulators. Deciding how many jobs there should be at simulator instantiation time is no problem. `Simulator` has a `self.make_network()` method and I will simply call it `n_job` times. But the above example uses `os.getpid()`, and I will only know the `pid` when I pass simulator.run() to joblib, so I cannot use it at instantiation time. Is there anything else I can use to make the jobs not interfere with each other? Any pointers/ideas would be appreciated.

---

<div class="post-metadata">

**Author:** ![mstimberg](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/mstimberg/32/11_2.png) [@mstimberg](https://brian.discourse.group/u/mstimberg)\
**Post date:** [16 June 2025 15:25 UTC](https://brian.discourse.group/t/standalone-object-oriented-simulator-implementation-not-working-with-joblib/1464/2 "2025-06-16T15:25:46Z")

</div>

Hi @danielmk. I just realized that the example you pointed to is a bit out of date, in the sense that one does not necessarily need one version of the compiled code per process anymore. Instead, it is enough to compile the code once, and specify separate directories for the results so that the actual run can be in parallel (using the `run_args` feature). This example demonstrates the approach: [Example: standalone\_multiple\_processes — Brian 2 0.0.post128 documentation](https://brian2.readthedocs.io/en/stable/examples/standalone.standalone_multiple_processes.html)

Would that work for you?

---

<div class="post-metadata">

**Author:** ![danielmk](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/danielmk/32/661_2.png) [@danielmk](https://brian.discourse.group/u/danielmk)\
**Post date:** [17 June 2025 05:17 UTC](https://brian.discourse.group/t/standalone-object-oriented-simulator-implementation-not-working-with-joblib/1464/3 "2025-06-17T05:17:21Z")

</div>

It worked with joblib! That’s my bad for not finding this example myself. I guess I missed it because I was specifically looking for joblib. I’ll still have to deploy to the cluster but so far speedup and everything looks good. Thanks.

---

<div class="post-metadata">

**Author:** ![mstimberg](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/mstimberg/32/11_2.png) [@mstimberg](https://brian.discourse.group/u/mstimberg)\
**Post date:** [17 June 2025 07:59 UTC](https://brian.discourse.group/t/standalone-object-oriented-simulator-implementation-not-working-with-joblib/1464/4 "2025-06-17T07:59:58Z")

</div>

Good to hear! I marked this as solved for now, but let us know if you run into issues on the cluster, of course.
