# SAEM in Pumas: ERROR: TaskFailedException

**URL:** <https://discourse.pumas.ai/t/saem-in-pumas-error-taskfailedexception/1015>\
**Category:** Estimation\
**Created:** [April 13, 2024, 6:40pm UTC](https://discourse.pumas.ai/t/saem-in-pumas-error-taskfailedexception/1015 "2024-04-13T18:40:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anafunguetto](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/anafunguetto/32/455_2.png) [@anafunguetto](https://discourse.pumas.ai/u/anafunguetto)\
**Post date:** [April 13, 2024, 6:40pm UTC](https://discourse.pumas.ai/t/saem-in-pumas-error-taskfailedexception/1015/1 "2024-04-13T18:40:19Z")

</div>

Hi, guys

I’m trying to use SAEM to evaluate my pre-clinical data. I tried to do my analysis using FOCE, but it did not work. I thought it might be because of the high variability in my profiles and the small number of samples.

So, I used this valuable topic of discussion as a reference to adapt my model ([SAEM algorithm parameters - #8 by bobbrown](https://discourse.pumas.ai/t/saem-algorithm-parameters/565/8)) beyond the standard documentation of the Pumas of course.

I’m working with the following code:

mdl\_2cmp\_prop\_saem = @ emmodel begin  
@ param begin  
tvcl ~ 1 | LogNormal #when FC == 1  
tvv ~ 1 | LogNormal  
tvq ~ 1 | LogNormal  
tvvp ~ 1 | LogNormal  
beta\_Cl\_FC\_2 ~ 1 | Normal # when FC == 2  
beta\_V1\_FC\_2 ~ 1 | Normal  
beta\_Q\_FC\_2 ~ 1 | Normal  
end

```
@ random begin # Previously I found IVV only in Cl, Vc, and Q, but not in Vp (Monolix)
η1 ~ 1 | Normal
η2 ~ 1 | Normal
η3 ~ 1 | Normal 
end

@ covariance (3)
@ covariates FC
@ pre begin #here I'm evaluating my categorical COV (1 or 2, where 1 is the standard)
CL = tvcl * beta_Cl_FC_2 * (FC ==2)* exp(η1)
Vc = tvv * beta_V1_FC_2 * (FC ==2)* exp(η2)
Q = tvq * beta_Q_FC_2 * (FC ==2)* exp(η3)
 Vp = tvvp
end

@dynamics 
#Central1Periph1 - I've tried using it as a library but it was the same
    Central' = -(CL+Q)/Vc*Central + Q/Vp*Peripheral
    Peripheral' = Q/Vc*Central - Q/Vp*Peripheral

@post begin
  cp = @. Central / Vc
end

@error begin
  DV ~ Normal(cp)
end

```

end

params\_2cmp\_prop\_saem = (  
tvcl = 7119.54,  
tvv = 1795.2,  
tvq = 3471.5,  
Ω = (0.1, 0.1, 0.1),  
tvvp =7124.9,  
σ = 1,  
η1 = 0.1,  
η2 = 0.1,  
η3 = 0.1,  
beta\_Cl\_FC\_2 = 1,  
beta\_V1\_FC\_2 = 1,  
beta\_Q\_FC\_2 = 1,  
)

## SAEM\_fit = fit(mdl\_2cmp\_prop\_saem, pop1, params\_2cmp\_prop\_saem, Pumas.SAEM())

And after countless attempts at correction, I have this error:

ERROR: TaskFailedException

```
nested task error: UndefVarError: `Central` not defined
Stacktrace:
  [1] macro expansion
    @ c:\Users\Ana\.julia\Curcumina\popPK IV\popPK iv 2cpt_monolix to pumas.jl:274 [inlined]
  [2] (::var"#18#20")(t::Float64, param::NamedTuple{(:tvcl, :tvv, :tvq, :tvvp, :beta_Cl_FC_2, :beta_V1_FC_2, :beta_Q_FC_2, :η1, :η2, :η3, :FC, :CL, :Vc, :Q, :Vp), Tuple{Float64, Float64, Float64, Float64, Float64, Float64, Float64, Float64, Float64, Float64, Int64, Vararg{Float64, 4}}})
    @ Main C:\a\PumasSystemImages\PumasSystemImages\julia_depot\packages\Pumas\Zl9W3\src\dsl\emmodel_macro.jl:38
  [3] _calc_expectations_loop!

```

I would appreciate it if you could suggest something!

---

<div class="post-metadata">

**Author:** ![mohamed82008](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/mohamed82008/32/127_2.png) [@mohamed82008](https://discourse.pumas.ai/u/mohamed82008)\
**Post date:** [May 10, 2024, 4:55am UTC](https://discourse.pumas.ai/t/saem-in-pumas-error-taskfailedexception/1015/2 "2024-05-10T04:55:08Z")

</div>

> [@anafunguetto](#):
>
> ```auto
> CL = tvcl * beta_Cl_FC_2 * (FC ==2)* exp(η1)
> Vc = tvv * beta_V1_FC_2 * (FC ==2)* exp(η2)
> Q = tvq * beta_Q_FC_2 * (FC ==2)* exp(η3)
> 
> ```

This will make CL, Vc and Q equal to 0 when FC is not 2. I think you should exponentiate `beta_Cl_FC_2 * (FC ==2)`, `beta_V1_FC_2 * (FC ==2)` and `beta_Q_FC_2 * (FC ==2)` in the formula.
