Skip to content

Fix latex repr of symbolic distributions #6231

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

Merged
merged 14 commits into from
Oct 30, 2022

Conversation

mattiadg
Copy link
Contributor

@mattiadg mattiadg commented Oct 19, 2022

Fix #6202

  • Do not put \operatorname inside \text
  • add test

What is this PR about?
When a symbolic distribution is defined as parameter of another one, the latex representation is broken.
This PR aims to solve this.

I think that the new failing tests are testing the wrong behavior, this is a draft because I would like someone more experienced with this to check on them.
What I'm doing is to remove \operatorname from inside \text because it's wrong.

Checklist

Major / Breaking Changes

  • ...

Bugfixes / New features

  • Fix broken latex representation of distributions inside other distributions

Docs / Maintenance

  • ...

* Do not put \operatorname inside \text
* add test
@ricardoV94 ricardoV94 marked this pull request as draft October 20, 2022 10:08
@ricardoV94 ricardoV94 changed the title [DRAFT] Fix latex repr of symbolic distributions Fix latex repr of symbolic distributions Oct 20, 2022
@codecov
Copy link

codecov bot commented Oct 20, 2022

Codecov Report

Merging #6231 (1d5940d) into main (9105d74) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #6231   +/-   ##
=======================================
  Coverage   94.14%   94.14%           
=======================================
  Files         100      100           
  Lines       21235    21239    +4     
=======================================
+ Hits        19992    19996    +4     
  Misses       1243     1243           
Impacted Files Coverage Δ
pymc/printing.py 86.55% <100.00%> (+0.46%) ⬆️

dfm and others added 5 commits October 21, 2022 09:19
…-devs#6232)

* Adding option to include transformed variables in InferenceData

Co-authored-by: Michael Osthege <[email protected]>
* remove them from the string borders since they always represent the math environment
* remove them from the string borders since they always represent the math environment
* fix tests to check the correct behavior
@mattiadg mattiadg marked this pull request as ready for review October 21, 2022 07:46
# Conflicts:
#	pymc/tests/test_printing.py
@mattiadg
Copy link
Contributor Author

Is anything else needed here?

# Conflicts:
#	pymc/tests/test_printing.py
@mattiadg
Copy link
Contributor Author

I've already solved conflicts twice because people keep adding wrong tests for the latex printing.
That functionality is currently broken as #6202 shows, so the tests must be wrong in order to fail.
Please, have a loot at this PR before merging additional code in test_printing.py.

@ricardoV94
Copy link
Member

I've already solved conflicts twice because people keep adding wrong tests for the latex printing. That functionality is currently broken as #6202 shows, so the tests must be wrong in order to fail. Please, have a loot at this PR before merging additional code in test_printing.py.

That sometimes happens, a reviewer may be able to get to another PR and merge it before yours. Sorry for the trouble, but it's also something one must get used to :)

@mattiadg
Copy link
Contributor Author

mattiadg commented Oct 25, 2022 via email

Copy link
Member

@Spaak Spaak left a comment

Choose a reason for hiding this comment

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

LGTM in general, though the testing should be fixed.

Copy link
Member

@Spaak Spaak left a comment

Choose a reason for hiding this comment

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

LGTM!

@Spaak
Copy link
Member

Spaak commented Oct 27, 2022

Looks good to me, thanks for adding the tests so quickly. I'll leave merging to someone else (eg @ricardoV94) because it's been a while for me.

@mattiadg
Copy link
Contributor Author

Looks good to me, thanks for adding the tests so quickly. I'll leave merging to someone else (eg @ricardoV94) because it's been a while for me.

That was easy, I added as tests the exact same distributions used in the issue to show the problem. This way it's also possible to reference back to them, should something go wrong in the future.
However, I still need to understand the two branches of Codecov: patch and project. I am still not sure why patch became lower initially

Copy link
Member

@larryshamalama larryshamalama left a comment

Choose a reason for hiding this comment

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

Looks good, thanks for your help! Glad that you were able to solve the other conflicts following the merge of #6242

return r"f(" + ", ".join([n.strip("$") for n in names]) + ")"


def _latex_text_format(text: str) -> str:
Copy link
Member

Choose a reason for hiding this comment

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

Okay for now, but I have a sense that this can be simplified since you're always using it on an output of _latex_escape

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can add the call to _latex_escape(text.strip("$") inside _latex_text_format and call this also in the other 2 occurrences of _latex_escape. Then, we can also remove the naked \text{ in there.

@michaelosthege
Copy link
Member

@mattiadg there appears to be one more conflict?

Would be great to push this over the finish line as we have a release coming up!

@michaelosthege michaelosthege added this to the v4.3.0 milestone Oct 30, 2022
@mattiadg
Copy link
Contributor Author

mattiadg commented Oct 30, 2022 via email

@mattiadg
Copy link
Contributor Author

@mattiadg there appears to be one more conflict?

Would be great to push this over the finish line as we have a release coming up!

done

@michaelosthege
Copy link
Member

Nice, thank you for fixing these @mattiadg !

@michaelosthege michaelosthege merged commit ea721e4 into pymc-devs:main Oct 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.

Improve Latex representation of symbolic distributions
7 participants