Skip to content
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

Add tests of various features #2806

Merged
merged 12 commits into from
Jul 27, 2024
Merged

Conversation

TorkelE
Copy link
Member

@TorkelE TorkelE commented Jun 15, 2024

Ok, I have tried to rewrite various tests in Catalyst to work within MTK (a bit more complicated since each system have to be generated directly, and cannot be generated from a single ReactionSystem model. These tests are primarily going through vaiours ways to interact with SciML structures, and giving input to problems, across various system types.

I have tried to go through all broken tests, and mark issues that are related. Unfortunately there are quite a few, so someone else would probably need to have a second look at each to check the issues are accurate.

@ChrisRackauckas
Copy link
Member

The tests fail?

@TorkelE
Copy link
Member Author

TorkelE commented Jun 15, 2024

Not too surprised. I will have a look locally (the test log is too large to actually see what is going on)

@TorkelE
Copy link
Member Author

TorkelE commented Jun 15, 2024

Ok, tests pass now (except for one downstream test)

Copy link
Member

@AayushSabharwal AayushSabharwal left a comment

Choose a reason for hiding this comment

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

Thanks for the extremely comprehensive tests. Apart from the specific comments below, I have a couple of overarching requests.

Firstly, these tests don't belong in MTK. They are all testing features implemented in SciMLBase, and should go there alongside the other tests for similar functionality.

  • Anything to do with remake should be in SciMLBase's modelingtoolkit_remake.jl testset
  • All of the tests for symbolic indexing/interpolation of integrators/solutions/etc should be in a comprehensive_indexing.jl testset
  • Both of the above should be in the "SymbolicIndexingInterface" group

That way all of these will be run in MTK downstream, and are tested in the library that implements the features being tested. SciMLBase wants to run these tests because changes in SciMLBase are more likely to break them than ones in MTK. remake for example is almost entirely a SciMLBase feature, and the only places MTK is likely to break it is remake_buffer.

Testing save_idxs is also unnecessary in my opinion. It's not something that's broken, it's a feature we don't support yet.

I would also like to not merge these tests in a state where the broken ones are commented out/marked as @test_broken. That defeats the purpose of the tests. We should test everything, and merge when it's all fixed.

base_esol = solve(base_eprob, ImplicitEM(); seed, trajectories = 2, saveat = 1.0)

# Simulates problems for all input types, checking that identical solutions are found.
@test_broken false # first remake in subsequent test yields a `ERROR: type Nothing has no field portion`.
Copy link
Member

Choose a reason for hiding this comment

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

What's the difference between this SDESystem and the one in https://github.com/SciML/SciMLBase.jl/blob/master/test/downstream/modelingtoolkit_remake.jl? remake passes there and fails here

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this ones goes through a couple of additional cases (e.g. observables). not sure why this one errors though, probably something very niche.

Copy link
Member

Choose a reason for hiding this comment

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

this test broken isn't setup right

base_esol = solve(base_eprob, SSAStepper(); seed, trajectories = 2, saveat = 1.0)

# Simulates problems for all input types, checking that identical solutions are found.
@test_broken false # first remake in subsequent test yields a `ERROR: type Nothing has no field portion`.
Copy link
Member

Choose a reason for hiding this comment

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

Same for JumpSystems

Copy link
Member Author

Choose a reason for hiding this comment

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

This on fails, but yes, let's investigate closer.

test/sciml_problem_inputs.jl Outdated Show resolved Hide resolved
test/sciml_problem_inputs.jl Outdated Show resolved Hide resolved
@test prob[X] == prob[sys.X] == prob[:X] == 4
@test prob[XY] == prob[sys.XY] == prob[:XY] == 9
@test prob[[XY, Y]] == prob[[sys.XY, sys.Y]] == prob[[:XY, :Y]] == [9, 5]
@test_broken prob[(XY, Y)] == prob[(sys.XY, sys.Y)] == prob[(:XY, :Y)] == (9, 5) # https://github.com/SciML/SciMLBase.jl/issues/709
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, indexing everywhere should just use getu.


# Test integrator indexing.
let
@test_broken false # NOTE: Multiple problems for `nint` (https://github.com/SciML/SciMLBase.jl/issues/662).
Copy link
Member

Choose a reason for hiding this comment

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

Does this still fail? The issue is closed.

Copy link
Member Author

Choose a reason for hiding this comment

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

The issues got closed but then the conversation continued. But I see that there was a PR merged related. I checked fairly recently and this was still broken, but should check again.

Copy link
Member Author

Choose a reason for hiding this comment

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

Checked, this still fails for nonlinear integrators

end

# Test solve's save_idxs argument.
# Currently, `save_idxs` is broken with symbolic stuff (https://github.com/SciML/ModelingToolkit.jl/issues/1761).
Copy link
Member

Choose a reason for hiding this comment

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

Yeah this is a nontrivial change, requiring updates to integrators, solutions, and a generic reimplementation of SII's index provider interface in SciMLBase.


# Handles nonlinear and steady state solutions differently.
let
@test_broken false # Currently a problem for nonlinear solutions and steady state solutions (https://github.com/SciML/SciMLBase.jl/issues/720).
Copy link
Member

Choose a reason for hiding this comment

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

This is also a case of everything not using getu.

@AayushSabharwal
Copy link
Member

I should have mentioned: I'll move the tests when I PR to SciMLBase to fix the bugs

@TorkelE
Copy link
Member Author

TorkelE commented Jun 16, 2024

I should have mentioned: I'll move the tests when I PR to SciMLBase to fix the bugs

Thanks!

@TorkelE
Copy link
Member Author

TorkelE commented Jun 16, 2024

Yeah, I am a bit uncertain what actually goes where now when the MTK pipeline have been split up in so many different places. To me it is basically tests of the System types that MTK implements. But I agree that if possible it would make sense to move them as far internal as possible. If you point out what and where I could do it, but might be easier for you to do it yourself.

@TorkelE
Copy link
Member Author

TorkelE commented Jun 16, 2024

For the save_idx I think it is just that it has been broken since the very beginning. It is something that should be supported, so don't think it is bad to keep the tests in until it actually gets fixed, even if it might be a while.

@TorkelE
Copy link
Member Author

TorkelE commented Jul 2, 2024

Are we sure that the modified version of these that got ported to SciMLBase are actually exhaustive? I.e. regression that I caught with these tests in Catalyst still appear in the ecosystem: #2838

@TorkelE
Copy link
Member Author

TorkelE commented Jul 6, 2024

I have modified this one, removing the SciMLBase related stuff, and also adding tests that static vectors can be used as input across all problem types. @AayushSabharwal

@TorkelE
Copy link
Member Author

TorkelE commented Jul 21, 2024

Haven't heard anything in a while, can we merge this @AayushSabharwal @ChrisRackauckas ?

Comment on lines 151 to 154
# jprob = remake(base_jprob; u0, p)
# @test base_sol == solve(base_jprob, SSAStepper(); seed, saveat = 1.0)
# eprob = remake(base_eprob; u0, p)
# @test base_esol == solve(eprob, SSAStepper(); seed, trajectories = 2, saveat = 1.0)
Copy link
Member

Choose a reason for hiding this comment

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

this isn't actually ran

@ChrisRackauckas
Copy link
Member

This needs a bit of work. All of the @test_brokens are not setup correctly and the actual tests are commented.

@TorkelE
Copy link
Member Author

TorkelE commented Jul 21, 2024

So, there are a large number of cases where I do

    @test_broken false # Does not work for certain inputs, likely related to https://github.com/SciML/ModelingToolkit.jl/issues/2804.
    for u0 in u0_alts_vec, p in p_alts_vec
        oprob = remake(base_oprob; u0, p)
        # @test base_sol == solve(oprob, Tsit5(); saveat = 1.0)
        eprob = remake(base_eprob; u0, p)
        # @test base_esol == solve(eprob, Tsit5(); trajectories = 2, saveat = 1.0)
    end

because some of the tests in the loop are broken, and some are not. Then just doing either @test or @test_broken will cause test failure. Separating the cases will cause tons of line to be written. Hence I comment out the actual test lines, and then write

@test_broken false

to record in the test file that there is something going on, so that the case where something is broken is lost. Similar in cases where the full test is commented out (as in some cases something in the build up fails, and sometimes not).

@ChrisRackauckas
Copy link
Member

Then why is it important for this to merge if the test broken isn't actually set to tell us if they are still broken? That's the only point of @test_broken.

@TorkelE
Copy link
Member Author

TorkelE commented Jul 21, 2024

It is meant as a reminder when you run the tests, it tells you that there are some broken tests and where (and links the issue).

Do you want me to just remove the @test_broken and comment out the relevant bits?

@TorkelE TorkelE closed this Jul 26, 2024
@TorkelE TorkelE reopened this Jul 26, 2024
@TorkelE
Copy link
Member Author

TorkelE commented Jul 26, 2024

@ChrisRackauckas I removed the stuff with the broken test, we can add them back later when they work. This should be good now. @AayushSabharwal do you have any last comments?

@ChrisRackauckas ChrisRackauckas merged commit 737490d into SciML:master Jul 27, 2024
38 of 44 checks passed
@ChrisRackauckas
Copy link
Member

Using @test_broken is fine, but the way you did it would not give an appropriate error when the test is fixed, and so it wasn't actually useful. It would be good to add correct @test_brokens where appropriate.

@TorkelE TorkelE deleted the add_indexing_tests branch July 27, 2024 18:26
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.

3 participants