@@ -165,26 +165,32 @@ end
165
165
166
166
function run! (neuralFMU:: ME_NeuralFMU , batchElement:: FMU2SolutionBatchElement ; lastBatchElement= nothing , kwargs... )
167
167
168
- neuralFMU. customCallbacksAfter = []
169
- neuralFMU. customCallbacksBefore = []
168
+ if fmi2CanGetSetState (neuralFMU. fmu)
169
+ @assert ! neuralFMU. fmu. executionConfig. instantiate " Batching not possible for auto-instanciating FMUs."
170
+ # if the fmu can get and set its state then do this before simulating the neuralFMU:
171
+ neuralFMU. customCallbacksAfter = []
172
+ neuralFMU. customCallbacksBefore = []
170
173
171
- # STOP CALLBACK
172
- if ! isnothing (lastBatchElement)
173
- stopcb = FunctionCallingCallback ((u, t, integrator) -> copyState! (neuralFMU. fmu, lastBatchElement);
174
- funcat= [batchElement. tStop])
175
- push! (neuralFMU. customCallbacksAfter, stopcb)
176
- end
177
-
178
- if isnothing (batchElement. initialState)
179
- startcb = FunctionCallingCallback ((u, t, integrator) -> copyState! (neuralFMU. fmu, batchElement);
180
- funcat= [batchElement. tStart], func_start= true )
181
- push! (neuralFMU. customCallbacksAfter, startcb)
182
-
183
- c = getCurrentComponent (neuralFMU. fmu)
184
- FMI. fmi2SetContinuousStates (c, batchElement. xStart)
185
- FMI. fmi2SetTime (c, batchElement. tStart)
174
+ # STOP CALLBACK
175
+ if ! isnothing (lastBatchElement)
176
+ stopcb = FunctionCallingCallback ((u, t, integrator) -> copyState! (neuralFMU. fmu, lastBatchElement);
177
+ funcat= [batchElement. tStop])
178
+ push! (neuralFMU. customCallbacksAfter, stopcb)
179
+ end
180
+
181
+ if isnothing (batchElement. initialState)
182
+ startcb = FunctionCallingCallback ((u, t, integrator) -> copyState! (neuralFMU. fmu, batchElement);
183
+ funcat= [batchElement. tStart], func_start= true )
184
+ push! (neuralFMU. customCallbacksAfter, startcb)
185
+
186
+ c = getCurrentComponent (neuralFMU. fmu)
187
+ FMI. fmi2SetContinuousStates (c, batchElement. xStart)
188
+ FMI. fmi2SetTime (c, batchElement. tStart)
189
+ else
190
+ pasteState! (neuralFMU. fmu, batchElement)
191
+ end
186
192
else
187
- pasteState! (neuralFMU . fmu, batchElement)
193
+ @warn " This FMU can't set/get a FMU state. So discrete states can't be estimated together with the continuous solution. "
188
194
end
189
195
190
196
batchElement. solution = neuralFMU (batchElement. xStart, (batchElement. tStart, batchElement. tStop); saveat= batchElement. saveat, kwargs... )
377
383
function batchDataSolution (neuralFMU:: NeuralFMU , x0_fun, train_t:: AbstractArray{<:Real} , targets:: AbstractArray ;
378
384
batchDuration:: Real = (train_t[end ]- train_t[1 ]), indicesModel= 1 : length (targets[1 ]), plot:: Bool = false , scalarLoss:: Bool = true , solverKwargs... )
379
385
380
- if fmi2CanGetSetState (neuralFMU. fmu)
381
- @assert ! neuralFMU. fmu. executionConfig. instantiate " Batching not possible for auto-instanciating FMUs."
382
- else
383
- @warn " This FMU can't set/get a FMU state. So discrete states can't be estimated together with the continuous solution."
384
- end
385
-
386
386
batch = Array {FMIFlux.FMU2SolutionBatchElement,1} ()
387
387
388
388
# indicesData = 1:1
0 commit comments