-
-
Notifications
You must be signed in to change notification settings - Fork 74
Model formatting #539
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
Model formatting #539
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of comments
file.write(result) | ||
else: | ||
print(result) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Printing is not very pythonic. Should it just return the result?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am thinking of how a user would use this method and I have a hard time imagining when they'd actually want the string as a result. If anything it encourages the style of programming we don't want, where the model code ends up stored as a string in the python code.
The workflow I'm imagining for this function is that it will either be used so that someone can preview the output, in which case printing is the right thing to do, or they will be batch-processing stan files and formatting them, in which case they'd be saving them back to disk.
I can be persuaded that this is too narrow, however
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I think printing is ok in this case
I want to write a few more test cases but need to update my local cmdstan to 2.29 to do so first. I'll try to do this by the end of the day |
Codecov Report
@@ Coverage Diff @@
## develop #539 +/- ##
===========================================
- Coverage 79.41% 79.25% -0.17%
===========================================
Files 45 15 -30
Lines 9600 3234 -6366
===========================================
- Hits 7624 2563 -5061
+ Misses 1976 671 -1305 Continue to review full report at Codecov.
|
Sorry for jumping late, I am about to add the same thing for cmdstanr and was just wondering about naming. I know naming is hard and I know I am jumping in the last minutes, just bouncing a few ideas that come to mind before we release this feature.
|
I agree on all three counts, |
One more suggestion: exposing max_line_length? EDIT: I did add it in the CmdStanR PR. |
Will do that as well, hopefully tomorrow |
Submission Checklist
Summary
Add
model.format_model
. This callsstanc --auto-format
, with optional arguments to 'canonicalize' the program. By default the formatted model is printed, ifsave=True
is passed it is written back out to the file on disk, after first creating a copy (namedfilename.stan.bak
)Copyright and Licensing
Please list the copyright holder for the work you are submitting (this will be you or your assignee, such as a university or company):
Simons Foundation
By submitting this pull request, the copyright holder is agreeing to license the submitted work under the following licenses: