Stream Connections of Subsystems

Hi, I have a system with two subsystems (which themself have two connectors with stream variables). I want to connect the connectors of the subsystem in the main system

using ModelingToolkit
using ModelingToolkit: t_nounits as t, scalarize

@connector TwoPhaseFluidPort begin
    @variables begin
        (h_outflow(t) = 0.0), [connect = Stream]
        (m_flow(t) = 0.0), [connect = Flow]
        P(t) = 0.0
    end
end

@mtkmodel SubSys begin
    @components begin
        sp1 = TwoPhaseFluidPort()
        sp2 = TwoPhaseFluidPort()
    end
end

@mtkmodel Sys begin
    @components begin
        subsys = SubSys()
    end
    @equations begin
        connect(subsys.sp1, subsys.sp2)
    end
end

@named sys = Sys()

sys_exp = expand_connections(sys)
eqs = equations(sys_exp)

# Output:
# 2-element Vector{Equation}:
# 0 ~ subsys₊sp1₊m_flow(t) + subsys₊sp2₊m_flow(t)
# subsys₊sp1₊P(t) ~ subsys₊sp2₊P(t)

The stream equations are missing. They appear when I don’t use subsystems:

 @mtkmodel Sys2 begin
    @components begin
        sp1 = TwoPhaseFluidPort()
        sp2 = TwoPhaseFluidPort()
    end
    @equations begin
        connect(sp1, sp2)
    end
end

@named sys2 = Sys2()

sys2_exp = expand_connections(sys2)
eqs2 = equations(sys2_exp)

# Output:
# 6-element Vector{Equation}:
#  sp1₊h_outflow(t) ~ ModelingToolkit.instream(sp2₊h_outflow(t))
#  sp2₊h_outflow(t) ~ ModelingToolkit.instream(sp1₊h_outflow(t))
#  0 ~ sp1₊m_flow(t)
#  0 ~ sp2₊m_flow(t)
#  0 ~ -sp1₊m_flow(t) - sp2₊m_flow(t)
#  sp1₊P(t) ~ sp2₊P(t)

Is this a bug or do I have to do sth differently?

I’m using Julia 1.10.5 with following package versions:

[961ee093] ModelingToolkit v9.46.1

I tried the first code snippet. Did you get and error complaining about use of Keyword Sys at line: @mtkmodel Sys begin ?
ERROR: cannot assign a value to imported variable Base.Sys from module Main

No, the code worked for me as given above. However, I renamed the models in the example to avoid this:

using ModelingToolkit
using ModelingToolkit: t_nounits as t, scalarize

@connector TwoPhaseFluidPort begin
    @variables begin
        (h_outflow(t) = 0.0), [connect = Stream]
        (m_flow(t) = 0.0), [connect = Flow]
        P(t) = 0.0
    end
end

@mtkmodel SubModel begin
    @components begin
        sp1 = TwoPhaseFluidPort()
        sp2 = TwoPhaseFluidPort()
    end
end

@mtkmodel Model begin
    @components begin
        subsys = SubModel()
    end
    @equations begin
        connect(subsys.sp1, subsys.sp2)
    end
end

@named model = Model()

model_exp = expand_connections(model)
eqs = equations(model_exp)

# Output:
# 2-element Vector{Equation}:
#  0 ~ subsys₊sp1₊m_flow(t) + subsys₊sp2₊m_flow(t)
#  subsys₊sp1₊P(t) ~ subsys₊sp2₊P(t)
 
@mtkmodel Model2 begin
   @components begin
        sp1 = TwoPhaseFluidPort()
        sp2 = TwoPhaseFluidPort()
    end
    @equations begin
        connect(sp1, sp2)
    end
end

@named model2 = Model2()

model2_exp = expand_connections(model2)
eqs2 = equations(model2_exp)

# Output:
# 6-element Vector{Equation}:
#  sp1₊h_outflow(t) ~ ModelingToolkit.instream(sp2₊h_outflow(t))
#  sp2₊h_outflow(t) ~ ModelingToolkit.instream(sp1₊h_outflow(t))
#  0 ~ sp1₊m_flow(t)
#  0 ~ sp2₊m_flow(t)
#  0 ~ -sp1₊m_flow(t) - sp2₊m_flow(t)
#  sp1₊P(t) ~ sp2₊P(t)