-
Notifications
You must be signed in to change notification settings - Fork 7
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
a sometimes failing concurrency test #1712
Conversation
This is good. We removed R altogether from this issue. |
Nice 🙂 |
fun to debug :) This writes the xmls which are passed to SimModel for calculation. Now when some simulations do not retrieve any results: this output variable is set as non-persistable! Here the xmls of a failing run: simulation 27 is the one with persistable = 0 So what happens: SimModel sometimes becomes an input with 0 required outputs, calculates and returns empty set of outputs, because none of the outputs is marked as to be returned. |
SO GOOD @Yuri05 |
once again, bug reports go in to SimModel and then bounce straight back out. Thanks @Yuri05 |
So we are already creating a new instance of the simulation exporter
So the quick fix that I was hoping is not happening |
Ok I think I have it.... |
/// Return a clone of the simulation that can be used during batch run. | ||
/// This simulation will contain the minimal information required to run. Configuration settings such as some building blocks will not be copied over | ||
/// </summary> | ||
/// <param name="simulation"></param> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That can be removed. You really just wanted the summary here I guess.
// Initialize a BuildConfiguration with only SimulationSettings because some of the properties to complete the initialization are required | ||
BuildConfiguration = new BuildConfiguration | ||
{ | ||
SimulationSettings = _cloneManagerForModel.Clone(simulationToClone.SimulationSettings) | ||
} | ||
}; | ||
|
||
// Initialize a BuildConfiguration with only SimulationSettings because some of the properties to complete the initialization are required | ||
// None of the other properties are required to complete the simulation | ||
var simulationBuildConfiguration = new BuildConfiguration | ||
{ | ||
SimulationSettings = _cloneManagerForModel.Clone(simulationToClone.SimulationSettings) | ||
}; | ||
simulation.BuildConfiguration = simulationBuildConfiguration; | ||
|
||
//Once we prepare a simulation for a batch, we are assuming that it won't be changed by the caller. | ||
//We update the persistable at this stage to avoid any possible thread problems | ||
_simulationPersistableUpdater.UpdateSimulationPersistable(simulation); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so the problem was that cloning did not properly copy the simulation settings and thus the curve was not set as persistable?
But why did it happen only sometimes and not every time?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No that's not it. I put it there because it's an implementation details that needs to happen as we are about to start the simulation run.
Befote, it was done in the initialize of the batch, which was using the clone already. However it was the same instance shared amongst all run of the batch. as this was happening in //, there was potentially a moment where one batch would cleaer the output to set them again, but the other one was done and was generating XML..
Anyways this line was added to fix another bug and I remembered not being too happy about doing it that way but I didn't find anything better. Now that we have a place to clone the simulation, this felt to me like the right location
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I see. cool, cool :)
@@ -25,7 +25,7 @@ public class ConcurrentRunSimulationBatch : IDisposable, IWithId | |||
|
|||
public ConcurrentRunSimulationBatch(IModelCoreSimulation simulation, SimulationBatchOptions simulationBatchOptions) | |||
{ | |||
Simulation = Api.GetSimulationTask().Clone(simulation); | |||
Simulation = Api.GetSimulationTask().CloneForBatchRun(simulation); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rwmcintosh @Yuri05 I have renamed this guy because we are not creating a real clone
Just one that is enough to calculate
} | ||
|
||
public void Initialize(IModelCoreSimulation simulation, SimulationBatchOptions simulationBatchOptions) | ||
{ | ||
_simulationPersistableUpdater.UpdateSimulationPersistable(simulation); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was the culprit. It is resetting the simulations output and then setting them again. This call is NOT thread safe and was called in mult thread environment
|
||
//Once we prepare a simulation for a batch, we are assuming that it won't be changed by the caller. | ||
//We update the persistable at this stage to avoid any possible thread problems | ||
_simulationPersistableUpdater.UpdateSimulationPersistable(simulation); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am doing it here. As soon as we cloen the simulation (for batch), I am making it also up to date as far as output selection is concerned. It is similar to what we do in normal run where we update before we reun
@@ -165,6 +228,7 @@ public override void GlobalContext() | |||
{ | |||
base.GlobalContext(); | |||
_simulation = _simulationPersister.LoadSimulation(HelperForSpecs.DataFile("S1.pkml")); | |||
_simulationPersistableUpdater.UpdateSimulationPersistable(_simulation); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not know why this was required . The test is bypassing the runner and calling directly the underlying stuff so that's probably why
// Initialize a BuildConfiguration with only SimulationSettings because some of the properties to complete the initialization are required | ||
BuildConfiguration = new BuildConfiguration | ||
{ | ||
SimulationSettings = _cloneManagerForModel.Clone(simulationToClone.SimulationSettings) | ||
} | ||
}; | ||
|
||
// Initialize a BuildConfiguration with only SimulationSettings because some of the properties to complete the initialization are required | ||
// None of the other properties are required to complete the simulation | ||
var simulationBuildConfiguration = new BuildConfiguration | ||
{ | ||
SimulationSettings = _cloneManagerForModel.Clone(simulationToClone.SimulationSettings) | ||
}; | ||
simulation.BuildConfiguration = simulationBuildConfiguration; | ||
|
||
//Once we prepare a simulation for a batch, we are assuming that it won't be changed by the caller. | ||
//We update the persistable at this stage to avoid any possible thread problems | ||
_simulationPersistableUpdater.UpdateSimulationPersistable(simulation); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No that's not it. I put it there because it's an implementation details that needs to happen as we are about to start the simulation run.
Befote, it was done in the initialize of the batch, which was using the clone already. However it was the same instance shared amongst all run of the batch. as this was happening in //, there was potentially a moment where one batch would cleaer the output to set them again, but the other one was done and was generating XML..
Anyways this line was added to fix another bug and I remembered not being too happy about doing it that way but I didn't find anything better. Now that we have a place to clone the simulation, this felt to me like the right location
Damm I had written all those comments yesterday in the PR and forgot to submit review. I HATE THIS FEATURE IN GITHUB |
going to merge now. I think this will solve all our issues |
Awesome. Once PK-Sim is updated, we should also update Core in R and should be able to use simulation batches again. |
@Yuri05 @msevestre @PavelBal
When I run this test it will fail similarly often to the R code that inspired it.
The SequenceEqual test is checking that all the sequences are identical besides any from failing runs.