Skip to content

Support enabling SymEngine#37

Closed
utensil wants to merge 4 commits intomasterfrom
sym-engine
Closed

Support enabling SymEngine#37
utensil wants to merge 4 commits intomasterfrom
sym-engine

Conversation

@utensil
Copy link
Copy Markdown
Member

@utensil utensil commented Sep 27, 2019

  • Add a Python 3.7 build with SymEngine enabled
  • Drop CI build for python-3.4

@utensil utensil force-pushed the sym-engine branch 2 times, most recently from b5fe2b5 to a2d8725 Compare September 27, 2019 09:40
@utensil
Copy link
Copy Markdown
Member Author

utensil commented Sep 27, 2019

I recalled that enabling SymEngine will fail miserably, this PR is just a reproduction and is expected to fail, will keep it for a while until I figure out why.

@codecov
Copy link
Copy Markdown

codecov bot commented Dec 8, 2019

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 67.84%. Comparing base (8ce4920) to head (9194188).
Report is 493 commits behind head on master.

❗ Current head 9194188 differs from pull request most recent head d48355d. Consider uploading reports for the commit d48355d to get more accurate results

Additional details and impacted files
@@           Coverage Diff           @@
##           master      #37   +/-   ##
=======================================
  Coverage   67.84%   67.84%           
=======================================
  Files           9        9           
  Lines        4684     4684           
=======================================
  Hits         3178     3178           
  Misses       1506     1506           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@utensil utensil changed the base branch from master to 0.4.4-release December 8, 2019 01:35
@utensil utensil changed the base branch from 0.4.4-release to master December 8, 2019 01:36
@utensil
Copy link
Copy Markdown
Member Author

utensil commented Dec 8, 2019

The only error left is ImportError: cannot import name 'lambdify' from 'symengine'.

@utensil
Copy link
Copy Markdown
Member Author

utensil commented Dec 11, 2019

Will add a SymEngine build instead of enabling it for all builds as @eric-wieser suggested when I have time to work on it:

Probably a good idea to add an extra CI job for symengine, so that we can run CI both with and without

@utensil utensil closed this Dec 11, 2019
@utensil utensil reopened this Dec 17, 2019
@utensil
Copy link
Copy Markdown
Member Author

utensil commented Dec 17, 2019

From #149 (comment) :

If you do, from sympy import diff it'll use the sympy function regardless of the environment variable value. If you do from sympy.core.backend import diff, then diff will either be a sympy function or a symengine function depending on the environment variable.

Will need to adjusting accordingly too.

@utensil utensil mentioned this pull request Dec 17, 2019
7 tasks
@utensil utensil changed the title Verify enabling SymEngine Support enabling SymEngine Dec 17, 2019
@lgtm-com
Copy link
Copy Markdown

lgtm-com bot commented Dec 17, 2019

This pull request fixes 1 alert when merging a6970f8 into ca66680 - view on LGTM.com

fixed alerts:

  • 1 for Wrong number of arguments in a call

Comment thread test_requirements.txt Outdated
@utensil utensil added this to the 0.4.5 milestone Dec 18, 2019
@utensil utensil force-pushed the sym-engine branch 2 times, most recently from 2c5064c to d45d67f Compare December 18, 2019 02:24
@lgtm-com
Copy link
Copy Markdown

lgtm-com bot commented Dec 18, 2019

This pull request fixes 1 alert when merging d45d67f into 8ce4920 - view on LGTM.com

fixed alerts:

  • 1 for Wrong number of arguments in a call

@utensil
Copy link
Copy Markdown
Member Author

utensil commented Dec 18, 2019

python-3.7 python-3.7-sympy-1.5 python-3.7-symengine
3m 47s 4m 56s 3m 55s

The time is weird. Why is sympy-1.5 slower?

Copy link
Copy Markdown
Member

@eric-wieser eric-wieser left a comment

Choose a reason for hiding this comment

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

Think I know why this miraculously works yet isn't faster...

Comment thread .circleci/config.yml
Comment thread galgebra/lt.py
from sympy.core.backend import (
expand, symbols, zeros, Symbol, Function, S, Add
)
from sympy import Matrix, Transpose
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If you use sympy's Matrix, expressions will be converted to SymPy and you'll lose the performance benefits of SymEngine

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I guessed so. The problem here is if I don't use sympy's Matrix, it will fail:

TypeError: can't set attributes of built-in/extension type 'symengine.lib.symengine_wrapper.MutableDenseMatrix'

due to lines like https://github.com/pygae/galgebra/blob/master/galgebra/printer.py#L628

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In the long run, we probably should not be attempting to override __str__

Copy link
Copy Markdown
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 will be easier to fix once we drop support for Python 2.7 and rewrite the printer somehow.

TypeError: can't set attributes of built-in/extension type 'symengine.lib.symengine_wrapper.Basic'
TypeError: can't set attributes of built-in/extension type 'symengine.lib.symengine_wrapper.MutableDenseMatrix'
@eric-wieser
Copy link
Copy Markdown
Member

eric-wieser commented Dec 18, 2019

This looks like an incompatibility between symengine and sympy to me:

  File "/home/circleci/galgebra/galgebra/metric.py", line 324, in _build_metric_element
    return Rational(s)
  File "symengine_wrapper.pyx", line 1591, in symengine.lib.symengine_wrapper.Rational.__new__
TypeError: __new__() takes exactly 3 positional arguments (2 given)

Somewhat related: symengine/symengine.py#302

@eric-wieser
Copy link
Copy Markdown
Member

This looks like a case where calling deepcopy probably doesn't make sense in the first place:

  File "/home/circleci/galgebra/galgebra/ga.py", line 408, in __init__
    metric.Metric.__init__(self, bases, **kwargs)
  File "/home/circleci/galgebra/galgebra/metric.py", line 683, in __init__
    self.g_raw = copy.deepcopy(self.g)  # save original metric tensor for use with submanifolds
  File "/usr/local/lib/python3.7/copy.py", line 169, in deepcopy
    rv = reductor(4)
  File "stringsource", line 2, in symengine.lib.symengine_wrapper.MutableDenseMatrix.__reduce_cython__
TypeError: no default __reduce__ due to non-trivial __cinit__

@lgtm-com
Copy link
Copy Markdown

lgtm-com bot commented Dec 18, 2019

This pull request fixes 1 alert when merging d48355d into 8ce4920 - view on LGTM.com

fixed alerts:

  • 1 for Wrong number of arguments in a call

@utensil
Copy link
Copy Markdown
Member Author

utensil commented Dec 18, 2019

Now it fails at https://app.circleci.com/jobs/github/pygae/galgebra/944/tests with 4 erros:

  • TypeError: no default __reduce__ due to non-trivial __cinit__
  • TypeError: __new__() takes exactly 3 positional arguments (2 given)
  • AttributeError: 'Mul' object has no attribute 'is_commutative'
  • AttributeError: 'symengine.lib.symengine_wrapper.Symbol' object has no attribute 'args_cnc'

@eric-wieser
Copy link
Copy Markdown
Member

There are more errors than that, they're just hidden under "more"

@eric-wieser eric-wieser dismissed their stale review December 18, 2019 14:22

Symengine is now running

@utensil
Copy link
Copy Markdown
Member Author

utensil commented Dec 18, 2019

There are more errors than that, they're just hidden under "more"

Scrolled to the very bottom, I don't see the "more"?

image

@eric-wieser
Copy link
Copy Markdown
Member

Ah, you're using the new GUI which has no "more" button any longer.

@utensil
Copy link
Copy Markdown
Member Author

utensil commented Dec 18, 2019

Ah, you're using the new GUI which has no "more" button any longer.

Have you found any more error types?

@utensil
Copy link
Copy Markdown
Member Author

utensil commented Dec 18, 2019

We need a more efficient way to "uniq" and filter errors.

@utensil
Copy link
Copy Markdown
Member Author

utensil commented Dec 18, 2019

Somewhat related: symengine/symengine.py#302

Seems not the same issue. We could easily work around this or fix it at

https://github.com/symengine/symengine.py/blob/master/symengine/lib/symengine_wrapper.pyx#L1589-L1593

like

https://github.com/symengine/symengine.py/blob/master/symengine/lib/symengine_wrapper.pyx#L1786

GitHub
Python wrappers for SymEngine. Contribute to symengine/symengine.py development by creating an account on GitHub.
GitHub
Python wrappers for SymEngine. Contribute to symengine/symengine.py development by creating an account on GitHub.

@eric-wieser
Copy link
Copy Markdown
Member

We could easily ... fix it

Agreed, an upstream patch to symengine is likely the way to go.

utensil added a commit that referenced this pull request Dec 19, 2019
Extracted from #37 . This will only partially enable SymEngine.
@utensil utensil modified the milestones: 0.4.5, 0.5.0 Dec 19, 2019
@utensil utensil modified the milestones: 0.5.0, 0.6.0 May 29, 2020
@utensil utensil added the stale The issue is stale and might be no longer valid label Mar 30, 2024
@utensil
Copy link
Copy Markdown
Member Author

utensil commented Mar 30, 2024

Most of the work in this PR is no longer relevant today.

In pursuit of the performance for symbolic calculation, my bet is now on things like https://www.ginac.de/ or https://github.com/egraphs-good/egg (see #42 ) and their marriage with Lean.

Maybe someone else would be still interested in enabling SymEngine with GAlgebra, but I probably won't invest more time into it. Closing.

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

Labels

stale The issue is stale and might be no longer valid

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants