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

Refactoring Expressions #43

Merged

Conversation

CactusWin
Copy link
Collaborator

@CactusWin CactusWin commented Aug 23, 2022

Main Files Changed

In the symbolic folder

  • expression.py
  • basic_expression.py
  • sympy_expression.py
  • z3_expression.py

In the util folder

  • callable_util.py
  • symbolic_error_util.py
  • sympy_util.py => Xiang already had this and z3_util
  • z3_util.py

Linting

I downloaded black to lint the file (pip install black) => black file_name --fast. I'm linting now, so the files are cleaner to read and to make it easier for us to switch to fbcode. I think this is the linter that phabriactor is based off.

Organization

I moved all the extraneous files into a util file. I created 2 util files (symbolic_error_util and callable_util)

  • I put all of the helper functions that are used for callable purposes in callable_util
  • I put all of the helper functions that are used for sympy purposes in sympy_util
  • I put all of the helper classes that are used for errors in symbolic_error_util

I made sure all of the import functions are used => removed any that are unused
I ordered the functions and classes the same along files.

Code

There is no new code!

Tests

I commented out a test in normalizer_test because it is failing in the main branch

Reviewing

I think it'll be easier to review this PR with the raw file, rather than going through the GitHub interface

Next Steps

  • Refactor other parts of symbolic in another PR

@CactusWin CactusWin marked this pull request as draft August 23, 2022 23:56
@@ -289,14 +347,22 @@ def basic_add_operation(type_) -> BasicAbelianOperation:
return BasicAbelianOperation(operator.add, BasicConstant(0, type_), operator.neg)


def BasicSummation(type_: type, index: Variable, constraint: Context, body: Expression) -> BasicQuantifierExpression:
def basic_summation(
Copy link
Collaborator Author

@CactusWin CactusWin Aug 24, 2022

Choose a reason for hiding this comment

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

Renamed this and BasicIntegral to follow the python convention of naming functions

Copy link
Collaborator Author

@CactusWin CactusWin left a comment

Choose a reason for hiding this comment

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

I reordered a lot of the functions to make the consistent throughout the file.

import neuralpp.symbolic.functions as functions


class AmbiguousTypeError(TypeError, ValueError):
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 moved all the error classes to a new folder. I realized that these files are hard to read because of how many things there are in the files.

super().__init__(f"{python_callable} is ambiguous.")


def boolean_function_of_arity(arity: int) -> Callable:
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 moved these extra functions that do not depend on Expression to the util folder. I had to remove a function from that folder due to circular dependency.

@CactusWin CactusWin marked this pull request as ready for review August 24, 2022 19:07
@@ -50,6 +50,21 @@ def _symbolically_eliminate(operation: AbelianOperation, index: Variable, interv
return None


def _map_leaves_of_if_then_else(conditional_intervals: Expression,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Moved this from utils due to circular dependency

@CactusWin CactusWin marked this pull request as draft August 26, 2022 17:46
@CactusWin CactusWin marked this pull request as ready for review August 26, 2022 18:12
@@ -181,6 +181,8 @@ def from_constraint(index: Variable, constraint: Context, context: Context, is_i
For example, x > 0 and x <= 5 should return an interval [1, 5]
More complicated cases will be added later
"""
if profiler is None:
profiler = Profiler()
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added this for the interval test to pass

@CactusWin CactusWin mentioned this pull request Aug 26, 2022
Copy link
Owner

@rodrigodesalvobraz rodrigodesalvobraz left a comment

Choose a reason for hiding this comment

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

Thanks, Winnie, it's great you did this!

@rodrigodesalvobraz rodrigodesalvobraz merged commit c51825c into rodrigodesalvobraz:main Aug 30, 2022
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.

2 participants