Skip to content

Conversation

@BenWibking
Copy link
Collaborator

@BenWibking BenWibking commented Jul 21, 2024

It successfully generates code for _wD (still to be tested).

It still does not combine exp(a)*exp(b) into exp(a+b). Sympy bug report: sympy/sympy#26846

@BenWibking
Copy link
Collaborator Author

BenWibking commented Jul 21, 2024

This doesn't work yet. Stuck here when trying networks/my_react_primordial3:

Substituted ydot  4
Traceback (most recent call last):
  File "/Users/benwibking/GPUAstroChem/write_actual_rhs.py", line 25, in <module>
    bb.write_cxxnetwork_withCSE(T,scomp,redshift)
  File "/Users/benwibking/GPUAstroChem/rate_collection.py", line 1977, in write_cxxnetwork_withCSE
    this_ydot = ydots[specie].subs({ChemSpecie('elec').sym_name: sy[0], ChemSpecie('hp').sym_name: sy[1], \
                ^^^^^^^^^^^^^^^^^^
AttributeError: 'int' object has no attribute 'subs'

@BenWibking
Copy link
Collaborator Author

BenWibking commented Jul 21, 2024

Ok, now I get this when I use networks/my_react_primordial_wD instead:

YDOTS written

EDOT substituted
Traceback (most recent call last):
  File "/Users/benwibking/GPUAstroChem/write_actual_rhs.py", line 25, in <module>
    bb.write_cxxnetwork_withCSE(T,scomp,redshift)
  File "/Users/benwibking/GPUAstroChem/rate_collection.py", line 2011, in write_cxxnetwork_withCSE
    simplified_tdot = self.simplify_expression(tdot_subs)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/benwibking/GPUAstroChem/rate_collection.py", line 1937, in simplify_expression
    new_expr = old_expr.replace(lambda expr: expr.is_Pow, pow_as_exp_of_log)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/benwibking/myenv/lib/python3.12/site-packages/sympy/core/basic.py", line 1666, in replace
    rv = walk(self, rec_replace)
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/benwibking/myenv/lib/python3.12/site-packages/sympy/core/basic.py", line 1641, in walk
    newargs = tuple([walk(a, F) for a in args])
                     ^^^^^^^^^^
  File "/Users/benwibking/myenv/lib/python3.12/site-packages/sympy/core/basic.py", line 1641, in walk
    newargs = tuple([walk(a, F) for a in args])
                     ^^^^^^^^^^
  File "/Users/benwibking/myenv/lib/python3.12/site-packages/sympy/core/basic.py", line 1641, in walk
    newargs = tuple([walk(a, F) for a in args])
                     ^^^^^^^^^^
  [Previous line repeated 7 more times]
  File "/Users/benwibking/myenv/lib/python3.12/site-packages/sympy/core/basic.py", line 1643, in walk
    rv = rv.func(*newargs)
         ^^^^^^^^^^^^^^^^^
  File "/Users/benwibking/myenv/lib/python3.12/site-packages/sympy/core/relational.py", line 822, in __new__
    raise TypeError("Invalid comparison of non-real %s" % me)
TypeError: Invalid comparison of non-real 1.6e-18*exp(-11700.0/T) + 6.7e-19*exp(-5860.0/T) + 3.0e-24*exp(-510.0/T) + 4.98567087237285e-33*exp(-2197000.0/T**3)*exp(3.76*log(T))*(1.0 + 6.01424680352726e-8*exp(2.1*log(T)))**(-1)

@BenWibking
Copy link
Collaborator Author

@psharda why did we do sympy.expand_log again?

import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable
from matplotlib.ticker import MaxNLocator
import networkx as nx
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I removed all of the unused imports.

T = sp.symbols('T', positive=True)

redshift = sp.symbols('z', real=True)
redshift = sp.symbols('z', positive=True)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We can assume redshift is always positive 😄

@BenWibking BenWibking changed the title attempt to rewrite pow within sympy [WIP] attempt to rewrite pow within sympy Jul 21, 2024
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.

1 participant