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

simplify types #23

Merged
merged 22 commits into from
Nov 17, 2021
Merged

simplify types #23

merged 22 commits into from
Nov 17, 2021

Conversation

rkurchin
Copy link
Collaborator

Starting to work on this. Will try to commit-by-commit remove more things (and only ever committing a working state) so if we decide we want to go only part of the way, it's easy to just revert. This present commit removes only the AbstractElement type, which, now that I've done it, seems like unambiguously a good idea and I don't think it was adding much of anything.

Signed-off-by: Rachel Kurchin <rkurchin@cmu.edu>
…mmit, put them back

Signed-off-by: Rachel Kurchin <rkurchin@cmu.edu>
@codecov-commenter
Copy link

codecov-commenter commented Nov 10, 2021

Codecov Report

Merging #23 (9a01ba9) into master (0007177) will increase coverage by 47.36%.
The diff coverage is 45.45%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master      #23       +/-   ##
===========================================
+ Coverage    0.00%   47.36%   +47.36%     
===========================================
  Files           4        4               
  Lines          97       76       -21     
===========================================
+ Hits            0       36       +36     
+ Misses         97       40       -57     
Impacted Files Coverage Δ
src/implementation_soa.jl 52.63% <40.00%> (+52.63%) ⬆️
src/atoms.jl 43.75% <43.75%> (ø)
src/interface.jl 35.71% <44.44%> (+35.71%) ⬆️
src/implementation_aos.jl 69.23% <66.66%> (+69.23%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0007177...9a01ba9. Read the comment docs.

Signed-off-by: Rachel Kurchin <rkurchin@cmu.edu>
Signed-off-by: Rachel Kurchin <rkurchin@cmu.edu>
@rkurchin
Copy link
Collaborator Author

Okay, there we have it! Personally, I feel quite good things up through fede982, but I'm on the fence about also removing AbstractSystem...I can't decide if what we gain in flexibility offsets what we would lose in being able to dispatch things with some guarantees about things like dimensionality, what sorts of particles make up the system, etc., the way we can with an AbstractSystem that would have those things as type parameters. Eager to discuss.

I've also made some notes to myself about other potential small tweaks, the applicability of some of which will depend on how many commits in this we keep, so I'll do them after we decide rather than cluttering up the history here.

Signed-off-by: Rachel Kurchin <rkurchin@cmu.edu>
Signed-off-by: Rachel Kurchin <rkurchin@cmu.edu>
… file that somehow came back

Signed-off-by: Rachel Kurchin <rkurchin@cmu.edu>
…fix return types of other singular functions, rename ET parameter to S, add default size dispatch since firstindex default to a scalar

Signed-off-by: Rachel Kurchin <rkurchin@cmu.edu>
Signed-off-by: Rachel Kurchin <rkurchin@cmu.edu>
Signed-off-by: Rachel Kurchin <rkurchin@cmu.edu>
Signed-off-by: Rachel Kurchin <rkurchin@cmu.edu>
Signed-off-by: Rachel Kurchin <rkurchin@cmu.edu>
@rkurchin rkurchin requested review from mfherbst, Gregstrq and jgreener64 and removed request for mfherbst and Gregstrq November 12, 2021 17:16
Signed-off-by: Rachel Kurchin <rkurchin@cmu.edu>
Signed-off-by: Rachel Kurchin <rkurchin@cmu.edu>
Signed-off-by: Rachel Kurchin <rkurchin@cmu.edu>
Signed-off-by: Rachel Kurchin <rkurchin@cmu.edu>
Copy link
Collaborator

@jgreener64 jgreener64 left a comment

Choose a reason for hiding this comment

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

Looks good to me, readme and tests are nice too.

Copy link
Collaborator

@Gregstrq Gregstrq left a comment

Choose a reason for hiding this comment

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

We need to add indexing versions of position and species for the concrete implementations.

README.md Show resolved Hide resolved
Signed-off-by: Rachel Kurchin <rkurchin@cmu.edu>
Copy link
Member

@mfherbst mfherbst left a comment

Choose a reason for hiding this comment

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

A few nits, but generally LGTM.

sandbox/aos_vs_soa.jl Outdated Show resolved Hide resolved
src/atoms.jl Outdated Show resolved Hide resolved
src/implementation_aos.jl Outdated Show resolved Hide resolved
src/implementation_soa.jl Outdated Show resolved Hide resolved
src/interface.jl Outdated Show resolved Hide resolved
src/interface.jl Outdated
Comment on lines 79 to 80
Base.getindex(::AbstractSystem, ::Int) = error("Implement me")
Base.size(::AbstractSystem) = error("Implement me")
Base.length(::AbstractSystem) = error("Implement me")
Copy link
Member

Choose a reason for hiding this comment

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

I've only put the error("Implement me") here during development. I guess with the readme making this clear to be implemented we should drop these stubs completely (and let Julia throw an error for us). Thoughts?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I can see it both ways. On the one hand, it's redundant to throw an error "manually" here, but on the other, having all the required functions in the interface.jl file does make it a useful reference for someone who wants to sit down and implement the interface...

Copy link
Collaborator

Choose a reason for hiding this comment

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

I would lean towards not putting the errors here, and perhaps adding a comment if we want the information to be in that file. See the first section of https://www.oxinabox.net/2020/04/19/Julia-Antipatterns.html for some discussion.

Copy link
Member

Choose a reason for hiding this comment

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

I agree with @jgreener64 (and oxinabox) on that point very much.

Copy link
Member

Choose a reason for hiding this comment

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

Is this intended to be implemented now during interface development? Then I think an error message is fine because it will flag that this is supposed to be implemented but isn't. But if it is an interface function that a user should implement, then I don't think the error message should be there.

Signed-off-by: Rachel Kurchin <rkurchin@cmu.edu>
Signed-off-by: Rachel Kurchin <rkurchin@cmu.edu>
Signed-off-by: Rachel Kurchin <rkurchin@cmu.edu>
Copy link
Member

@mfherbst mfherbst left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Member

@cortner cortner left a comment

Choose a reason for hiding this comment

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

looks good I think, just left a few fairly trivial comments.

struct FlexibleSystem{D,ET<:AbstractElement,AT<:AbstractParticle{ET}} <: AbstractSystem{D,ET,AT}
box::SVector{D,<:SVector{D,<:Unitful.Length}}
struct FlexibleSystem{D,S,L<:Unitful.Length,AT} <: AbstractSystem{D,S}
box::SVector{D,<:SVector{D,L}}
Copy link
Member

Choose a reason for hiding this comment

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

"morally" it seems to me that box and boundary_conditions should be tuples of ... rather than SVectors. But I don't have too strong a view on that.

end
# convenience constructor where we don't have to preconstruct all the static stuff...
function FlexibleSystem(
box::Vector{Vector{L}},
box::Vector{<:AbstractVector{L}},
Copy link
Member

Choose a reason for hiding this comment

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

why type this? the box could be provided as a Vector, AbstractVector, Tuple, .... same with bc and particles below. This is a convenience constructor no? I would then just make it convenient to construct the thing and enforce such strict typing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, that would probably be better. I was having trouble figuring out how to write it in a general enough way...will file an issue for this too.

Copy link
Member

@cortner cortner Nov 17, 2021

Choose a reason for hiding this comment

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

The way I did it in JuLIP was to have a conversion interface e.g.

_convert_positions(X::Vector) = X 
_convert_positions(X::AbstractVector) = collect(X) 
_convert_positions(X::AbstractMatrix) = # convert into vector of SVectors 

_convert_bc(bc::NTuple{3, Bool}) = bc 
_convert_bc(bc::AbstractVector) = tuple(Bool.(bc)...)

and so forth. So this means that ANY sensible input will be automatically converted into the format needed internally.

Copy link
Member

Choose a reason for hiding this comment

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

ok, will repost in the issue.

print(io, "StaticAtom: $(a.element.symbol)")
end

const AbstractAtomicSystem{D} = AbstractSystem{D,Element}
Copy link
Member

Choose a reason for hiding this comment

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

I don't have time to look for the definition of AbstractSystem, so I'll add this comment here: I can sort of see why one might want to make the dimension a type parameter, though I'm not entirely sure where this is needed?

But does the element type really have to be a type parameter in the abstract type? What is the use case?

#
# Implementation of AtomsBase interface in a struct-of-arrays style.
#

using StaticArrays

export FastSystem
Copy link
Member

Choose a reason for hiding this comment

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

I find the FlexibleSystem and FastSystem terms a bit odd. Isn't it a bit context specific when they are fast / slow / convenient / inconvenient? Why not simply call them SystemSOA and SystemAOS then it is clear what they are. There could be a convenience constructor that can construct either, depending on a flag, with default probable being the AOS but I'm not sure about it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

😆 hahaha that's what they were originally called and I changed them at @mfherbst's suggestion

Copy link
Member

Choose a reason for hiding this comment

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

ah - sorry, that's what I get for not paying attention. Just don't have the time I'm afraid. I can't even quite put my finger on why I don't like those terms. I guess I prefer technically precise terms? Especially with an interface function a user will never have to worry about it until they know what they are doing and then they'll just go and read the docs?

#
Return the velocity of a particle `p`.
"""
velocity(p)::Union{Unitful.Velocity,Missing} = missing
Copy link
Member

Choose a reason for hiding this comment

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

could there be also a momentum function that call velocity and mass (and simply fails when there is no mass?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Certainly...do we think that needs to be at this top level though?

Copy link
Member

Choose a reason for hiding this comment

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

it is so generic and universal that I think there is no harm introducing it? I don't have a strong view - you decide what you think is best.

@@ -81,82 +38,82 @@ struct DirichletZero <: BoundaryCondition end # Dirichlet zero boundary (i.e. m
struct Periodic <: BoundaryCondition end # Periodic BCs
Copy link
Member

Choose a reason for hiding this comment

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

should this have a flag true/false? Since the bc is implemented as a vector (or tuple) of BCs, you probably want each element of that vector to be e.g. a Periodic() . But now suppose you want a system that is open in the x, y direction and periodic in the z direction (e.g. dislocations). Then you need a different type Open() and you have a type instability. But with Periodic(true), Periodic(false) there is no problem.

Copy link
Member

Choose a reason for hiding this comment

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

Personally, I don't really see how one needs anything other than a boolean here? I can see many other options such as reflecting, embedding, etc but those are not really relevant for the particle system per se, but rather for fields in the background, or for the embedding one would need additional structures anyhow into which to embed the System...

But I don't see any harm in keeping the Periodic type.


A `D`-dimensional system comprised of particles identified by type `S`.
"""
abstract type AbstractSystem{D,S} end
Copy link
Member

Choose a reason for hiding this comment

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

ah - there it is now. So if I want a particle system that has multiple element types then I can't have that? I agree that in 99% of the cases I probably don't want that because it will likely give me type instabilities. Just making sure this is really important enough to sacrifice the flexibility?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think the group of us has decent consensus that these belong here so I'm going to leave them in when I merge this, but I'll open an issue for further discussion of this point.

Copy link
Member

Choose a reason for hiding this comment

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

ok

src/interface.jl Outdated
Comment on lines 79 to 80
Base.getindex(::AbstractSystem, ::Int) = error("Implement me")
Base.size(::AbstractSystem) = error("Implement me")
Base.length(::AbstractSystem) = error("Implement me")
Copy link
Member

Choose a reason for hiding this comment

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

Is this intended to be implemented now during interface development? Then I think an error message is fine because it will flag that this is supposed to be implemented but isn't. But if it is an interface function that a user should implement, then I don't think the error message should be there.

…and bounding_box for now since there are type annotations...

Signed-off-by: Rachel Kurchin <rkurchin@cmu.edu>
@rkurchin
Copy link
Collaborator Author

I'm going to merge this. I've filed several issues to discuss lingering questions: #25, #26, #27, #28

@rkurchin rkurchin merged commit b3b7a45 into master Nov 17, 2021
@mfherbst mfherbst deleted the less_abstract branch November 17, 2021 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants