@@ -190,6 +190,16 @@ struct System <: IntermediateDeprecationSystem
190190 """
191191 tstops:: Vector{Any}
192192 """
193+ $INTERNAL_FIELD_WARNING
194+ The list of input variables of the system.
195+ """
196+ inputs:: OrderedSet{BasicSymbolic}
197+ """
198+ $INTERNAL_FIELD_WARNING
199+ The list of output variables of the system.
200+ """
201+ outputs:: OrderedSet{BasicSymbolic}
202+ """
193203 The `TearingState` of the system post-simplification with `mtkcompile`.
194204 """
195205 tearing_state:: Any
@@ -255,8 +265,9 @@ struct System <: IntermediateDeprecationSystem
255265 brownians, iv, observed, parameter_dependencies, var_to_name, name, description,
256266 defaults, guesses, systems, initialization_eqs, continuous_events, discrete_events,
257267 connector_type, assertions = Dict {BasicSymbolic, String} (),
258- metadata = MetadataT (), gui_metadata = nothing ,
259- is_dde = false , tstops = [], tearing_state = nothing , namespacing = true ,
268+ metadata = MetadataT (), gui_metadata = nothing , is_dde = false , tstops = [],
269+ inputs = Set {BasicSymbolic} (), outputs = Set {BasicSymbolic} (),
270+ tearing_state = nothing , namespacing = true ,
260271 complete = false , index_cache = nothing , ignored_connections = nothing ,
261272 preface = nothing , parent = nothing , initializesystem = nothing ,
262273 is_initializesystem = false , is_discrete = false , isscheduled = false ,
@@ -296,7 +307,8 @@ struct System <: IntermediateDeprecationSystem
296307 observed, parameter_dependencies, var_to_name, name, description, defaults,
297308 guesses, systems, initialization_eqs, continuous_events, discrete_events,
298309 connector_type, assertions, metadata, gui_metadata, is_dde,
299- tstops, tearing_state, namespacing, complete, index_cache, ignored_connections,
310+ tstops, inputs, outputs, tearing_state, namespacing,
311+ complete, index_cache, ignored_connections,
300312 preface, parent, initializesystem, is_initializesystem, is_discrete,
301313 isscheduled, schedule)
302314 end
@@ -332,7 +344,8 @@ function System(eqs::Vector{Equation}, iv, dvs, ps, brownians = [];
332344 continuous_events = SymbolicContinuousCallback[], discrete_events = SymbolicDiscreteCallback[],
333345 connector_type = nothing , assertions = Dict {BasicSymbolic, String} (),
334346 metadata = MetadataT (), gui_metadata = nothing ,
335- is_dde = nothing , tstops = [], tearing_state = nothing ,
347+ is_dde = nothing , tstops = [], inputs = OrderedSet {BasicSymbolic} (),
348+ outputs = OrderedSet {BasicSymbolic} (), tearing_state = nothing ,
336349 ignored_connections = nothing , parent = nothing ,
337350 description = " " , name = nothing , discover_from_metadata = true ,
338351 initializesystem = nothing , is_initializesystem = false , is_discrete = false ,
@@ -367,15 +380,35 @@ function System(eqs::Vector{Equation}, iv, dvs, ps, brownians = [];
367380
368381 defaults = anydict (defaults)
369382 guesses = anydict (guesses)
383+ inputs = OrderedSet {BasicSymbolic} (inputs)
384+ outputs = OrderedSet {BasicSymbolic} (outputs)
385+ for subsys in systems
386+ for var in ModelingToolkit. inputs (subsys)
387+ push! (inputs, renamespace (subsys, var))
388+ end
389+ for var in ModelingToolkit. outputs (subsys)
390+ push! (outputs, renamespace (subsys, var))
391+ end
392+ end
370393 var_to_name = anydict ()
371394
372395 let defaults = discover_from_metadata ? defaults : Dict (),
373- guesses = discover_from_metadata ? guesses : Dict ()
396+ guesses = discover_from_metadata ? guesses : Dict (),
397+ inputs = discover_from_metadata ? inputs : Set (),
398+ outputs = discover_from_metadata ? outputs : Set ()
374399
375400 process_variables! (var_to_name, defaults, guesses, dvs)
376401 process_variables! (var_to_name, defaults, guesses, ps)
377402 process_variables! (var_to_name, defaults, guesses, [eq. lhs for eq in observed])
378403 process_variables! (var_to_name, defaults, guesses, [eq. rhs for eq in observed])
404+
405+ for var in dvs
406+ if isinput (var)
407+ push! (inputs, var)
408+ elseif isoutput (var)
409+ push! (outputs, var)
410+ end
411+ end
379412 end
380413 filter! (! (isnothing ∘ last), defaults)
381414 filter! (! (isnothing ∘ last), guesses)
@@ -417,7 +450,8 @@ function System(eqs::Vector{Equation}, iv, dvs, ps, brownians = [];
417450 costs, consolidate, dvs, ps, brownians, iv, observed, Equation[],
418451 var_to_name, name, description, defaults, guesses, systems, initialization_eqs,
419452 continuous_events, discrete_events, connector_type, assertions, metadata, gui_metadata, is_dde,
420- tstops, tearing_state, true , false , nothing , ignored_connections, preface, parent,
453+ tstops, inputs, outputs, tearing_state, true , false ,
454+ nothing , ignored_connections, preface, parent,
421455 initializesystem, is_initializesystem, is_discrete; checks)
422456end
423457
@@ -731,6 +765,7 @@ function flatten(sys::System, noeqs = false)
731765 discrete_events = discrete_events (sys), assertions = assertions (sys),
732766 is_dde = is_dde (sys), tstops = symbolic_tstops (sys),
733767 initialization_eqs = initialization_equations (sys),
768+ inputs = inputs (sys), outputs = outputs (sys),
734769 # without this, any defaults/guesses obtained from metadata that were
735770 # later removed by the user will be re-added. Right now, we just want to
736771 # retain `defaults(sys)` as-is.
@@ -1143,6 +1178,8 @@ function Base.isapprox(sysa::System, sysb::System)
11431178 isequal (get_metadata (sysa), get_metadata (sysb)) &&
11441179 isequal (get_is_dde (sysa), get_is_dde (sysb)) &&
11451180 issetequal (get_tstops (sysa), get_tstops (sysb)) &&
1181+ issetequal (get_inputs (sysa), get_inputs (sysb)) &&
1182+ issetequal (get_outputs (sysa), get_outputs (sysb)) &&
11461183 safe_issetequal (get_ignored_connections (sysa), get_ignored_connections (sysb)) &&
11471184 isequal (get_is_initializesystem (sysa), get_is_initializesystem (sysb)) &&
11481185 isequal (get_is_discrete (sysa), get_is_discrete (sysb)) &&
0 commit comments