title: Is it possible to use callbacks to access a single trajectory in Julia's DifferentialEquations Ensemble Problems?
body: <p>I am new to Julia and trying to use the Julia package DifferentialEquations to simultaneously solve for several conditions of the same set of coupled ODEs. My system is a model of an experiment and in one of the conditions, I increase the amount of one of the dependent variables at mid-way through the process.</p>
  <p>I would like to be able to adjust the condition of this single trajectory, however so far I am only able to adjust all the trajectories at once. Is it possible to access a single one using callbacks? If not, is there a better way to do this?</p>
  <p>Here is a simplified example using the lorentz equations for what I want to be doing:</p>
  <pre><code>#Differential Equations setup
  function lorentz!(du,u,p,t)
      a,r,b=p
        
      du[1]= a*(u[2]-u[1])             
      du[2]=u[1]*(r-u[3])-u[2]
      du[3]=u[1]*u[2]-b*u[3];      
  end
  
  #function to cycle through inital conditions
  function prob_func(prob,i,repeat)
      remake(prob; u0 = u0_arr[i]);
  end
      
  #inputs
  t_span=[(0.0,100.0),(0.0,100.0)];
  u01=[0.0;1.0;0.0];
  u02=[0.0;1.0;0.0];
  u0_arr = [u01,u02];
  p=[10.,28.,8/3];
  
  #initialising the Ensemble Problem
  prob = ODEProblem(lorentz!,u0_arr[1],t_span[1],p);
  CombinedProblem = EnsembleProblem(prob,
                                      prob_func = prob_func, #-&gt; (prob),#repeat is a count for how many times the trajectories had been repeated
                                      safetycopy = true # determines whether a safetly deepcopy is called on the prob before the prob_func (sounds best to leave as true for user-given prob_func)
                                      );
      
  #introducing callback 
  function condition(u,t,repeat)
          return  50 .-t      
      end
  function affect!(repeat)
          repeat.u[1]=repeat.u[1] +50
      end
  callback = DifferentialEquations.ContinuousCallback(condition, affect!)  
  
  #solving
  sim=solve(CombinedProblem,Rosenbrock23(),EnsembleSerial(),trajectories=2,callback=callback);
   
  
  # Plotting for ease of understanding example
  plot(sim[1].t,sim[1][1,:])
  plot!(sim[2].t,sim[2][1,:])
  </code></pre>
  <p>I want to produce something like this:</p>
  <p><a href="https://i.stack.imgur.com/rjzYU.png" rel="nofollow noreferrer">Example_desired_outcome</a></p>
  <p>But this code produces:</p>
  <p><a href="https://i.stack.imgur.com/8qzCc.png" rel="nofollow noreferrer">Example_current_outcome</a></p>
  <p>Thank you for your help!</p>