-
Notifications
You must be signed in to change notification settings - Fork 125
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
Improve creating an Op documentation page #1086
base: main
Are you sure you want to change the base?
Conversation
@@ -165,35 +151,6 @@ or :meth:`Op.make_thunk`. | |||
:meth:`COp.c_code` and other related ``c_**`` methods. Note that an | |||
:class:`Op` can provide both Python and C implementations. | |||
|
|||
:meth:`Op.make_thunk` method is another alternative to :meth:`Op.perform`. |
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.
This is outdated, and tbh I don't think it's necessary for 99.9999% of the people reading this page
2f1a456
to
3a77d6b
Compare
d37103d
to
1d9bc2b
Compare
doc/extending/creating_an_op.rst
Outdated
@@ -1,40 +1,18 @@ | |||
|
|||
.. _creating_an_op: | |||
|
|||
Creating a new :class:`Op`: Python implementation | |||
Creating a new :ref:`op`: Python implementation |
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.
Where do you want the :ref:`op`
/:class:`Op`
to point to? To https://pytensor--1086.org.readthedocs.build/en/1086/extending/op.html or to https://pytensor--1086.org.readthedocs.build/en/1086/extending/graphstructures.html#op?
I think many of the broken cross-references come from this page: https://pytensor--1086.org.readthedocs.build/en/1086/extending/op.html, which is wildly inconsistent with itself. If the cross-reference would ideally point there we should fix this page first.
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.
Will check. I just wanted it to point somewhere, it wasn't before
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.
@OriolAbril extending op seems much more useful than the graphstructures#op, so I guess there.
doc/extending/creating_an_op.rst
Outdated
has no bugs, and potentially profits from rewrites that have already been | ||
implemented. | ||
Odds are your function that uses existing PyTensor expressions is short, has no bugs, can be differentiated, | ||
and may even work in non-default backends and benefit from optimization rewrites. |
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.
Suggestion: "A PyTensor function that builds upon existing expressions tends to be concise, reliable, and automatically differentiable, while often working seamlessly across different backends, thereby benefiting from optimization."
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.
Rewrote to something in that vein but simpler
ec648b9
to
ade5653
Compare
ade5653
to
f797c62
Compare
Changes: 1. Remove references to c-code which apply to `COp` but not `Op` 2. Fix failing doctests 3. Improve explanation of `make_node` 4. Emphasize distinction between itypes/otypes and make-node 5. Show `L_op` instead of `grad` 6. Show how to test `L_op` and `infer_shape` implementation 7. Simplify explanation of `__props__` and illustrate in example. 8. Introduce more complex multi-output Op to drive these details home 9. Remove old references to numba/ random variable Ops
f797c62
to
c64736a
Compare
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.
Just a few typos. LGTM.
|
||
- it first checks that the input :class:`Variable`\s types are compatible | ||
with the current :class:`Op`. If the :class:`Op` cannot be applied on the provided | ||
input types, it must raises an exception (such as :class:`TypeError`). |
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.
Typo: must raise
pass | ||
|
||
def R_op(self, inputs, eval_points): | ||
# Defines that symbolic expression for the R-operator based on the input variables |
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.
should be "the symbolic"(?)
|
||
def R_op(self, inputs, eval_points): | ||
# R_op can receive None as eval_points. | ||
# That mean there is no diferientiable path through that input |
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.
2 Typos: "That means" and "differentiable"
|
||
def perform(self, node, inputs, output_storage): | ||
# Validate input type | ||
if not x.type.ndim == 2 and x.type.dtype == "float64": |
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.
need to enclose conditions in parentheses
|
||
x = pytensor.tensor.matrix() | ||
x = matrix(x, dtype="float64") |
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.
matrix name should be enclosed in quotes
|
||
For instance, to verify the :meth:`Rop` method of the ``DoubleOp``, you can use this: | ||
For instance, to verify the :meth:`R_op` method of the ``DoubleOp``, you can use this: |
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.
do you mean "of the DoubleROp
" here?
|
||
.. code-block:: none | ||
Finally we should test the gradient implementation. | ||
For this we can use the ``pytensor.gradient.verify_grad`` utility which will compare the output of a gradient function with fininte differences. |
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.
Type: "finite"
|
||
PyTensor has some functionalities to test for a correct implementation of an :class:`Op` and it's many methods. | ||
|
||
We have already seen some user facing helpers, but there are also test classes for :class:`Op` implementations |
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.
nit: "user-facing"
See commit message for list of changes.
The changes are based on feedback from helping other devs and users
Tagging @OriolAbril because I'm 100% sure I messed up some sphinx stuff (sorry)
📚 Documentation preview 📚: https://pytensor--1086.org.readthedocs.build/en/1086/