Skip to content

Adding inputs and outputs functions #1209

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/ModelingToolkit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,20 @@ function states end
"""
$(TYPEDSIGNATURES)

Get the set of states decorated as inputs for the given system.
"""
function inputs end

"""
$(TYPEDSIGNATURES)

Get the set of states decorated as outputs for the given system.
"""
function outputs end

"""
$(TYPEDSIGNATURES)

Get the set of parameters variables for the given system.
"""
function parameters end
Expand Down Expand Up @@ -173,7 +187,7 @@ export Differential, expand_derivatives, @derivatives
export Equation, ConstrainedEquation
export Term, Sym
export SymScope, LocalScope, ParentScope, GlobalScope
export independent_variables, independent_variable, states, parameters, equations, controls, observed, structure
export independent_variables, independent_variable, states, parameters, equations, controls, observed, structure, inputs, outputs
export structural_simplify
export DiscreteSystem, DiscreteProblem

Expand Down
8 changes: 8 additions & 0 deletions src/systems/abstractsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,14 @@ function states(sys::AbstractSystem)
[sts; reduce(vcat,namespace_variables.(systems))])
end

function inputs(sys::AbstractSystem)
[st for st in states(sys) if isinput(st)]
end

function outputs(sys::AbstractSystem)
[st for st in states(sys) if isoutput(st)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may not be true. Do you want it to be true?

Copy link
Contributor Author

@dannys4 dannys4 Aug 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In what case would it operate incorrectly?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah they could be eliminated to observed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, so should I cat any states in observed that are also decorated as outputs?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But then, you cannot calculate the Jacobian.

Copy link
Member

@YingboMa YingboMa Aug 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suppose we have the reduced output as an observed variable x ~ a + b with the equation D(y) ~ a + sin(a) + b. What's the derivative of the right hand wrt x ~ a + b? We cannot differentiate this thing. First, matching a+b is hard. Second, we don't know if this a + b is from x. It could very well be something else.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree with you on the idea that the a+b needs to be "from" x, but I see your point nonetheless. Does that have anything to do with it being an output though? Your argument seems to be valid regardless of that. Right now, don't we just expect people to, for lack of better words, "not do that"?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given x is an output, what's the output Jacobian of

D(y) ~ a + b + x
0 ~ a + b - x

and what's the output Jacobian of

```julia
D(y) ~ 2a + 2b

wrt a+b?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Say x isn't an output though. Isn't this still a problem? I'm failing to see where it being labelled as output=true comes in

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When linearizing control problems, we need to compute the Jacobian wrt the inputs or the outputs.

end

function parameters(sys::AbstractSystem)
ps = get_ps(sys)
systems = get_systems(sys)
Expand Down