# Feasibility Inquiry: Building a Chemical Process Simulation and Optimization Package with JuMP

**URL:** <https://discourse.julialang.org/t/feasibility-inquiry-building-a-chemical-process-simulation-and-optimization-package-with-jump/109236>\
**Category:** Specific Domains\
**Tags:** jump, chemical-engineering\
**Created:** [January 25, 2024, 5:06am UTC](https://discourse.julialang.org/t/feasibility-inquiry-building-a-chemical-process-simulation-and-optimization-package-with-jump/109236 "2024-01-25T05:06:28Z")\
**Posts on this page:** 20\
**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:** [August 12, 2024, 12:52pm UTC](https://discourse.julialang.org/t/feasibility-inquiry-building-a-chemical-process-simulation-and-optimization-package-with-jump/109236/21 "2024-08-12T12:52:05Z")

</div>

You might be hitting the array registration issues. This is something that got fixed with Symbolics v3 but it’s currently going to be blocked until the bumping [Symbolics / SymbolicUtils / TermInterface bump by ChrisRackauckas · Pull Request #2948 · SciML/ModelingToolkit.jl · GitHub](https://github.com/SciML/ModelingToolkit.jl/pull/2948) is done. I’m hoping that piece is all completed by the end of the week, in which case @Vinicius_Viena is unblocked and the Clapeyron integrations should all be working.

---

<div class="post-metadata">

**Author:** ![Vinicius\_Viena](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vinicius_viena/32/36579_2.png) [@Vinicius\_Viena](https://discourse.julialang.org/u/Vinicius_Viena)\
**Post date:** [August 12, 2024, 1:31pm UTC](https://discourse.julialang.org/t/feasibility-inquiry-building-a-chemical-process-simulation-and-optimization-package-with-jump/109236/22 "2024-08-12T13:31:44Z")

</div>

Hi!

Calling unregistered Clapyeron functions will likely fail as symbolics will trace down inner function calls.

Here’s a related thread about it, but using coolprop for single component systems: [Media properties and component encapsulation in MTK - #7 by Sushrut\_Deshpande](https://discourse.julialang.org/t/media-properties-and-component-encapsulation-in-mtk/83557/7).

A symbolic extension is being done in Clapyeron with symbolic registration of relevant functions. To make it functional though, the updates Chris mentioned are necessary.

---

<div class="post-metadata">

**Author:** ![Sushrut\_Deshpande](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sushrut_deshpande/32/52754_2.png) [@Sushrut\_Deshpande](https://discourse.julialang.org/u/Sushrut_Deshpande)\
**Post date:** [August 12, 2024, 2:15pm UTC](https://discourse.julialang.org/t/feasibility-inquiry-building-a-chemical-process-simulation-and-optimization-package-with-jump/109236/23 "2024-08-12T14:15:35Z")

</div>

Indeed I have faced the same issue when calling Clapeyron functions.

Any idea when ProcessSimulator will be open for public release? If my understanding is correct it has already connected Clapeyron functions with ModelingToolkit.

---

<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, 2024, 2:16am UTC](https://discourse.julialang.org/t/feasibility-inquiry-building-a-chemical-process-simulation-and-optimization-package-with-jump/109236/24 "2024-08-19T02:16:26Z")

</div>

The ModelingToolkit updates just went through last week, so the team should be unblocked now 🤞

---

<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 21, 2024, 5:44am UTC](https://discourse.julialang.org/t/feasibility-inquiry-building-a-chemical-process-simulation-and-optimization-package-with-jump/109236/25 "2024-09-21T05:44:51Z")

</div>

I just opened:

> **[GitHub - SciML/ProcessSimulator.jl](https://github.com/SciML/ProcessSimulator.jl)**
>
> Contribute to SciML/ProcessSimulator.jl development by creating an account on GitHub.

I will want to setup a call, next Tuesday? There’s a lot there (mostly in a PR branch right now), but there’s still a lot more to do, and it seems like there’s a good amount of folks that want to join. DM me if interested.

---

<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 23, 2024, 1:00pm UTC](https://discourse.julialang.org/t/feasibility-inquiry-building-a-chemical-process-simulation-and-optimization-package-with-jump/109236/26 "2024-09-23T13:00:20Z")

</div>

Latest version of the ProcessSimulator can be found in the second half of this video:

[![](https://global.discourse-cdn.com/julialang/original/3X/c/e/ce990e5274c7fec595af4d1d058ae75916f23a52.jpeg "Practical Acausal Component-Based Modeling for Engineering Systems with ModelingToolkit.jl in Julia") ](https://www.youtube.com/watch?v=lh_RK6iN7Lk)

---

<div class="post-metadata">

**Author:** ![anodos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/anodos/32/212778_2.png) [@anodos](https://discourse.julialang.org/u/anodos)\
**Post date:** [October 22, 2024, 3:05am UTC](https://discourse.julialang.org/t/feasibility-inquiry-building-a-chemical-process-simulation-and-optimization-package-with-jump/109236/28 "2024-10-22T03:05:57Z")

</div>

Just want to say, as a long time Clapeyron user, am _very_ happy to see this! Looking forward to playing with it soon.

---

<div class="post-metadata">

**Author:** ![anodos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/anodos/32/212778_2.png) [@anodos](https://discourse.julialang.org/u/anodos)\
**Post date:** [November 14, 2024, 11:26pm UTC](https://discourse.julialang.org/t/feasibility-inquiry-building-a-chemical-process-simulation-and-optimization-package-with-jump/109236/29 "2024-11-14T23:26:06Z")

</div>

Out of curiosity, what will be the capabilities for black-box modelling of unit operations? All I really want for Christmas is a tool that allows me to define individual unit operation functions (reactor, absorber, HX) as julia code, define how they link (this stream flows from here to there), and solves the whole system, either automatically tearing (sequential) or by automatically bringing everything together (equation oriented). It looks like this project is closer to the latter, but it doesn’t look like it could handle arbitrary Julia functions inside unit operation blocks? I understand there’s a tradeoff: with arbitrary julia functions, you’d lose most of the numerical magic possible with ModelingToolkit.jl …

---

<div class="post-metadata">

**Author:** ![cstjean](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cstjean/32/1444_2.png) [@cstjean](https://discourse.julialang.org/u/cstjean)\
**Post date:** [November 15, 2024, 1:40am UTC](https://discourse.julialang.org/t/feasibility-inquiry-building-a-chemical-process-simulation-and-optimization-package-with-jump/109236/30 "2024-11-15T01:40:56Z")

</div>

> [@anodos](#):
>
> a tool that allows me to define individual unit operation functions (reactor, absorber, HX) as julia code, define how they link (this stream flows from here to there), and solves the whole system

Unless I misunderstand you, ModelingToolkit is already that tool? MTK might be rough around the edges, but on our side, we have some (basic) code working that does what you ask for using stream connectors. It works well, once you understand MTK’s idiosyncrasies and limitations. See [Acausal Component-Based Modeling · ModelingToolkit.jl](https://docs.sciml.ai/ModelingToolkit/dev/tutorials/acausal_components/)

From my understanding, ProcessSimulator.jl aims to be a library of prebuilt components. If you’re willing to write your own, the capabilities are already there.

> it doesn’t look like it could handle arbitrary Julia functions inside unit operation blocks

You can’t have a complex equation with an arbitrary function and expect MTK to do fancy algebra to simplify / invert it. But for an equation like dx/dt = x ^ 2 + f(x), `f` can be an arbitrary function (even an interpolation between data — see the DataInterpolations usage in the linked tutorial) and DifferentialEquations.jl will just integrate over it.

---

<div class="post-metadata">

**Author:** ![anodos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/anodos/32/212778_2.png) [@anodos](https://discourse.julialang.org/u/anodos)\
**Post date:** [November 15, 2024, 3:50am UTC](https://discourse.julialang.org/t/feasibility-inquiry-building-a-chemical-process-simulation-and-optimization-package-with-jump/109236/31 "2024-11-15T03:50:41Z")

</div>

To clarify. Suppose I had a very simple system with three components, a mixer, a reactor, and a separator. I’d like to be able to write 3 functions:

```julia
function Mixer(mixerinputs)
    #Do Arbitrary Julia Stuff Without Any Cares in the World
    return mixeroutputs
end

function Reactor(reactorinputs)
    #Do Arbitrary Julia Stuff Without Any Cares in the World
    return reactoroutputs
end

function Separator(reactorinputs)
    #Do Arbitrary Julia Stuff Without Any Cares in the World
    return reactoroutputs
end

```

I’d then have a separate file that defines the stream geometry so, for instance, mixeroutputs might go to reactorinputs, some variables in separatoroutputs might recycle back to mixerinputs. The tool would then take all this structure and these arbitrary julia functions, and figure out how to solve them as a whole. This would probably require tearing and sequential solving, as if we’re allowed to do arbitrary things inside each function, I don’t think it would be possible to collate the various unit operations into one large set of equations.

My question is if such Black-box modelling is a capability or possible capability in this Julia Process Simulator suite? If not, that’s fine. The only way I could imagine it working in an equation-oriented approach is if you had automated generation of surrogates (e.g. piecewise linear surrogates, like OMLT allows for) which could then be fed into a larger equation-oriented structure.

The reason I ask is that this kind of iterative, write-your-own-unit-operation code, is relatively common among a certain class of chemical process design engineers, and at present there aren’t any nice tools for automating the tearing and linking things up with a GUI, let alone automatic surrogate generation from black box models with subsequent integration into an equation oriented framework. IDAES has been pushing this way slowly, but it’s still a work in progress.

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [November 15, 2024, 4:56am UTC](https://discourse.julialang.org/t/feasibility-inquiry-building-a-chemical-process-simulation-and-optimization-package-with-jump/109236/32 "2024-11-15T04:56:53Z")

</div>

> like OMLT allows for

Since you mentioned [OMLT](https://github.com/cog-imperial/OMLT) (I assume we’re talking about the same thing), I’ll drop a link to [GitHub - lanl-ansi/MathOptAI.jl: Embed trained machine learning predictors in JuMP](https://github.com/lanl-ansi/MathOptAI.jl)

---

<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:** [November 15, 2024, 9:17am UTC](https://discourse.julialang.org/t/feasibility-inquiry-building-a-chemical-process-simulation-and-optimization-package-with-jump/109236/33 "2024-11-15T09:17:32Z")

</div>

> [@anodos](#):
>
> My question is if such Black-box modelling is a capability or possible capability in this Julia Process Simulator suite? If not, that’s fine. The only way I could imagine it working in an equation-oriented approach is if you had automated generation of surrogates (e.g. piecewise linear surrogates, like OMLT allows for) which could then be fed into a larger equation-oriented structure.

Yeah it all works together. For example, there’s ModelingToolkitNeuralNetworks.jl which allows for blocks defined as neural networks and you can train those as well. Here’s an example of doing the universal differential equation workflow on an acausal block model:

> **[Friction Model · ModelingToolkitNeuralNets.jl](https://docs.sciml.ai/ModelingToolkitNeuralNets/dev/friction/)**
>
> Documentation for ModelingToolkitNeuralNets.jl.

ModelingToolkit then has a system for declaring tunability so you can set some parameters as fixed and others to learn.

> [@anodos](#):
>
> ```julia
> function Mixer(mixerinputs)
> #Do Arbitrary Julia Stuff Without Any Cares in the World
> return mixeroutputs
> end
> 
> ```

This is done via the function registration system. You can make any function a node and register properties like inverses, discontinuities, etc. which are then specialized by the solvers. See for details:

> **[Function Registration and Tracing · Symbolics.jl](https://docs.sciml.ai/Symbolics/stable/manual/functions/)**
>
> Documentation for Symbolics.jl.

> [@cstjean](#):
>
> (even an interpolation between data — see the DataInterpolations usage in the linked tutorial)

DataInterpolations is pre-registered so it just works with the system. Other things like property models using a spline you make on your own, you will need to do the registration.

> [@anodos](#):
>
> The reason I ask is that this kind of iterative, write-your-own-unit-operation code, is relatively common among a certain class of chemical process design engineers, and at present there aren’t any nice tools for automating the tearing and linking things up with a GUI, let alone automatic surrogate generation from black box models with subsequent integration into an equation oriented framework.

Yes exactly, and that’s what is unique here. It’s a fully acausal modeling system, but it’s built within its own host language, Julia. This means that every function it handles by default, like `sqrt`, is added to the modeling system in exactly the same way that you can. There’s no difference between built-ins and the things that you can do. ModelingToolkitStandardLibrary.jl builds the basic standard library and also serves as a tool to show you how to do it. And since the host language is a fully featured language, unlike something like Modelica or GPROMs, you can pull anything from it. You can register a function calls to JuMP to embed convex optimizers for convex model-predictive control, you can register neural network training into the ODE right hand side for all I care. You can create events which log information and visualizations as a way to create animations. You can use the entire imperative language just by registering it in or using functional affect callbacks.

> [@odow](#):
>
> Since you mentioned [OMLT](https://github.com/cog-imperial/OMLT) (I assume we’re talking about the same thing), I’ll drop a link to [GitHub - lanl-ansi/MathOptAI.jl: Embed trained machine learning predictors in JuMP](https://github.com/lanl-ansi/MathOptAI.jl)

Not entirely since these IIUC cannot do the training. So you can train effectively a lookup table and embed it, but you cannot do something like the UDEs through this approach. It’s a 50% solution but it does help in some of the process modeling cases, but not others.

---

<div class="post-metadata">

**Author:** ![anodos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/anodos/32/212778_2.png) [@anodos](https://discourse.julialang.org/u/anodos)\
**Post date:** [November 18, 2024, 2:11am UTC](https://discourse.julialang.org/t/feasibility-inquiry-building-a-chemical-process-simulation-and-optimization-package-with-jump/109236/34 "2024-11-18T02:11:09Z")

</div>

This is exciting - I’ll definitely be looking into this once ProcessSimulator.jl is out! Thanks!

---

<div class="post-metadata">

**Author:** ![anodos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/anodos/32/212778_2.png) [@anodos](https://discourse.julialang.org/u/anodos)\
**Post date:** [November 18, 2024, 6:48am UTC](https://discourse.julialang.org/t/feasibility-inquiry-building-a-chemical-process-simulation-and-optimization-package-with-jump/109236/35 "2024-11-18T06:48:21Z")

</div>

Actually, to follow up on this, is there anyone I could reach out to discuss access to ProcessSimulator.jl at this time? I’m pitching a multi-year academic project, and would like to explore its potential vs my default IDAES/OMLT setup. Integration with Clapeyron is a HUGE draw if everything else works. Would be happy to contribute in modest ways (e.g. adding worked examples to docs, etc.).

---

<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:** [November 18, 2024, 10:36am UTC](https://discourse.julialang.org/t/feasibility-inquiry-building-a-chemical-process-simulation-and-optimization-package-with-jump/109236/36 "2024-11-18T10:36:29Z")

</div>

I’m always happy to chat (and collaborate on grants).

---

<div class="post-metadata">

**Author:** ![Vinicius\_Viena](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vinicius_viena/32/36579_2.png) [@Vinicius\_Viena](https://discourse.julialang.org/u/Vinicius_Viena)\
**Post date:** [November 24, 2024, 7:22pm UTC](https://discourse.julialang.org/t/feasibility-inquiry-building-a-chemical-process-simulation-and-optimization-package-with-jump/109236/37 "2024-11-24T19:22:23Z")

</div>

It would be great having you on board collaborating :). We have a group of people discussing it - we can include you. Unfortunately, there’s no one fully dedicated to it and things are not moving so quickly. So, we are after grants for that.

Regarding Clapyeron integration, registered Julia functions (including ones with vector args) from any library should already work within MTK.jl as far as I know. It is just a matter of registering the relevant functions.

---

<div class="post-metadata">

**Author:** ![anodos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/anodos/32/212778_2.png) [@anodos](https://discourse.julialang.org/u/anodos)\
**Post date:** [November 25, 2024, 3:27am UTC](https://discourse.julialang.org/t/feasibility-inquiry-building-a-chemical-process-simulation-and-optimization-package-with-jump/109236/38 "2024-11-25T03:27:51Z")

</div>

@ChrisRackauckas I may take you up on that, but first I should put some time into understanding MTK!

@Vinicius_Viena I’d love to be involved, thanks!

---

<div class="post-metadata">

**Author:** ![ysyecust](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ysyecust/32/210991_2.png) [@ysyecust](https://discourse.julialang.org/u/ysyecust)\
**Post date:** [December 26, 2024, 1:49pm UTC](https://discourse.julialang.org/t/feasibility-inquiry-building-a-chemical-process-simulation-and-optimization-package-with-jump/109236/39 "2024-12-26T13:49:30Z")

</div>

I saw the source code in ProcessSimulator.jl

> <https://github.com/SciML/ProcessSimulator.jl/blob/c3eb1561de1554596176c36dccdef5c4d0f3f8bb/src/Separation/Flash.jl#L94>

but when I use it in my code , it return error about “MethodError: no method matching -(::Num, ::SymbolicUtils.BasicSymbolic{Any})  
The function `-` exists, but no method is defined for this combination of argument types.”  
My model like this:

```julia

using ModelingToolkit, NonlinearSolve
using Clapeyron
namelist = ["ethane","ethylene","propylene","methane","propane"]
numcomp = length(namelist)
model = SRK(namelist;alpha=SoaveAlpha)
@variables x[1:numcomp] y[1:numcomp] vaporFraction phiL[1:numcomp] phiV[1:numcomp]
@parameters z[1:numcomp] T P
eqs = [
    0~sum(y) - 1,
    [0 ~ z[i]-x[i]*(1-vaporFraction)+y[i]*vaporFraction for i in 1:numcomp]...,
    [0~phiL[i]-Clapeyron.fugacity_coefficient(model,T,P,y,phase="liquid")[i] for i in 1:numcomp]...,
    [0~phiV[i]-Clapeyron.fugacity_coefficient(model,T,P,y,phase="vapor")[i] for i in 1:numcomp]...,
    [0~ phiL[i].*x[i]-phiV[i].*y[i] for i in 1:numcomp]...
]

```

---

<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:** [December 26, 2024, 7:40pm UTC](https://discourse.julialang.org/t/feasibility-inquiry-building-a-chemical-process-simulation-and-optimization-package-with-jump/109236/40 "2024-12-26T19:40:42Z")

</div>

You didn’t copy the registrations though?

---

<div class="post-metadata">

**Author:** ![ysyecust](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ysyecust/32/210991_2.png) [@ysyecust](https://discourse.julialang.org/u/ysyecust)\
**Post date:** [December 27, 2024, 5:06am UTC](https://discourse.julialang.org/t/feasibility-inquiry-building-a-chemical-process-simulation-and-optimization-package-with-jump/109236/41 "2024-12-27T05:06:39Z")

</div>

I have completed the registration using this method and my code is already calculating properly, is there a more natural way to do this now?

```julia
fugL(T,P,x) = Clapeyron.fugacity_coefficient(model,P,T,x,phase="liquid")
@register_array_symbolic fugL(T::Num,P::Num,x::Symbolics.Arr{Num, 1}) begin
    size = size(x)
    eltype = promote_type(eltype(x), eltype(x))
end

```

[Previous page](https://discourse.julialang.org/t/feasibility-inquiry-building-a-chemical-process-simulation-and-optimization-package-with-jump/109236.md?page=1)

[Next page](https://discourse.julialang.org/t/feasibility-inquiry-building-a-chemical-process-simulation-and-optimization-package-with-jump/109236.md?page=3)
