-
Notifications
You must be signed in to change notification settings - Fork 2
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
Remove the Model
abstract type, simplify model migration code.
#172
base: withmodel_subtype
Are you sure you want to change the base?
Conversation
typecon too allow subtyping in WithModel Change how import works. remove redundant Using Gatlab . . fix docstrings .
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## withmodel_subtype #172 +/- ##
=====================================================
- Coverage 95.56% 95.43% -0.14%
=====================================================
Files 38 38
Lines 2234 2257 +23
=====================================================
+ Hits 2135 2154 +19
- Misses 99 103 +4 ☔ View full report in Codecov by Sentry. |
Model
abstract type, simply model migration code.Model
abstract type, simplify model migration code.
@@ -75,20 +71,26 @@ struct ImplementationNotes | |||
end | |||
|
|||
""" | |||
`implements(m::Model, tag::ScopeTag) -> Union{ImplementationNotes, Nothing}` | |||
`implements(m::MyModel, tag::ScopeTag) -> Union{ImplementationNotes, Nothing}` |
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.
shouldn't this be on the first line indented by 4 spaces to make it monospace?
@@ -9,13 +9,15 @@ using StructEquality | |||
hom::HomT | |||
end | |||
|
|||
@struct_hash_equal struct SliceC{ObT, HomT, C<:Model{Tuple{ObT, HomT}}} <: Model{Tuple{SliceOb{ObT, HomT}, HomT}} | |||
@struct_hash_equal struct SliceC{ObT, HomT, C} |
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.
I like this massive reduction in type constraining code
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.
Given the considerations in my comments below, it seems like this would become
@struct_hash_equal struct SliceC{ObT, HomT, C<:Model} <: Model
... # same code inside
end
which is still an improvement!
This PR's change makes life much easier in many ways, including those in the original description and also things like allowing Models to be subtypes of other abstract types (rather than forcing any type that is used as a Model to be a subtype of GATlab's particular abstract type). But I've realized now that GATlab's Base.getindex(::typeof(f), m::Any) = args -> f(WithModel(m), args...) However GATlab doesn't own any of There are a few ways to address this.
|
I came to this realization because I wanted to write What would be nice is to just define once Base.getindex(any_method, any_model) = args -> any_method(WithModel(any_model), args...) Which is blatant type piracy that brought this all to my attention. So, one argument for option 3 above is that we could do this: Base.getindex(any_method, any_model::Model) = args -> any_method(WithModel(any_model), args...) Or perhaps with |
I think that requiring a fixed super type for models or methods would really limit the utility of this whole goal. Can we provide a macro that is a thin wrapper around function definition that lets users register the method with the model and generate the right method definition to avoid piracy? The problem is that we can't overload getindex withour specializing on the type of the model or the type of the function. But if we used a manual opt-in, you would have those types to define specialized methods. |
I think you're suggesting a macro that take a function name (e.g. Base.getvalue(::typeof(pullback), m::WithModel{T}) where T = xs -> pullback(m, xs...) I agree this is nicer than making some random theory with This doesn't address the problem of needing to sprinkle in |
This PR removes the
Model
abstract type which was overly constraining (preventing one and the samestruct
from being a model of many different theories). One purpose theModel
type served was to make it easy to see what Julia types were associated with the theory type constructors, but this functionality is now provided byimpl_type
methods which get defined by@instance
.This also led to an opportunity to simply model migration code, which is no longer handled convolutedly within the module of a
@theorymap
but instead is a function (which callseval
to create a new struct which just wraps the input model). If we start actually using model migrations and get worried about generating too many structs, it wouldn't be hard to cache the inputs to this function.All interesting changes are in
ModelInterface.jl
. Lots of tiny changes (mostly removing<: Model{...}
are in other files.