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

Pass immutable arg_id_to_dtype to InKernelCallables #906

Merged
merged 1 commit into from
Jan 31, 2025

Conversation

alexfikl
Copy link
Contributor

This uses immutabledict whenever possible. It's not exactly clear to me if some of these should be passed in as immutable higher up the stack, so someone more knowledgeable should have a serious look.

Fixes #905.

@alexfikl alexfikl force-pushed the fix-callable-warnings branch 3 times, most recently from 4e57b84 to 011b5ee Compare January 29, 2025 14:20
@alexfikl
Copy link
Contributor Author

@inducer I can't say I'm a fan of this. Maybe a nicer workaround would be to have InKernelCallable.copy automatically cast to immutabledict?

@inducer
Copy link
Owner

inducer commented Jan 29, 2025

I'm torn. On the one hand, I agree it's a mess. On the other hand, I dislike all the implicit casting in constructor-like interfaces (copy counts as such, to me). While it seems convenient at first, I worry about cost, and dataclasses have a more-than-implicit nudge towards constructors without intelligence. So I don't hate having to cast to the right type where these things are being made from scratch.

A few practical concerns next up:

@alexfikl
Copy link
Contributor Author

I'm torn. On the one hand, I agree it's a mess. On the other hand, I dislike all the implicit casting in constructor-like interfaces (copy counts as such, to me). While it seems convenient at first, I worry about cost, and dataclasses have a more-than-implicit nudge towards constructors without intelligence. So I don't hate having to cast to the right type where these things are being made from scratch.

Yeah, agreed. My main worry was that it's a pain to find all the places that should be wrapped, but it's slowly getting there by rummaging through the warnings.

A few practical concerns next up:

Definitely fine with waiting for that to get in first.

  • This currently breaks Firedrake, on a mutability assumption. @connorjward, could you chime in? IIUC, this should be a simple patch on your end. (Cast to dict and back.)

Maybe it can be fixed on this side? I haven't looked too much into it..

@connorjward
Copy link
Contributor

This currently breaks Firedrake, on a mutability assumption. @connorjward, could you chime in? IIUC, this should be a simple patch on your end. (Cast to dict and back.)

I'm sure the fix would be straightforward, which I'm happy to do.

@inducer
Copy link
Owner

inducer commented Jan 30, 2025

Definitely fine with waiting for that to get in first.

It's in!

@connorjward
Copy link
Contributor

I have a branch that I am currently testing where I think this is fixed. I am happy for you to merge this when ready and then I will update our fork and get my things merged.

@alexfikl alexfikl force-pushed the fix-callable-warnings branch 3 times, most recently from 1bb84f8 to 8c7accf Compare January 30, 2025 17:13
@alexfikl alexfikl marked this pull request as ready for review January 30, 2025 17:14
@alexfikl
Copy link
Contributor Author

alexfikl commented Jan 30, 2025

Batch mutation should likely happen via an immutables-style mutation context manager. immutabledict doesn't have this, but we're switching to constandict anyway, which does.

I'm note quite sure where to use batch mutation stuff in here (if any?). Most places that cast to constantdict are in with_dtypes and they all cast to dict and then mutate that. Is that ok?

@alexfikl alexfikl force-pushed the fix-callable-warnings branch from 8c7accf to f169d82 Compare January 30, 2025 17:27
Comment on lines 42 to 47
new_arg_id_to_dtype = dict(arg_id_to_dtype)
for i in range(len(arg_id_to_dtype)):
if i in arg_id_to_dtype and arg_id_to_dtype[i] is not None:
new_arg_id_to_dtype[-i-1] = new_arg_id_to_dtype[i]

return (self.copy(arg_id_to_dtype=new_arg_id_to_dtype,
return (self.copy(arg_id_to_dtype=constantdict(new_arg_id_to_dtype),
Copy link
Collaborator

Choose a reason for hiding this comment

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

This could probably be smth like:

        new_arg_id_to_dtype = constantdict(arg_id_to_dtype).mutate()
        for i in range(len(arg_id_to_dtype)):
            if i in arg_id_to_dtype and arg_id_to_dtype[i] is not None:
                new_arg_id_to_dtype[-i-1] = new_arg_id_to_dtype[i]

        return (self.copy(arg_id_to_dtype=new_arg_id_to_dtype.finish()),

This avoids a second copy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I see! Thanks a lot for the example. I'll make those changes.

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 think I got all the places where this made sense (at least in the parts that were already modified). Let me know if you spot anything else!

@alexfikl alexfikl force-pushed the fix-callable-warnings branch 2 times, most recently from 3321e22 to 395d313 Compare January 31, 2025 08:14
@alexfikl alexfikl force-pushed the fix-callable-warnings branch from 395d313 to b86f8a1 Compare January 31, 2025 08:17
@alexfikl
Copy link
Contributor Author

@inducer This should be ready for a look now.

@connorjward It seems like the Firedrake failure was on this side.. I prematurely cast something to constantdict. It all works now!

@inducer inducer merged commit 2f4a982 into inducer:main Jan 31, 2025
18 checks passed
@inducer
Copy link
Owner

inducer commented Jan 31, 2025

Thanks! In it goes.

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.

Large number of arg_id_to_{dtype,descr} deprecation warnings raised internally by loopy
4 participants