Skip to content

Strengthen alias elimination #1635

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

Merged
merged 3 commits into from
Jun 28, 2022
Merged

Strengthen alias elimination #1635

merged 3 commits into from
Jun 28, 2022

Conversation

Keno
Copy link
Contributor

@Keno Keno commented Jun 9, 2022

Previously, we would only alias eliminate variables that do not occur
differentiated. This was unnecessarily restricted for systems such as

x ~ 0
D(x) ~ x - y

where alias elimination is now able to determine that x and y are
aliases.

While this is the main point of the PR, this does improve alias elimination
in some of the tests, causing tearing order to change. Previously we had
a suboptimality in tearing where an equation assigned to an scc in which it
is not able to solve a variable would not be reconsidered in another scc.
Fix that also, to make sure the tests keep working.

Copy link
Member

@YingboMa YingboMa left a comment

Choose a reason for hiding this comment

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

Could you test the example

x ~ 0
D(x) ~ x - y

get eliminated as expected? What about

D(z) ~ 0

if we eliminate D(z) away, then we won't have z as an observed variable as no initial condition would be provided for it.

may_eliminate &= isnothing(diff_to_var[v]) && isnothing(var_to_diff[v])
end
locally_structure_simplify!((@view mm[ei, :]), vi, ag, may_eliminate)
locally_structure_simplify!((@view mm[ei, :]), vi, ag, var_to_diff)
Copy link
Member

Choose a reason for hiding this comment

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

Could you make sure that variables that are marked irreducible to not be eliminated away? See

isirreducible(var) && continue

Copy link
Contributor Author

Choose a reason for hiding this comment

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

irreducible values are not included in the linear subsystem, so they should not be eliminated.

@YingboMa
Copy link
Member

YingboMa commented Jun 9, 2022

BTW, remember to run using JuliaFormatter, ModelingToolkit; format(joinpath(dirname(pathof(ModelingToolkit)), "..")) before committing.

@YingboMa
Copy link
Member

YingboMa commented Jun 9, 2022

The CI failures https://github.com/SciML/ModelingToolkit.jl/runs/6804925627?check_suite_focus=true#step:6:1540 look legitimate. Are you sure they still eliminate the same number of variables as the number of equations to keep the system balanced?

Previously, we would only alias eliminate variables that do not occur
differentiated. This was unnecessarily restricted for systems such as
```
x ~ 0
D(x) ~ x - y
```
where alias elimination is now able to determine that `x` and `y` are
aliases.

While this is the main point of the PR, this does improve alias elimination
in some of the tests, causing tearing order to change. Previously we had
a suboptimality in tearing where an equation assigned to an scc in which it
is not able to solve a variable would not be reconsidered in another scc.
Fix that also, to make sure the tests keep working.
@@ -37,17 +37,57 @@ end

function tear_graph_modia(structure::SystemStructure; varfilter = v -> true,
eqfilter = eq -> true)
# It would be possible here to simply iterate over all variables and attempt to
Copy link
Member

Choose a reason for hiding this comment

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

Should we split this to another PR?

@YingboMa YingboMa merged commit d45503c into SciML:master Jun 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants