Coder Social home page Coder Social logo

Need Help in code generation. about matchpy HOT 7 CLOSED

hpac avatar hpac commented on June 1, 2024
Need Help in code generation.

from matchpy.

Comments (7)

ashishkg0022 avatar ashishkg0022 commented on June 1, 2024

https://github.com/ashishkg0022/sympy/tree/rubi_progress/sympy/integrals/rubi
Here is the rubi module
rubi.py contains the manytoonereplacer
rules contain all rules
constraints.py contain constraints.

There are around 7000 rules.

from matchpy.

ashishkg0022 avatar ashishkg0022 commented on June 1, 2024

For few rules I tried this

import re
import os

from sympy.core.expr import Basic
from sympy.integrals.rubi.rubi import rubi_object
from sympy.integrals.rubi.rubi import *
from sympy import *
from sympy.core.singleton import Singleton

from matchpy.matching.code_generation import CodeGenerator
rubi = rubi_object()[0]
GENERATED_TEMPLATE = '''
# -*- coding: utf-8 -*-
from matchpy import *
from sympy import *
from sympy.integrals.rubi.utility_function import *
from sympy.integrals.rubi.constraints import *
from sympy.integrals.rubi.symbol import *
{}
{}
'''.strip()

generator = CodeGenerator(rubi.matcher)
global_code, code = generator.generate_code()
code = GENERATED_TEMPLATE.format(global_code, code)

with open('generated.py', 'w', encoding='utf-8') as f:
    f.write(code)

from generated import match_root

x = symbols('x')
for r, _ in match_root(Integral(x, x)):
print(r)

But this gives an key_error

~/generated.py in match_root(subject)
  27036                                                                                 yield 6, tmp_subst
  27037                                                 subjects2.appendleft(tmp120)
> 27038                                 if 'i1' in subst1 and CustomConstraint(cons_f16)(subst1):
  27039                                         # State 6226
  27040                                         if len(subjects2) >= 1:

~/Envs/sym/lib/python3.6/site-packages/matchpy/expressions/constraints.py in __call__(self, match)
    186 
    187     def __call__(self, match: substitution.Substitution) -> bool:
--> 188         args = dict((name, match[var_name]) for name, var_name in self._variables.items())
    189 
    190         return self.constraint(**args)

~/Envs/sym/lib/python3.6/site-packages/matchpy/expressions/constraints.py in <genexpr>(.0)
    186 
    187     def __call__(self, match: substitution.Substitution) -> bool:
--> 188         args = dict((name, match[var_name]) for name, var_name in self._variables.items())
    189 
    190         return self.constraint(**args)

KeyError: 'u'

What can be the cause of this ?

from matchpy.

ashishkg0022 avatar ashishkg0022 commented on June 1, 2024

Here is some progress sympy/sympy#14988
I got the code generator working. But it is able to match few expression and unable to match many.

from matchpy.

wheerd avatar wheerd commented on June 1, 2024

The cause for the error is likely that you are using a variable u in your constraint which is not matched.
I don't have time to help you debug that though. You might also want to look into overriding constraint_repr of the code generator for your custom constraint classes.

from matchpy.

ashishkg0022 avatar ashishkg0022 commented on June 1, 2024

Actually that problem is solved. We have faced a new issue, in which it is able to match some expressions and unable for some. Progress can be seen here sympy/sympy#14988

from matchpy.

ashishkg0022 avatar ashishkg0022 commented on June 1, 2024

@wheerd we are observing that, in code_generation matching, if any constraint returns False, matching is not continued any further. Probably this is the only issue. If this is fixed, our work is done.

from matchpy.

hbarthels avatar hbarthels commented on June 1, 2024

@wheerd we are observing that, in code_generation matching, if any constraint returns False, matching is not continued any further. Probably this is the only issue. If this is fixed, our work is done.

If I'm not mistaken, this problem is fixed (see #41).

from matchpy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.