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

Add ScalarVariable canonicalizations and rewrites #1235

Open
brandonwillard opened this issue Oct 4, 2022 · 0 comments
Open

Add ScalarVariable canonicalizations and rewrites #1235

brandonwillard opened this issue Oct 4, 2022 · 0 comments
Labels
enhancement New feature or request graph rewriting help wanted Extra attention is needed important question Further information is requested request discussion

Comments

@brandonwillard
Copy link
Member

brandonwillard commented Oct 4, 2022

We don't really have any canonicalizations or rewrites for ScalarVariable-based (sub-)graphs.

For example, this would simplify at compile-time in the TensorVariable case:

import aesara
import aesara.tensor as at
from aesara.scalar import int64


a = int64("a")

z = 0 * a

test_fn = aesara.function([a], [z])

aesara.dprint(test_fn)
# mul [id A] 0
#  |ScalarConstant{0} [id B]
#  |a [id C]

Normally, these kinds of graphs wouldn't be generated by a user, so the issue doesn't arise all that often; however, I've noticed some examples of this during debugging that appear to arise from the construction of Composite Ops.

On a related note, we're missing a canonicalization that "compresses" nested Composites:

import aesara
from aesara.scalar import int64, Composite


a = int64("a")

c_op_1 = Composite([a], [a * 2])
c_op_2 = Composite([a], [c_op_1(a) + 3])

z = c_op_2(a)

test_fn = aesara.function([a], [z])

aesara.dprint(test_fn)
# Composite{(Composite{(i0 * 2)}(i0) + 3)} [id A] 0
#  |a [id B]

I'll need to dig up those examples I saw among the Scan tests and demonstrate how these cases arise via our TensorVariable-only interface. In general, we probably want to stick with a TensorVariable-only interface and make as many changes as we can to prevent these situations from arising, but we may also need some of these rewrites regardless.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request graph rewriting help wanted Extra attention is needed important question Further information is requested request discussion
Projects
None yet
Development

No branches or pull requests

1 participant