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

feat: port diff implementation from gen.jl (4/n) #56

Merged
merged 1 commit into from
Nov 28, 2023
Merged

Conversation

sritchie
Copy link
Collaborator

This PR ports more of the diff.jl implementation over from Gen.jl: https://github.com/probcomp/Gen.jl/blob/master/src/diff.jl

This is not complete, but gives us a base that supports the dynamic language and lets us start moving toward proper support for argdiffs on the interfaces that need it.

@sritchie sritchie requested a review from zane November 14, 2023 22:43
Copy link

codecov bot commented Nov 14, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (868346a) 71.88% compared to head (9d900a8) 72.15%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #56      +/-   ##
==========================================
+ Coverage   71.88%   72.15%   +0.26%     
==========================================
  Files          20       20              
  Lines         996     1009      +13     
  Branches       24       25       +1     
==========================================
+ Hits          716      728      +12     
  Misses        256      256              
- Partials       24       25       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sritchie sritchie changed the title feat: port diff implementation from gen.jl feat: port diff implementation from gen.jl (4/n) Nov 15, 2023
@sritchie sritchie requested review from littleredcomputer and removed request for zane November 21, 2023 15:14
"If `x` is an instance of [[IDiffed]], returns the wrapped value. Else, acts
as identity."))

(extend-protocol IDiffed

Choose a reason for hiding this comment

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

Does this interface need to be total, in the sense that every object in the universe should support get-diff and strip-diff?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

My thought was that if it was, we could gradually add support for this and gracefully fall back for cases we hadn't added yet. Here is the corresponding Gen.jl code: https://github.com/probcomp/Gen.jl/blob/master/src/diff.jl

Choose a reason for hiding this comment

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

I can see your point. Looking here, it seems to me that the Julia code lets the arguments carry the Diff nature in their types, but then uses a macro to enable such things to silently enter unary and binary operations. I could see it either way.

The PR is fine of course, but I'm curious as to how you will implement the generic operations so that they can transport the "joint difference" of the arguments to the result. I'd still argue for testing the arguments with satisfies? rather than adding the default case, or if you're going to use multifns à la Emmy then you could add defmethods for all the possibilities of diffed and undiffed arguments. An interesting case!

Copy link

@littleredcomputer littleredcomputer left a comment

Choose a reason for hiding this comment

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

LG, but consider the question of whether

  • (extend-type Object ...)
  • (defmethod get-diff :default ...) or
  • (satisfies? IDiff)
    would be best for Gen, since I sometimes fret about which approach is best. in CLJS, the extend-type approach adds the implementation to a map of types to implementations which has to be consulted when the function is called, so I think it's the least attractive of the implementations, unless that is consistent with the spirit of Gen

@sritchie
Copy link
Collaborator Author

@littleredcomputer , @zane pointed out that satisfies? is actually quite slow, so I think the default impl might be the way to go here. I'm going to keep this as-is, and then we can do a pass and potentially try and remove all satisfies? calls if and when it matters.

@sritchie sritchie merged commit 56551c1 into main Nov 28, 2023
5 of 6 checks passed
@sritchie sritchie deleted the sritchie/diff branch November 28, 2023 17:31
@littleredcomputer
Copy link

@littleredcomputer , @zane pointed out that satisfies? is actually quite slow, so I think the default impl might be the way to go here. I'm going to keep this as-is, and then we can do a pass and potentially try and remove all satisfies? calls if and when it matters.

Perhaps, but I wonder how Clojure can conclude that the default implementation is applicable faster than satisfies? could say no. Might be worth it (to me) to understand that better.

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.

2 participants