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

[GSoC] Simplification for the solutions of systems of ODEs #19998

Merged
merged 8 commits into from Oct 2, 2020

Conversation

mijo2
Copy link
Contributor

@mijo2 mijo2 commented Aug 24, 2020

References to other Issues or PRs

Brief description of what is fixed or changed

Other comments

Release Notes

  • solvers
    • Added simplification strategies for simplifying the solutions of systems of ODEs

@sympy-bot
Copy link

sympy-bot commented Aug 24, 2020

Hi, I am the SymPy bot (v161). I'm here to help you write a release notes entry. Please read the guide on how to write release notes.

Your release notes are in good order.

Here is what the release notes will look like:

This will be added to https://github.com/sympy/sympy/wiki/Release-Notes-for-1.7.

Click here to see the pull request description that was parsed.
<!-- Your title above should be a short description of what
was changed. Do not include the issue number in the title. -->

#### References to other Issues or PRs
<!-- If this pull request fixes an issue, write "Fixes #NNNN" in that exact
format, e.g. "Fixes #1234" (see
https://tinyurl.com/auto-closing for more information). Also, please
write a comment on that issue linking back to this pull request once it is
open. -->


#### Brief description of what is fixed or changed


#### Other comments


#### Release Notes

<!-- Write the release notes for this release below. See
https://github.com/sympy/sympy/wiki/Writing-Release-Notes for more information
on how to write release notes. The bot will check your release notes
automatically to see if they are formatted correctly. -->

<!-- BEGIN RELEASE NOTES -->
* solvers
  * Added simplification strategies for simplifying the solutions of systems of ODEs
<!-- END RELEASE NOTES -->

Update

The release notes on the wiki have been updated.

@@ -1508,6 +1508,8 @@ def _higher_order_ode_solver(match):
is_euler = is_transformed and type == "type1"
is_higher_order_type2 = is_transformed and type == "type2" and 'P' in match

print(match.get('rhs', None))
Copy link
Member

Choose a reason for hiding this comment

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

I hope this was for debugging(similarly other such statements)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I have removed these lines locally. Forgot to fix up these statements

@mijo2
Copy link
Contributor Author

mijo2 commented Aug 30, 2020

I have created a set of functions that can be used to print the test case given a system. Along with that, I have also created a basic structure to replace any rationals in a solution with Rational(a, b). I am not sure if it will always work but the below is what I have created:

In [113]: def filldedent_string_to_tab(string): 
     ...:     string = filldedent(string, w=100) 
     ...:     string = string.split("\n") 
     ...:     if len(string[0]) == 0: del string[0] 
     ...:     string = ['  ' + s if i != 0 else s for i, s in enumerate(string)] 
     ...:     return "\n".join(string)

In [114]: def add_more_spaces(string, more_spaces=10, ignore_first=False): 
     ...:     string = string.split("\n") 
     ...:     string = [more_spaces * ' ' + s if i != 0 or not ignore_first else s for i, s in enumerate(string)] 
     ...:     return "\n".join(string) 
     ...:                             

In [114]: def replace_rationals(str):  
     ...:     array = re.findall(r'[0-9]+/[0-9]+', str)  
     ...:     for expr in array: 
     ...:         str = str.replace(expr, "Rational({}, {})".format(*expr.split('/'))) 
     ...:     return str 
     ...:                                                                                                                                                                                                   

In [115]: def print_eqs(sol, initial_string="sol = {}"): 
     ...:     base = len(initial_string) 
     ...:     print(initial_string, end="") 
     ...:     for i, eq in enumerate(sol): 
     ...:         print((i==0)*'[' + replace_rationals(add_more_spaces(filldedent_string_to_tab(str(eq)), more_spaces=base, ignore_first=(i == 0))) + (i == len(sol)-1) * ']') 
     ...:                           

In [116]: def print_one_sol(eqs, n=1): 
     ...:     sol = dsolve(eqs) 
     ...:     print_eqs(eqs, "eqs{} = ".format(n)) 
     ...:     print_eqs(sol, "sol{} = ".format(n)) 
     ...:     print("assert dsolve(eqs{}) == sol{}".format(n, n)) 
     ...:     print("assert checksysodesol(eqs{}, sol{}) == (True, {})".format(n, n, n*[0])) 
     ...:    
                                                                                                                                                                                                                                                                                                                                                                       

@oscarbenjamin
Copy link
Contributor

@mijo2 what's the status of this?

Did you cancel the tests yourself?

@mijo2
Copy link
Contributor Author

mijo2 commented Sep 2, 2020

@oscarbenjamin I cancelled the tests. I want to complete this PR, but due to some commitments, I won't be able to work for atleast the first half of this month. I do intend to complete this PR in this month itself

Solutions to dsolve for systems of ODEs will be simplified into a
canonical form. Integrals will be evaluated automatically when calling
dsolve but doit=False can be passed to dsolve_system.
Solutions from dsolve_system are now simplified automatically. This
commit updates the test cases that are changed as a result.
@oscarbenjamin
Copy link
Contributor

I've pushed a few commits on here to finish off the simplification. This involved changing many of the tests because the output from dsolve changed. Some tests were too slow so I've reorganised some to mark some as slow or perhaps too slow.

@mijo2 Can you review this?

@codecov
Copy link

codecov bot commented Sep 30, 2020

Codecov Report

Merging #19998 into master will decrease coverage by 11.368%.
The diff coverage is 87.671%.

@@              Coverage Diff               @@
##            master    #19998        +/-   ##
==============================================
- Coverage   75.847%   64.478%   -11.369%     
==============================================
  Files          671       671                
  Lines       173810    173874        +64     
  Branches     41048     41069        +21     
==============================================
- Hits        131830    112112     -19718     
- Misses       36222     55335     +19113     
- Partials      5758      6427       +669     

@mijo2
Copy link
Contributor Author

mijo2 commented Oct 1, 2020

I've pushed a few commits on here to finish off the simplification. This involved changing many of the tests because the output from dsolve changed. Some tests were too slow so I've reorganised some to mark some as slow or perhaps too slow.

@mijo2 Can you review this?

Sure, I will review it soon, at max by tomorrow. Thanks for the commits.

@mijo2
Copy link
Contributor Author

mijo2 commented Oct 2, 2020

Looks good to me. Really liked how you implemented the simplification part along with optimizing the integral computations.

@oscarbenjamin
Copy link
Contributor

Thanks @mijo2. I think with this in the new systems code is ready for release. It would be great if you could write a new page in the docs to describe the systems that can be solved and the new functions though. At the moment none of this is really visible to users except that dsolve might give better answers for many systems.

@oscarbenjamin oscarbenjamin merged commit 8064e60 into sympy:master Oct 2, 2020
@mijo2
Copy link
Contributor Author

mijo2 commented Oct 2, 2020

It would be great if you could write a new page in the docs to describe the systems that can be solved and the new functions though.

I would love to write a page showing all the examples that can be solved but I am currently very busy. Can you tell me a tentative date for the release so that I can make proper arrangements and plan accordingly to write the doc page?

@oscarbenjamin
Copy link
Contributor

This PR was the main blocker for the release so now it should be fairly soon although I haven't announced anything yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants