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

Improvement in satask: Reduce the need of costly rcall() on SymPy expression #17379

Merged
merged 11 commits into from Aug 23, 2019

Conversation

@ShubhamKJha
Copy link
Member

commented Aug 11, 2019

References to other Issues or PRs

Follows #17144

Brief description of what is fixed or changed

This is an attempt to remove SymPy's costly rcall used on sathandlers. For sufficiently large expressions, this can almost take half of the total querying time. With this PR, the performance gain is subtle and the time spent on sathandlers is now one-fourth of what was before.

Other comments

  • Modify test_sathandlers to account for these changes.

Release Notes

  • assumptions
    • Improved the code in sathandlers to speed up satask.
@sympy-bot

This comment has been minimized.

Copy link

commented Aug 11, 2019

Hi, I am the SymPy bot (v147). 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:

  • assumptions

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

Note: This comment will be updated with the latest check if you edit the pull request. You need to reload the page to see it.

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://github.com/blog/1506-closing-issues-via-pull-requests . Please also
write a comment on that issue linking back to this pull request once it is
open. -->
Follows #17144 

#### Brief description of what is fixed or changed
This is an attempt to remove SymPy's costly **rcall** used on sathandlers. For sufficiently large expressions, this can almost take half of the total querying time. With this PR, the performance gain is subtle and the time spent on sathandlers is now *one-fourth* of what was before.

#### Other comments
- [x]   Modify `test_sathandlers` to account for these changes.  

#### 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 -->
* assumptions
  * Improved the code in sathandlers to speed up satask.

<!-- END RELEASE NOTES -->

Update

The release notes on the wiki have been updated.

ShubhamKJha added 2 commits Aug 11, 2019
@ShubhamKJha

This comment has been minimized.

Copy link
Member Author

commented Aug 11, 2019

One significant example is,

from sympy import *
p = random_poly(x, 50, -50, 50)
print(ask(Q.positive(p), Q.positive(x)))

In the master it takes 4.292 s, out of this 2.483 s is spent in rcall

  _     ._   __/__   _ _  _  _ _/_   Recorded: 11:36:37  Samples:  4151
 /_//_/// /_\ / //_// / //_'/ //     Duration: 4.293     CPU time: 4.281
/   _/                      v3.0.3

Program: my_test2.py

4.292 <module>  my_test2.py:1
`- 4.292 ask  sympy\assumptions\ask.py:1238
   |- 3.543 satask  sympy\assumptions\satask.py:12
   |  |- 3.164 get_all_relevant_facts  sympy\assumptions\satask.py:110
   |  |  |- 2.843 get_relevant_facts  sympy\assumptions\satask.py:54
   |  |  |  |- 2.483 rcall  sympy\core\basic.py:612
   |  |  |  |  `- 2.481 _recursive_call  sympy\core\basic.py:629
   |  |  |  |     |- 2.218 <listcomp>  sympy\core\basic.py:644
   |  |  |  |     |  `- 2.217 _recursive_call  sympy\core\basic.py:629
   |  |  |  |     |     |- 1.107 <listcomp>  sympy\core\basic.py:644
   |  |  |  |     |     |  `- 1.106 _recursive_call  sympy\core\basic.py:629
   |  |  |  |     |     |     `- 1.071 __new__  sympy\assumptions\sathandlers.py:52
   |  |  |  |     |     |        `- 1.047 apply  sympy\assumptions\sathandlers.py:157
   |  |  |  |     |     |           |- 0.534 <listcomp>  sympy\assumptions\sathandlers.py:164
   |  |  |  |     |     |           |  `- 0.522 __new__  sympy\core\operations.py:410
   |  |  |  |     |     |           |     |- 0.331 __new__  sympy\core\function.py:262
   |  |  |  |     |     |           |     |  `- 0.324 sympify  sympy\core\sympify.py:78
   |  |  |  |     |     |           |     |     `- 0.324 <lambda>  sympy\sets\sets.py:1732
   |  |  |  |     |     |           |     |        `- 0.324 __new__  sympy\sets\sets.py:1581
   |  |  |  |     |     |           |     |           `- 0.316 ordered  sympy\core\compatibility.py:609
   |  |  |  |     |     |           |     |              `- 0.302 ordered  sympy\core\compatibility.py:609
   |  |  |  |     |     |           |     |                 |- 0.197 ordered  sympy\core\compatibility.py:609
   |  |  |  |     |     |           |     |                 |  |- 0.063 [self]
   |  |  |  |     |     |           |     |                 |  `- 0.054 __eq__  sympy\core\numbers.py:2244
   |  |  |  |     |     |           |     |                 `- 0.098 _nodes  sympy\core\compatibility.py:590
   |  |  |  |     |     |           |     |                    `- 0.084 count  sympy\core\basic.py:1582
   |  |  |  |     |     |           |     |                       `- 0.071 <genexpr>  sympy\core\basic.py:1585
   |  |  |  |     |     |           |     |                          `- 0.053 __next__  sympy\core\basic.py:2074
   |  |  |  |     |     |           |     |                             `- 0.043 _preorder_traversal  sympy\core\basic.py:2028
   |  |  |  |     |     |           |     `- 0.174 _new_args_filter  sympy\logic\boolalg.py:665
   |  |  |  |     |     |           |        `- 0.166 binary_check_and_simplify  sympy\logic\boolalg.py:453
   |  |  |  |     |     |           |           |- 0.071 <listcomp>  sympy\logic\boolalg.py:458
   |  |  |  |     |     |           |           |  `- 0.066 atoms  sympy\core\basic.py:435
   |  |  |  |     |     |           |           |     `- 0.049 __next__  sympy\core\basic.py:2074
   |  |  |  |     |     |           |           `- 0.047 <listcomp>  sympy\logic\boolalg.py:473
   |  |  |  |     |     |           |              `- 0.045 subs  sympy\core\basic.py:808
   |  |  |  |     |     |           `- 0.513 __new__  sympy\core\operations.py:410
   |  |  |  |     |     |              |- 0.384 _new_args_filter  sympy\logic\boolalg.py:783
   |  |  |  |     |     |              |  `- 0.383 binary_check_and_simplify  sympy\logic\boolalg.py:453
   |  |  |  |     |     |              |     |- 0.312 <listcomp>  sympy\logic\boolalg.py:457
   |  |  |  |     |     |              |     |  `- 0.312 binary_symbols  sympy\logic\boolalg.py:165
   |  |  |  |     |     |              |     |     `- 0.296 args  sympy\core\operations.py:457
   |  |  |  |     |     |              |     |        `- 0.294 ordered  sympy\core\compatibility.py:609
   |  |  |  |     |     |              |     |           `- 0.292 ordered  sympy\core\compatibility.py:609
   |  |  |  |     |     |              |     |              |- 0.197 ordered  sympy\core\compatibility.py:609
   |  |  |  |     |     |              |     |              |  |- 0.065 [self]
   |  |  |  |     |     |              |     |              |  `- 0.054 __eq__  sympy\core\numbers.py:2244
   |  |  |  |     |     |              |     |              `- 0.091 _nodes  sympy\core\compatibility.py:590
   |  |  |  |     |     |              |     |                 `- 0.083 count  sympy\core\basic.py:1582
   |  |  |  |     |     |              |     |                    `- 0.073 <genexpr>  sympy\core\basic.py:1585
   |  |  |  |     |     |              |     |                       `- 0.052 __next__  sympy\core\basic.py:2074
   |  |  |  |     |     |              |     |                          `- 0.043 _preorder_traversal  sympy\core\basic.py:2028
   |  |  |  |     |     |              |     `- 0.063 <listcomp>  sympy\logic\boolalg.py:458
   |  |  |  |     |     |              |        `- 0.063 atoms  sympy\core\basic.py:435
   |  |  |  |     |     |              |           `- 0.049 __next__  sympy\core\basic.py:2074
   |  |  |  |     |     |              `- 0.128 __new__  sympy\core\function.py:262
   |  |  |  |     |     |                 `- 0.128 sympify  sympy\core\sympify.py:78
   |  |  |  |     |     |                    `- 0.128 <lambda>  sympy\sets\sets.py:1732
   |  |  |  |     |     |                       `- 0.128 __new__  sympy\sets\sets.py:1581
   |  |  |  |     |     |                          `- 0.127 ordered  sympy\core\compatibility.py:609
   |  |  |  |     |     |                             `- 0.126 ordered  sympy\core\compatibility.py:609
   |  |  |  |     |     |                                |- 0.071 _nodes  sympy\core\compatibility.py:590
   |  |  |  |     |     |                                |  `- 0.071 count  sympy\core\basic.py:1582
   |  |  |  |     |     |                                |     `- 0.068 <genexpr>  sympy\core\basic.py:1585
   |  |  |  |     |     |                                |        `- 0.047 __next__  sympy\core\basic.py:2074
   |  |  |  |     |     |                                |           `- 0.043 _preorder_traversal  sympy\core\basic.py:2028
   |  |  |  |     |     |                                `- 0.054 ordered  sympy\core\compatibility.py:609
   |  |  |  |     |     `- 1.080 __new__  sympy\assumptions\sathandlers.py:52
   |  |  |  |     |        |- 0.790 apply  sympy\assumptions\sathandlers.py:157
   |  |  |  |     |        |  |- 0.397 __new__  sympy\core\operations.py:410
   |  |  |  |     |        |  |  |- 0.293 _new_args_filter  sympy\logic\boolalg.py:783
   |  |  |  |     |        |  |  |  `- 0.293 binary_check_and_simplify  sympy\logic\boolalg.py:453
   |  |  |  |     |        |  |  |     |- 0.242 <listcomp>  sympy\logic\boolalg.py:457
   |  |  |  |     |        |  |  |     |  `- 0.242 binary_symbols  sympy\logic\boolalg.py:165
   |  |  |  |     |        |  |  |     |     `- 0.234 args  sympy\core\operations.py:457
   |  |  |  |     |        |  |  |     |        `- 0.234 ordered  sympy\core\compatibility.py:609
   |  |  |  |     |        |  |  |     |           `- 0.231 ordered  sympy\core\compatibility.py:609
   |  |  |  |     |        |  |  |     |              |- 0.148 ordered  sympy\core\compatibility.py:609
   |  |  |  |     |        |  |  |     |              |  `- 0.045 __lt__  sympy\core\numbers.py:2263
   |  |  |  |     |        |  |  |     |              `- 0.080 _nodes  sympy\core\compatibility.py:590
   |  |  |  |     |        |  |  |     |                 `- 0.074 count  sympy\core\basic.py:1582
   |  |  |  |     |        |  |  |     |                    `- 0.064 <genexpr>  sympy\core\basic.py:1585
   |  |  |  |     |        |  |  |     |                       `- 0.046 __next__  sympy\core\basic.py:2074
   |  |  |  |     |        |  |  |     |                          `- 0.043 _preorder_traversal  sympy\core\basic.py:2028
   |  |  |  |     |        |  |  |     `- 0.047 <listcomp>  sympy\logic\boolalg.py:458
   |  |  |  |     |        |  |  |        `- 0.046 atoms  sympy\core\basic.py:435
   |  |  |  |     |        |  |  `- 0.101 __new__  sympy\core\function.py:262
   |  |  |  |     |        |  |     `- 0.100 sympify  sympy\core\sympify.py:78
   |  |  |  |     |        |  |        `- 0.100 <lambda>  sympy\sets\sets.py:1732
   |  |  |  |     |        |  |           `- 0.100 __new__  sympy\sets\sets.py:1581
   |  |  |  |     |        |  |              `- 0.100 ordered  sympy\core\compatibility.py:609
   |  |  |  |     |        |  |                 `- 0.099 ordered  sympy\core\compatibility.py:609
   |  |  |  |     |        |  |                    |- 0.056 _nodes  sympy\core\compatibility.py:590
   |  |  |  |     |        |  |                    |  `- 0.055 count  sympy\core\basic.py:1582
   |  |  |  |     |        |  |                    |     `- 0.055 <genexpr>  sympy\core\basic.py:1585
   |  |  |  |     |        |  |                    `- 0.043 ordered  sympy\core\compatibility.py:609
   |  |  |  |     |        |  `- 0.386 <listcomp>  sympy\assumptions\sathandlers.py:164
   |  |  |  |     |        |     `- 0.376 __new__  sympy\core\operations.py:410
   |  |  |  |     |        |        |- 0.247 __new__  sympy\core\function.py:262
   |  |  |  |     |        |        |  `- 0.243 sympify  sympy\core\sympify.py:78
   |  |  |  |     |        |        |     `- 0.242 <lambda>  sympy\sets\sets.py:1732
   |  |  |  |     |        |        |        `- 0.242 __new__  sympy\sets\sets.py:1581
   |  |  |  |     |        |        |           `- 0.235 ordered  sympy\core\compatibility.py:609
   |  |  |  |     |        |        |              `- 0.225 ordered  sympy\core\compatibility.py:609
   |  |  |  |     |        |        |                 |- 0.144 ordered  sympy\core\compatibility.py:609
   |  |  |  |     |        |        |                 |  `- 0.051 [self]
   |  |  |  |     |        |        |                 `- 0.080 _nodes  sympy\core\compatibility.py:590
   |  |  |  |     |        |        |                    `- 0.073 count  sympy\core\basic.py:1582
   |  |  |  |     |        |        |                       `- 0.056 <genexpr>  sympy\core\basic.py:1585
   |  |  |  |     |        |        `- 0.116 _new_args_filter  sympy\logic\boolalg.py:665
   |  |  |  |     |        |           `- 0.110 binary_check_and_simplify  sympy\logic\boolalg.py:453
   |  |  |  |     |        |              `- 0.056 <listcomp>  sympy\logic\boolalg.py:458
   |  |  |  |     |        |                 `- 0.054 atoms  sympy\core\basic.py:435
   |  |  |  |     |        `- 0.202 apply  sympy\assumptions\sathandlers.py:103
   |  |  |  |     |           |- 0.157 __new__  sympy\core\operations.py:410
   |  |  |  |     |           |  |- 0.077 _new_args_filter  sympy\logic\boolalg.py:665
   |  |  |  |     |           |  |  `- 0.068 binary_check_and_simplify  sympy\logic\boolalg.py:453
   |  |  |  |     |           |  `- 0.069 __new__  sympy\core\function.py:262
   |  |  |  |     |           |     `- 0.063 sympify  sympy\core\sympify.py:78
   |  |  |  |     |           |        `- 0.063 <lambda>  sympy\sets\sets.py:1732
   |  |  |  |     |           |           `- 0.063 __new__  sympy\sets\sets.py:1581
   |  |  |  |     |           |              `- 0.060 ordered  sympy\core\compatibility.py:609
   |  |  |  |     |           |                 `- 0.049 ordered  sympy\core\compatibility.py:609
   |  |  |  |     |           `- 0.045 <listcomp>  sympy\assumptions\sathandlers.py:104
   |  |  |  |     |              `- 0.045 rcall  sympy\core\basic.py:612
   |  |  |  |     |                 `- 0.044 _recursive_call  sympy\core\basic.py:629
   |  |  |  |     `- 0.210 __new__  sympy\assumptions\sathandlers.py:52
   |  |  |  |        `- 0.142 apply  sympy\assumptions\sathandlers.py:229
   |  |  |  |           `- 0.122 __new__  sympy\logic\boolalg.py:1258
   |  |  |  |              `- 0.077 __new__  sympy\core\operations.py:410
   |  |  |  |                 `- 0.069 _new_args_filter  sympy\logic\boolalg.py:665
   |  |  |  |                    `- 0.067 binary_check_and_simplify  sympy\logic\boolalg.py:453
   |  |  |  |- 0.194 atoms  sympy\core\basic.py:435
   |  |  |  |  `- 0.155 __next__  sympy\core\basic.py:2074
   |  |  |  |     `- 0.130 _preorder_traversal  sympy\core\basic.py:2028
   |  |  |  |        `- 0.122 _preorder_traversal  sympy\core\basic.py:2028
   |  |  |  |           `- 0.113 _preorder_traversal  sympy\core\basic.py:2028
   |  |  |  |              `- 0.096 _preorder_traversal  sympy\core\basic.py:2028
   |  |  |  |                 `- 0.070 _preorder_traversal  sympy\core\basic.py:2028
   |  |  |  |                    `- 0.044 _preorder_traversal  sympy\core\basic.py:2028
   |  |  |  `- 0.152 rcall  sympy\assumptions\sathandlers.py:248
   |  |  |     `- 0.048 <lambda>  sympy\assumptions\sathandlers.py:307
   |  |  |        `- 0.045 __and__  sympy\logic\boolalg.py:62
   |  |  |           `- 0.044 __new__  sympy\core\operations.py:410
   |  |  `- 0.251 add_prop  sympy\assumptions\cnf.py:327
   |  |     |- 0.206 from_prop  sympy\assumptions\cnf.py:222
   |  |     |  `- 0.203 add  sympy\assumptions\cnf.py:200
   |  |     |     `- 0.202 to_CNF  sympy\assumptions\cnf.py:279
   |  |     |        |- 0.103 distribute_AND_over_OR  sympy\assumptions\cnf.py:169
   |  |     |        |  `- 0.078 <listcomp>  sympy\assumptions\cnf.py:181
   |  |     |        |     `- 0.078 distribute_AND_over_OR  sympy\assumptions\cnf.py:169
   |  |     |        `- 0.097 to_NNF  sympy\assumptions\cnf.py:102
   |  |     |           `- 0.067 to_NNF  sympy\assumptions\cnf.py:102
   |  |     `- 0.044 add_from_cnf  sympy\assumptions\cnf.py:331
   |  |        `- 0.043 <listcomp>  sympy\assumptions\cnf.py:332
   |  `- 0.373 check_satisfiability  sympy\assumptions\satask.py:30
   |     `- 0.356 satisfiable  sympy\logic\inference.py:38
   |        `- 0.355 dpll_satisfiable  sympy\logic\algorithms\dpll2.py:21
   |           |- 0.182 _find_model  sympy\logic\algorithms\dpll2.py:165
   |           |  |- 0.073 _simplify  sympy\logic\algorithms\dpll2.py:421
   |           |  |  `- 0.071 _unit_prop  sympy\logic\algorithms\dpll2.py:450
   |           |  |     `- 0.062 _assign_literal  sympy\logic\algorithms\dpll2.py:328
   |           |  `- 0.058 _vsids_calculate  sympy\logic\algorithms\dpll2.py:506
   |           `- 0.171 __init__  sympy\logic\algorithms\dpll2.py:84
   |              `- 0.142 _initialize_clauses  sympy\logic\algorithms\dpll2.py:140
   `- 0.747 _eval_ask  sympy\assumptions\assume.py:109
      `- 0.747 eval  sympy\assumptions\assume.py:178
         |- 0.679 Add  sympy\assumptions\handlers\order.py:266
         |  `- 0.679 ask  sympy\assumptions\ask.py:1238
         |     `- 0.676 _eval_ask  sympy\assumptions\assume.py:109
         |        `- 0.676 eval  sympy\assumptions\assume.py:178
         |           `- 0.660 Add  sympy\assumptions\handlers\sets.py:204
         |              `- 0.660 test_closed_group  sympy\assumptions\handlers\common.py:118
         |                 `- 0.660 _fuzzy_group  sympy\core\logic.py:40
         |                    `- 0.660 <genexpr>  sympy\assumptions\handlers\common.py:124
         |                       `- 0.660 ask  sympy\assumptions\ask.py:1238
         |                          `- 0.615 _eval_ask  sympy\assumptions\assume.py:109
         |                             `- 0.615 eval  sympy\assumptions\assume.py:178
         |                                `- 0.615 Mul  sympy\assumptions\handlers\sets.py:214
         |                                   `- 0.613 ask  sympy\assumptions\ask.py:1238
         |                                      |- 0.530 _eval_ask  sympy\assumptions\assume.py:109
         |                                      |  `- 0.530 eval  sympy\assumptions\assume.py:178
         |                                      |     `- 0.529 Pow  sympy\assumptions\handlers\sets.py:234
         |                                      |        `- 0.523 ask  sympy\assumptions\ask.py:1238
         |                                      |           |- 0.227 from_cnf  sympy\assumptions\cnf.py:309
         |                                      |           |  `- 0.185 <listcomp>  sympy\assumptions\cnf.py:313
         |                                      |           |     `- 0.179 encode  sympy\assumptions\cnf.py:347
         |                                      |           |        `- 0.166 <setcomp>  sympy\assumptions\cnf.py:348
         |                                      |           |           `- 0.090 __eq__  sympy\core\basic.py:299
         |                                      |           |              `- 0.054 [self]
         |                                      |           |- 0.142 satask  sympy\assumptions\satask.py:12
         |                                      |           |  |- 0.069 get_all_relevant_facts  sympy\assumptions\satask.py:110
         |                                      |           |  `- 0.067 check_satisfiability  sympy\assumptions\satask.py:30
         |                                      |           |     `- 0.063 satisfiable  sympy\logic\inference.py:38
         |                                      |           |        `- 0.063 dpll_satisfiable  sympy\logic\algorithms\dpll2.py:21
         |                                      |           `- 0.098 satisfiable  sympy\logic\inference.py:38
         |                                      |              `- 0.092 dpll_satisfiable  sympy\logic\algorithms\dpll2.py:21
         |                                      |                 `- 0.057 _find_model  sympy\logic\algorithms\dpll2.py:165
         |                                      `- 0.081 from_cnf  sympy\assumptions\cnf.py:309
         |                                         `- 0.071 <listcomp>  sympy\assumptions\cnf.py:313
         |                                            `- 0.063 encode  sympy\assumptions\cnf.py:347
         |                                               `- 0.060 <setcomp>  sympy\assumptions\cnf.py:348
         `- 0.064 Expr  sympy\assumptions\handlers\order.py:223
            `- 0.064 getit  sympy\core\assumptions.py:260
               `- 0.064 _ask  sympy\core\assumptions.py:272
                  `- 0.064 _eval_is_positive  sympy\core\expr.py:853
                     `- 0.064 getit  sympy\core\assumptions.py:260
                        `- 0.064 _ask  sympy\core\assumptions.py:272
                           `- 0.061 _ask  sympy\core\assumptions.py:272
                              `- 0.061 _ask  sympy\core\assumptions.py:272
                                 `- 0.061 _ask  sympy\core\assumptions.py:272
                                    `- 0.061 _ask  sympy\core\assumptions.py:272
                                       `- 0.061 _ask  sympy\core\assumptions.py:272
                                          `- 0.061 _ask  sympy\core\assumptions.py:272
                                             `- 0.061 _ask  sympy\core\assumptions.py:272
                                                `- 0.060 _ask  sympy\core\assumptions.py:272
                                                   `- 0.060 _ask  sympy\core\assumptions.py:272
                                                      `- 0.057 _eval_is_extended_negative  sympy\core\add.py:693
                                                         `- 0.057 _monotonic_sign  sympy\core\exprtools.py:31
                                                            `- 0.057 getit  sympy\core\assumptions.py:260
                                                               `- 0.057 _ask  sympy\core\assumptions.py:272
                                                                  `- 0.057 _ask  sympy\core\assumptions.py:272
                                                                     `- 0.057 _eval_is_negative  sympy\core\expr.py:863
                                                                        `- 0.057 getit  sympy\core\assumptions.py:260
                                                                           `- 0.057 _ask  sympy\core\assumptions.py:272
                                                                              `- 0.057 _ask  sympy\core\assumptions.py:272
                                                                                 `- 0.057 _eval_is_positive  sympy\core\expr.py:853
                                                                                    `- 0.057 getit  sympy\core\assumptions.py:260
                                                                                       `- 0.057 _ask  sympy\core\assumptions.py:272
                                                                                          `- 0.057 _eval_is_extended_positive  sympy\core\add.py:609
                                                                                             `- 0.057 <listcomp>  sympy\core\add.py:626
                                                                                                `- 0.057 getit  sympy\core\assumptions.py:260
                                                                                                   `- 0.057 _ask  sympy\core\assumptions.py:272

With this, the time spent is 1.929 s and 0.539 s respectively,

  _     ._   __/__   _ _  _  _ _/_   Recorded: 11:42:31  Samples:  1798
 /_//_/// /_\ / //_// / //_'/ //     Duration: 1.929     CPU time: 1.938
/   _/                      v3.0.3

Program: my_test2.py

1.929 <module>  my_test2.py:1
`- 1.929 ask  sympy\assumptions\ask.py:1238
   |- 1.217 satask  sympy\assumptions\satask.py:12
   |  |- 0.814 get_all_relevant_facts  sympy\assumptions\satask.py:111
   |  |  |- 0.712 get_relevant_facts  sympy\assumptions\satask.py:54
   |  |  |  |- 0.539 rcall  sympy\assumptions\cnf.py:279
   |  |  |  |  |- 0.165 apply  sympy\assumptions\sathandlers.py:234
   |  |  |  |  |  |- 0.127 __new__  sympy\logic\boolalg.py:1258
   |  |  |  |  |  |  |- 0.075 __new__  sympy\core\operations.py:410
   |  |  |  |  |  |  |  `- 0.061 _new_args_filter  sympy\logic\boolalg.py:665
   |  |  |  |  |  |  |     `- 0.053 binary_check_and_simplify  sympy\logic\boolalg.py:453
   |  |  |  |  |  |  |        `- 0.020 <listcomp>  sympy\logic\boolalg.py:473
   |  |  |  |  |  |  |           `- 0.020 subs  sympy\core\basic.py:808
   |  |  |  |  |  |  `- 0.023 <listcomp>  sympy\logic\boolalg.py:1291
   |  |  |  |  |  |     `- 0.023 __invert__  sympy\logic\boolalg.py:74
   |  |  |  |  |  |        `- 0.023 __new__  sympy\core\function.py:262
   |  |  |  |  |  `- 0.027 evaluate_old_assump  sympy\assumptions\sathandlers.py:222
   |  |  |  |  |     `- 0.025 xreplace  sympy\core\basic.py:1130
   |  |  |  |  |        `- 0.025 _xreplace  sympy\core\basic.py:1195
   |  |  |  |  |           `- 0.025 __getitem__  sympy\core\rules.py:57
   |  |  |  |  |              `- 0.023 _old_assump_replacer  sympy\assumptions\sathandlers.py:179
   |  |  |  |  |- 0.144 rcall  sympy\assumptions\sathandlers.py:260
   |  |  |  |  |  |- 0.042 <lambda>  sympy\assumptions\sathandlers.py:318
   |  |  |  |  |  |  `- 0.039 __and__  sympy\logic\boolalg.py:62
   |  |  |  |  |  |     `- 0.039 __new__  sympy\core\operations.py:410
   |  |  |  |  |  |- 0.041 <lambda>  sympy\assumptions\sathandlers.py:316
   |  |  |  |  |  |  `- 0.040 __and__  sympy\logic\boolalg.py:62
   |  |  |  |  |  |     `- 0.040 __new__  sympy\core\operations.py:410
   |  |  |  |  |  |        `- 0.020 _new_args_filter  sympy\logic\boolalg.py:665
   |  |  |  |  |  |- 0.041 <lambda>  sympy\assumptions\sathandlers.py:319
   |  |  |  |  |  |  `- 0.037 __and__  sympy\logic\boolalg.py:62
   |  |  |  |  |  |     `- 0.037 __new__  sympy\core\operations.py:410
   |  |  |  |  |  |        `- 0.021 _new_args_filter  sympy\logic\boolalg.py:665
   |  |  |  |  |  |           `- 0.020 binary_check_and_simplify  sympy\logic\boolalg.py:453
   |  |  |  |  |  `- 0.020 <lambda>  sympy\assumptions\sathandlers.py:323
   |  |  |  |  |- 0.131 distribute_AND_over_OR  sympy\assumptions\cnf.py:183
   |  |  |  |  |  `- 0.120 <listcomp>  sympy\assumptions\cnf.py:199
   |  |  |  |  |     `- 0.119 distribute_AND_over_OR  sympy\assumptions\cnf.py:183
   |  |  |  |  |        |- 0.097 <listcomp>  sympy\assumptions\cnf.py:195
   |  |  |  |  |        |  `- 0.096 distribute_AND_over_OR  sympy\assumptions\cnf.py:183
   |  |  |  |  |        |     `- 0.053 <listcomp>  sympy\assumptions\cnf.py:199
   |  |  |  |  |        |        `- 0.053 distribute_AND_over_OR  sympy\assumptions\cnf.py:183
   |  |  |  |  |        |           `- 0.032 all_or  sympy\assumptions\cnf.py:304
   |  |  |  |  |        |              `- 0.027 _or  sympy\assumptions\cnf.py:252
   |  |  |  |  |        `- 0.020 all_or  sympy\assumptions\cnf.py:304
   |  |  |  |  `- 0.032 apply  sympy\assumptions\sathandlers.py:161
   |  |  |  |- 0.053 _and  sympy\assumptions\cnf.py:261
   |  |  |  |  `- 0.052 [self]
   |  |  |  |- 0.048 [self]
   |  |  |  |- 0.042 to_CNF  sympy\assumptions\cnf.py:318
   |  |  |  |  `- 0.021 distribute_AND_over_OR  sympy\assumptions\cnf.py:183
   |  |  |  `- 0.023 all_predicates  sympy\assumptions\cnf.py:246
   |  |  |- 0.048 add_from_cnf  sympy\assumptions\cnf.py:370
   |  |  |  `- 0.048 <listcomp>  sympy\assumptions\cnf.py:371
   |  |  |     `- 0.047 encode  sympy\assumptions\cnf.py:386
   |  |  |        `- 0.045 <setcomp>  sympy\assumptions\cnf.py:387
   |  |  |           `- 0.026 encode_arg  sympy\assumptions\cnf.py:374
   |  |  `- 0.020 <listcomp>  sympy\assumptions\satask.py:148
   |  `- 0.395 check_satisfiability  sympy\assumptions\satask.py:30
   |     |- 0.356 satisfiable  sympy\logic\inference.py:38
   |     |  `- 0.356 dpll_satisfiable  sympy\logic\algorithms\dpll2.py:21
   |     |     |- 0.177 __init__  sympy\logic\algorithms\dpll2.py:84
   |     |     |  |- 0.145 _initialize_clauses  sympy\logic\algorithms\dpll2.py:140
   |     |     |  `- 0.031 _vsids_init  sympy\logic\algorithms\dpll2.py:471
   |     |     `- 0.176 _find_model  sympy\logic\algorithms\dpll2.py:165
   |     |        |- 0.070 _vsids_calculate  sympy\logic\algorithms\dpll2.py:506
   |     |        `- 0.064 _simplify  sympy\logic\algorithms\dpll2.py:421
   |     |           `- 0.059 _unit_prop  sympy\logic\algorithms\dpll2.py:450
   |     |              `- 0.051 _assign_literal  sympy\logic\algorithms\dpll2.py:328
   |     |                 `- 0.033 [self]
   |     `- 0.039 copy  sympy\assumptions\cnf.py:362
   |        `- 0.039 <listcomp>  sympy\assumptions\cnf.py:363
   `- 0.709 _eval_ask  sympy\assumptions\assume.py:109
      `- 0.709 eval  sympy\assumptions\assume.py:178
         |- 0.641 Add  sympy\assumptions\handlers\order.py:266
         |  `- 0.641 ask  sympy\assumptions\ask.py:1238
         |     `- 0.638 _eval_ask  sympy\assumptions\assume.py:109
         |        `- 0.638 eval  sympy\assumptions\assume.py:178
         |           `- 0.637 Add  sympy\assumptions\handlers\sets.py:204
         |              `- 0.637 test_closed_group  sympy\assumptions\handlers\common.py:118
         |                 `- 0.637 _fuzzy_group  sympy\core\logic.py:40
         |                    `- 0.637 <genexpr>  sympy\assumptions\handlers\common.py:124
         |                       `- 0.637 ask  sympy\assumptions\ask.py:1238
         |                          |- 0.596 _eval_ask  sympy\assumptions\assume.py:109
         |                          |  `- 0.596 eval  sympy\assumptions\assume.py:178
         |                          |     `- 0.595 Mul  sympy\assumptions\handlers\sets.py:214
         |                          |        `- 0.594 ask  sympy\assumptions\ask.py:1238
         |                          |           |- 0.513 _eval_ask  sympy\assumptions\assume.py:109
         |                          |           |  `- 0.513 eval  sympy\assumptions\assume.py:178
         |                          |           |     `- 0.509 Pow  sympy\assumptions\handlers\sets.py:234
         |                          |           |        `- 0.504 ask  sympy\assumptions\ask.py:1238
         |                          |           |           |- 0.230 from_cnf  sympy\assumptions\cnf.py:348
         |                          |           |           |  |- 0.191 <listcomp>  sympy\assumptions\cnf.py:352
         |                          |           |           |  |  `- 0.185 encode  sympy\assumptions\cnf.py:386
         |                          |           |           |  |     `- 0.177 <setcomp>  sympy\assumptions\cnf.py:387
         |                          |           |           |  |        |- 0.094 __eq__  sympy\core\basic.py:299
         |                          |           |           |  |        |  |- 0.048 [self]
         |                          |           |           |  |        |  `- 0.046 _sympify  sympy\core\sympify.py:392
         |                          |           |           |  |        |     |- 0.026 sympify  sympy\core\sympify.py:78
         |                          |           |           |  |        |     |  `- 0.022 [self]
         |                          |           |           |  |        |     `- 0.020 [self]
         |                          |           |           |  |        |- 0.043 encode_arg  sympy\assumptions\cnf.py:374
         |                          |           |           |  |        |  `- 0.035 [self]
         |                          |           |           |  |        `- 0.040 [self]
         |                          |           |           |  `- 0.031 all_predicates  sympy\assumptions\cnf.py:246
         |                          |           |           |     `- 0.021 <setcomp>  sympy\assumptions\cnf.py:249
         |                          |           |           |- 0.132 satask  sympy\assumptions\satask.py:12
         |                          |           |           |  |- 0.068 check_satisfiability  sympy\assumptions\satask.py:30
         |                          |           |           |  |  `- 0.060 satisfiable  sympy\logic\inference.py:38
         |                          |           |           |  |     `- 0.060 dpll_satisfiable  sympy\logic\algorithms\dpll2.py:21
         |                          |           |           |  |        |- 0.034 _find_model  sympy\logic\algorithms\dpll2.py:165
         |                          |           |           |  |        `- 0.026 __init__  sympy\logic\algorithms\dpll2.py:84
         |                          |           |           |  |           `- 0.020 _initialize_clauses  sympy\logic\algorithms\dpll2.py:140
         |                          |           |           |  `- 0.063 get_all_relevant_facts  sympy\assumptions\satask.py:111
         |                          |           |           |     `- 0.046 from_cnf  sympy\assumptions\cnf.py:348
         |                          |           |           |        `- 0.034 <listcomp>  sympy\assumptions\cnf.py:352
         |                          |           |           |           `- 0.034 encode  sympy\assumptions\cnf.py:386
         |                          |           |           |              `- 0.033 <setcomp>  sympy\assumptions\cnf.py:387
         |                          |           |           |                 `- 0.021 __eq__  sympy\core\basic.py:299
         |                          |           |           `- 0.092 satisfiable  sympy\logic\inference.py:38
         |                          |           |              `- 0.089 dpll_satisfiable  sympy\logic\algorithms\dpll2.py:21
         |                          |           |                 |- 0.061 _find_model  sympy\logic\algorithms\dpll2.py:165
         |                          |           |                 |  `- 0.026 _assign_literal  sympy\logic\algorithms\dpll2.py:328
         |                          |           |                 `- 0.028 __init__  sympy\logic\algorithms\dpll2.py:84
         |                          |           |                    `- 0.022 _initialize_clauses  sympy\logic\algorithms\dpll2.py:140
         |                          |           `- 0.073 from_cnf  sympy\assumptions\cnf.py:348
         |                          |              `- 0.059 <listcomp>  sympy\assumptions\cnf.py:352
         |                          |                 `- 0.058 encode  sympy\assumptions\cnf.py:386
         |                          |                    `- 0.053 <setcomp>  sympy\assumptions\cnf.py:387
         |                          |                       `- 0.036 __eq__  sympy\core\basic.py:299
         |                          |                          `- 0.022 [self]
         |                          `- 0.039 from_cnf  sympy\assumptions\cnf.py:348
         |                             `- 0.031 <listcomp>  sympy\assumptions\cnf.py:352
         |                                `- 0.027 encode  sympy\assumptions\cnf.py:386
         |                                   `- 0.026 <setcomp>  sympy\assumptions\cnf.py:387
         `- 0.063 Expr  sympy\assumptions\handlers\order.py:223
            `- 0.063 getit  sympy\core\assumptions.py:260
               `- 0.063 _ask  sympy\core\assumptions.py:272
                  `- 0.063 _eval_is_positive  sympy\core\expr.py:853
                     `- 0.063 getit  sympy\core\assumptions.py:260
                        `- 0.063 _ask  sympy\core\assumptions.py:272
                           `- 0.060 _ask  sympy\core\assumptions.py:272
                              `- 0.060 _ask  sympy\core\assumptions.py:272
                                 `- 0.060 _ask  sympy\core\assumptions.py:272
                                    `- 0.060 _ask  sympy\core\assumptions.py:272
                                       `- 0.060 _ask  sympy\core\assumptions.py:272
                                          `- 0.060 _ask  sympy\core\assumptions.py:272
                                             `- 0.056 _eval_is_odd  sympy\core\add.py:589
                                                `- 0.056 <listcomp>  sympy\core\add.py:590
                                                   `- 0.056 getit  sympy\core\assumptions.py:260
                                                      `- 0.056 _ask  sympy\core\assumptions.py:272
                                                         `- 0.054 _eval_is_even  sympy\core\mul.py:1450
                                                            `- 0.054 getit  sympy\core\assumptions.py:260
                                                               `- 0.054 _ask  sympy\core\assumptions.py:272
                                                                  `- 0.054 _eval_is_integer  sympy\core\mul.py:1251
                                                                     `- 0.054 getit  sympy\core\assumptions.py:260
                                                                        `- 0.054 _ask  sympy\core\assumptions.py:272
                                                                           |- 0.029 _ask  sympy\core\assumptions.py:272
                                                                           |  `- 0.024 _ask  sympy\core\assumptions.py:272
                                                                           `- 0.024 _eval_is_rational  sympy\core\mul.py:1220
                                                                              `- 0.024 _fuzzy_group  sympy\core\logic.py:40
                                                                                 `- 0.024 <genexpr>  sympy\core\mul.py:1221
                                                                                    `- 0.024 getit  sympy\core\assumptions.py:260
                                                                                       `- 0.024 _ask  sympy\core\assumptions.py:272
                                                                                          `- 0.024 _ask  sympy\core\assumptions.py:272
@@ -208,7 +208,6 @@ def _eval_trace(self, bra, **options):
assert t.doit() == 1


@slow

This comment has been minimized.

Copy link
@asmeurer

asmeurer Aug 12, 2019

Member

That's interesting that a quantum test is affected by this. Does the quantum module use the new assumptions?

This comment has been minimized.

Copy link
@ShubhamKJha

ShubhamKJha Aug 12, 2019

Author Member

It uses matrix methods, which in turn uses new assumptions.

Fixed failing sathandlers tests: Now UnevaluatedOnFree class returns …
…NNF objects when called with AppliedPredicate arguments, so changed all the result to NNF in tests
@codecov

This comment has been minimized.

Copy link

commented Aug 14, 2019

Codecov Report

Merging #17379 into master will increase coverage by 0.049%.
The diff coverage is 92.857%.

@@              Coverage Diff              @@
##            master    #17379       +/-   ##
=============================================
+ Coverage   74.669%   74.719%   +0.049%     
=============================================
  Files          631       633        +2     
  Lines       163172    164458     +1286     
  Branches     38282     38610      +328     
=============================================
+ Hits        121840    122882     +1042     
- Misses       35996     36183      +187     
- Partials      5336      5393       +57
@ShubhamKJha

This comment has been minimized.

Copy link
Member Author

commented Aug 18, 2019

ping @asmeurer @jksuom @oscarbenjamin this is ready for review.

@oscarbenjamin

This comment has been minimized.

Copy link
Contributor

commented Aug 18, 2019

I don't know the new assumptions well enough to fully understand this PR but it looks good. I find a ~15% speed up for the tests in sympy/assumptions.

sympy/assumptions/cnf.py Outdated Show resolved Hide resolved
@asmeurer

This comment has been minimized.

Copy link
Member

commented Aug 20, 2019

This looks mostly fine. I'm mostly worried that this makes it harder to extend the handlers with new kinds of classes, but I think we can refactor some of the logic into the base class to reduce that issue.

ShubhamKJha added 2 commits Aug 22, 2019
Simplified sathandlers. Now new sathandlers require only an apply() m…
…ethod (returning an NNF object) to work. Also simplified logic for rcall on CNF object
@ShubhamKJha

This comment has been minimized.

Copy link
Member Author

commented Aug 23, 2019

ping @asmeurer, please take a lot at the changes.

@asmeurer asmeurer merged commit 30c90c3 into sympy:master Aug 23, 2019

3 checks passed

codecov/project 74.719% (target 0%)
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
sympy-bot/release-notes The release notes look OK
Details
@ShubhamKJha

This comment has been minimized.

Copy link
Member Author

commented Aug 23, 2019

Thanks @asmeurer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.