Skip to content

Improve string representation of Assert Ops #739

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

Closed

Conversation

ricardoV94
Copy link
Member

Description

Makes graphs with Assert a bit more readable

Checklist

Type of change

  • New feature / enhancement
  • Bug fix
  • Documentation
  • Maintenance
  • Other (please specify):

@ricardoV94 ricardoV94 force-pushed the improve_assert_str_repr branch from f56cd76 to 973c1d5 Compare May 1, 2024 12:51
@@ -48,7 +48,13 @@ def __init__(self, exc_type, msg=""):
self.msg = msg

def __str__(self):
return f"CheckAndRaise{{{self.exc_type}({self.msg})}}"
name = self.__class__.__name__
Copy link
Member

Choose a reason for hiding this comment

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

Will the name variable not always be instance of CheckAndRaise in itself here? If so what is the benefit of having a separate variable for it?

Copy link
Member Author

Choose a reason for hiding this comment

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

If there is a subclass it will use the subclass name instead

Comment on lines +53 to +56
if len(self.msg) > 30:
msg = self.msg[:27] + "..."
else:
msg = self.msg
Copy link
Member

Choose a reason for hiding this comment

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

I am a bit conflicted here. Why do we want to contain the error message? I understand that it makes the code more readable but it would also hide some important information regarding the message. Although the length of 27 again seems sufficient when displaying the error message.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is just for the text representation (like when doing pytensor.dprint). If the assert fails during execution, the whole message will be print out.

Right now showing the whole message makes graph printing pretty ugly. That's the whole point of this PR

Copy link
Member

Choose a reason for hiding this comment

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

Ohh I see. LGTM 👍

@ricardoV94
Copy link
Member Author

ricardoV94 commented May 14, 2024

Need to fix some tests that depended on the graph representation of Assert. @Dhruvanshu-Joshi could you help out with this? You should be able to checkout my branch and push to it directly from git

@Dhruvanshu-Joshi
Copy link
Member

Need to fix some tests that depended on the graph representation of Assert. @Dhruvanshu-Joshi could you help out with this? You should be able to checkout my branch and push to it directly from git

Hi @ricardoV94 . I have solved the error with these changes locally. However, I am unable to push the changes to your fork of the branch in order for the changes to appear here. Should I open a separate PR and reference it here?

@Dhruvanshu-Joshi
Copy link
Member

Contd in #891

@jessegrabowski
Copy link
Member

This should be closed if it is superseded by #891

@ricardoV94 ricardoV94 closed this Jul 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants