# Automatic differentiation with subset of parameters in ModelingToolkit

**URL:** <https://discourse.julialang.org/t/automatic-differentiation-with-subset-of-parameters-in-modelingtoolkit/85917>\
**Category:** Optimization (Mathematical)\
**Tags:** diffeq, modelingtoolkit\
**Created:** [August 18, 2022, 10:51am UTC](https://discourse.julialang.org/t/automatic-differentiation-with-subset-of-parameters-in-modelingtoolkit/85917 "2022-08-18T10:51:15Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [August 19, 2022, 10:34am UTC](https://discourse.julialang.org/t/automatic-differentiation-with-subset-of-parameters-in-modelingtoolkit/85917/6 "2022-08-19T10:34:52Z")

</div>

> [@Antomek](#):
>
> But this would not work with Zygote, as mutation is not supported.

Instead just build the array instead of mutating, using a comprehension with an ifelse statement.

```julia
new_p = [ifelse(i in p_subset_indices,p_subset[i],p) for i in 1:length(p)]

```

Or use a Zygote.Buffer.

---

_[View the full topic](https://discourse.julialang.org/t/automatic-differentiation-with-subset-of-parameters-in-modelingtoolkit/85917)._
