# Tool for composable circuit simulation?

**URL:** https://discourse.julialang.org/t/tool-for-composable-circuit-simulation/103449
**Category:** Modelling & Simulations
**Tags:** question, modelingtoolkit
**Created:** [September 1, 2023, 4:18pm UTC](https://discourse.julialang.org/t/tool-for-composable-circuit-simulation/103449 "2023-09-01T16:18:27Z")
**Posts on this page:** 9
**Page:** 2

<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: [September 27, 2023, 12:23pm UTC](https://discourse.julialang.org/t/tool-for-composable-circuit-simulation/103449/21 "2023-09-27T12:23:50Z")

</div>

structural simplify before complete? I am surprised that didn’t error

---

<div class="post-metadata">

### Author: ![hacklint](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hacklint/32/25568_2.png) [@hacklint](https://discourse.julialang.org/u/hacklint)
#### Post date: [September 27, 2023, 12:31pm UTC](https://discourse.julialang.org/t/tool-for-composable-circuit-simulation/103449/22 "2023-09-27T12:31:36Z")

</div>

Its actually after, but both structural simplify and complete taking the original system as argument.

---

<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: [September 27, 2023, 12:33pm UTC](https://discourse.julialang.org/t/tool-for-composable-circuit-simulation/103449/23 "2023-09-27T12:33:49Z")

</div>

Yes, that’s why I’m saying your issue is. You want to complete the structurally simplified system.

```julia
sys = complete(structural_simplify(gsys))

```

Note this will likely change soon.

---

<div class="post-metadata">

### Author: ![hacklint](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hacklint/32/25568_2.png) [@hacklint](https://discourse.julialang.org/u/hacklint)
#### Post date: [September 27, 2023, 12:51pm UTC](https://discourse.julialang.org/t/tool-for-composable-circuit-simulation/103449/24 "2023-09-27T12:51:21Z")

</div>

OK, but this fails at attempted parameter setting in problem creation:

```julia
@named gsys = G2()
sys = complete(structural_simplify(gsys))

# Run g1 with one switch open, one closed, expecting current 0 (open circuit) 
prob = ODAEProblem(sys, [], (0, 10.0), [sys.g1.b1 => true, sys.g1.b2 => false])

```

giving

`ERROR: ArgumentError: System gsys: variable g1 does not exist`

Using gsys rather than sys for parameter keys fails to “bite” with the namespacing issues described above.

---

<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: [September 27, 2023, 12:54pm UTC](https://discourse.julialang.org/t/tool-for-composable-circuit-simulation/103449/25 "2023-09-27T12:54:23Z")

</div>

Interesting. Check:

```julia
@named gsys = G2()
gsys = complete(structural_simplify(gsys))

# Run g1 with one switch open, one closed, expecting current 0 (open circuit) 
prob = ODAEProblem(sys, [], (0, 10.0), [gsys.g1.b1 => true, gsys.g1.b2 => false])

```

---

<div class="post-metadata">

### Author: ![hacklint](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hacklint/32/25568_2.png) [@hacklint](https://discourse.julialang.org/u/hacklint)
#### Post date: [September 27, 2023, 1:02pm UTC](https://discourse.julialang.org/t/tool-for-composable-circuit-simulation/103449/26 "2023-09-27T13:02:50Z")

</div>

(Assuming the first argument to ODAEProblem is also supposed to be gsys)  
Fails with identical error message.

Still, solving the single-gadget problem above gives correct results with a problem defined on the structurally simplified system and parameterised with the “completed” parameter keys.  
Also the two-gadget problem seems (to me at least) to be apparently OK set up at least parameter-wise and it would be interesting to dig into that solution. Guess I just need a pickaxe… Is my failure to access variables in that solution related to the ordering of structural-simplify and complete?

Also, anything more you could share on “this will likely change soon”…? I’m obviously interested in getting this to work and its feels like I’m getting close, but I don’t want to kick a dead horse if there is a promise (or even hope) of a healthier one showing up soon 😉

---

<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: [September 27, 2023, 9:41pm UTC](https://discourse.julialang.org/t/tool-for-composable-circuit-simulation/103449/27 "2023-09-27T21:41:52Z")

</div>

There is a new front end syntax coming that will simplify this issue out and not require calling complete

---

<div class="post-metadata">

### Author: ![hacklint](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hacklint/32/25568_2.png) [@hacklint](https://discourse.julialang.org/u/hacklint)
#### Post date: [September 28, 2023, 6:33am UTC](https://discourse.julialang.org/t/tool-for-composable-circuit-simulation/103449/28 "2023-09-28T06:33:02Z")

</div>

Great! Any idea about the timing and is there an issue for it? If I can be of any help, I’d be happy to.

---

<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: [September 30, 2023, 4:10pm UTC](https://discourse.julialang.org/t/tool-for-composable-circuit-simulation/103449/29 "2023-09-30T16:10:14Z")

</div>

It will hopefully merge next week [Refactor tutorials with `@mtkmodel` by ven-k · Pull Request #2286 · SciML/ModelingToolkit.jl · GitHub](https://github.com/SciML/ModelingToolkit.jl/pull/2286)

[Previous page](https://discourse.julialang.org/t/tool-for-composable-circuit-simulation/103449.md?page=1)
