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

Updated pymc.simulator docstring (typos, defaults, type description) #6035

Merged
merged 4 commits into from
Aug 13, 2022

Conversation

daniel-saunders-phil
Copy link
Contributor

What is this PR about?

fixing a number of issues with the pymc.simulator docstring.

...

Checklist

Major / Breaking Changes

  • ...

Bugfixes / New features

  • ...

Docs / Maintenance

  • ... added defaults to each parameter, changed instances of Aesara Op to correct format Aesara_Op, fixed a typo

@codecov
Copy link

codecov bot commented Aug 6, 2022

Codecov Report

Merging #6035 (fb72b2e) into main (a8279d7) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #6035      +/-   ##
==========================================
- Coverage   89.30%   89.29%   -0.01%     
==========================================
  Files          72       72              
  Lines       12890    12890              
==========================================
- Hits        11511    11510       -1     
- Misses       1379     1380       +1     
Impacted Files Coverage Δ
pymc/distributions/simulator.py 87.50% <100.00%> (ø)
pymc/distributions/continuous.py 97.47% <0.00%> (-0.43%) ⬇️
pymc/distributions/multivariate.py 92.00% <0.00%> (-0.03%) ⬇️
pymc/func_utils.py 88.37% <0.00%> (+0.87%) ⬆️
pymc/parallel_sampling.py 86.79% <0.00%> (+0.99%) ⬆️

Copy link
Member

@OriolAbril OriolAbril left a comment

Choose a reason for hiding this comment

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

Thanks!

It already looks great, and the docs look better and are more clear already. I left some more comments, plus this one here because it is on a line I wasn't able to comment on: the short description also has

``pm.sample_smc``
# should instead be
:func:`~pymc.sample_smc`

it should return a 1d numpy array (or Aesara vector).
epsilon : float or array
epsilon : float or array, default 1.0
Copy link
Member

Choose a reason for hiding this comment

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

I think this should be tensor_like of float

Number of dimensions of the SimulatorRV (0 for scalar, 1 for vector, etc.)
Defaults to ``0``.
ndims_params : list[int]
ndims_params : list[int], default 0 for each parameter.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
ndims_params : list[int], default 0 for each parameter.
ndims_params : list of int, optional

As the default is a bit complex here, it is not a value we can add here but something that depends on other parameters, I would use optional and keep the explanation in the description

Comment on lines 83 to 85
be passed by order, in which case the keyword argument ``params`` is
ignored. Alternatively, each parameter can be passed by order after fn,
``param1, param2, ..., paramN``
Copy link
Member

Choose a reason for hiding this comment

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

Can't comment further up. It looks like unnamed_params is missing. I think it should be something like

*unnamed_params : list of TensorVariable
    description starts here
params : list of TensorVariable
    description extended here, plus mention that if both are present an error is thrown.

someone else will need to take over on the actual description though as I don't really know what to write. Is one preferred over the other, are there any potential behaviour differences?

If they are both exactly the same, then the we can follow for example xarray's pattern where this situation is very common with kwargs, see for example: https://docs.xarray.dev/en/stable/generated/xarray.Dataset.rename.html

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks like they should behave identically. If the keyword argument isn't passed, then params just gets defined as the unnamed_params and then params is used throughout the rest of the file. I went ahead and wrote a description similar to xarray.

@daniel-saunders-phil
Copy link
Contributor Author

Hi Oriol, thanks for the feedback - these suggestions are really helpful. I'm a bit unsure about the procedure. To revise a pull request, do I make the changes on my branch and then resubmit the whole PR through the git command line instructions or is there a different procedure?

@OriolAbril
Copy link
Member

Make the changes locally and commit them to the branch you opened your PR from, docstring_update in this case. After that you only need to push the changes and this same PR will be updated automatically with the new commits.

This is the last section in https://pymc-data-umbrella.xyz/en/latest/sprint/tutorials/pr_tutorial.html#get-ready-for-reviews which has the specific commands and extends the overview I gave in the above paragraph.

@daniel-saunders-phil
Copy link
Contributor Author

I implemented the suggested changes and then pushed them.

Also, one thing came up that wasn't strictly a docstring fix. I noticed the file uses inconsistent spellings of Kullback-Leiber and the class is incorrectly called KullbackLiebler. I thought we might want to change all of them to the correct spelling. I searched through the rest of the pymc package and couldn't find any references to the incorrectly spelled class, so I don't think this should cause trouble for other functions. But I'm also happy to ignore this and just stick to docstrings for now.

@reshamas
Copy link
Contributor

reshamas commented Aug 7, 2022

@daniel-saunders-phil
I think it's ok to fix the spelling of Kullback-Leiber.
I've been fixing spelling in the notebooks I have been updating, and it's been ok.

@daniel-saunders-phil
Copy link
Contributor Author

I’m not sure how to handle this pre-commit problem. I’m gonna try to figure it out for a little bit but I might have some questions in a couple of days.

@reshamas
Copy link
Contributor

reshamas commented Aug 9, 2022

@daniel-saunders-phil I am working on my 3rd notebook and, once again(!), stuck at the pre-commit stage. (+ possible git issue)

@OriolAbril
Perhaps we should have a special office hours session on how to get through pre-commit. ;)

cc: @symeneses

@OriolAbril
Copy link
Member

@daniel-saunders-phil if you click on the "Details" button of the checks seciton you'll be able to see the checks logs. In this PR, the issue is with the "trim trailing whitespace": https://github.com/pymc-devs/pymc/runs/7715083643?check_suite_focus=true#step:4:64.

That means that there are lines that end up with a white character instead of finishing with the last letter/punctiation sign of the line. If you have followed the steps from https://pymc-data-umbrella.xyz/en/latest/sprint/tutorials/environment_setup.html to set up your environment, you can run pre-commit run --all on your command line (while inside the pymc-dev environment). pre-commit will fail, but it will also modify the files and remove those trailing whitespaces. You can then git add and git commit those changes and push, which should fix the CI here.

@daniel-saunders-phil
Copy link
Contributor Author

It looks like all tests are passing this time! after a little bit of tinkering, I managed to get pre-commit working. Thanks a lot, @OriolAbril and @reshamas !

pymc/distributions/simulator.py Outdated Show resolved Hide resolved
pymc/distributions/simulator.py Outdated Show resolved Hide resolved
pymc/distributions/simulator.py Outdated Show resolved Hide resolved
pymc/distributions/simulator.py Outdated Show resolved Hide resolved
pymc/distributions/simulator.py Outdated Show resolved Hide resolved
Copy link
Member

@michaelosthege michaelosthege left a comment

Choose a reason for hiding this comment

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

Sorry for requesting changes this late, but I think we should keep an alias of the KullbackLeibler class:

class KullbackLiebler(KullbackLeibler):
    def __init__(self,  *args, **kwargs):
        """Alias for KullbackLeibler."""
        warnings.warn("You are using `KullbackLiebler` which is a typo. Use `KullbackLeibler` instead.", DeprecationWarning)
        super(). __init__(*args, **kwargs)

@OriolAbril
Copy link
Member

I considered it too but but eventually decided on not doing it because 1) it is not included in our docs and therefore not part of the public api and 2) no tests broke because it has not been refactored to v4, so it would be a breaking change on the private api with a major change version, from 3.11 to 4.x (whatever the version it gets updated).

We can still add the alias to be nice, but then it should have a different type of warning. This is the description of deprecationwarning in https://docs.python.org/3/library/exceptions.html#DeprecationWarning :

Base class for warnings about deprecated features when those warnings are intended for other Python developers.

Ignored by the default warning filters, except in the main module (PEP 565). Enabling the Python Development Mode shows this warning.

Copy link
Member

@michaelosthege michaelosthege left a comment

Choose a reason for hiding this comment

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

ok, thanks Oriol! I didn't realize this wasn't public API.

@michaelosthege michaelosthege merged commit 906fcdc into pymc-devs:main Aug 13, 2022
@reshamas
Copy link
Contributor

Congrats @daniel-saunders-phil !

#DataUmbrellaPyMCSprint

@daniel-saunders-phil daniel-saunders-phil deleted the docstring_update branch August 18, 2022 19:14
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.

4 participants