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

JLD2 Integration #505

Merged
merged 33 commits into from Jun 14, 2021
Merged

JLD2 Integration #505

merged 33 commits into from Jun 14, 2021

Conversation

AayushSabharwal
Copy link
Collaborator

@AayushSabharwal AayushSabharwal commented Jun 6, 2021

#496

Uses JLD2's custom serialization functionality (https://juliaio.github.io/JLD2.jl/dev/customserialization/)

@AayushSabharwal AayushSabharwal self-assigned this Jun 6, 2021
@AayushSabharwal AayushSabharwal changed the title Serialized versions of ABM, Grid|ContinuousSpace JLD2 Integration Jun 6, 2021
@AayushSabharwal
Copy link
Collaborator Author

AayushSabharwal commented Jun 6, 2021

Looking at https://github.com/JuliaGraphs/MetaGraphs.jl/blob/master/src/persistence.jl and from some testing I did, it appears as though GraphSpace.graph can be saved through JLD2.

Additionally, reimplementing all schedulers as function-like objects would make serialization significantly simpler. Currently, since ABM isn't mutable, model.scheduler = ... isn't possible. JLD2 when deserializing SerializedABM to ABM would (as of now) set the scheduler to fastest. The only other way would be manually converting ABM to SerializedABM (through a constructor) and give that to JLD2 to save, so that the reverse conversion function can take the scheduler as a parameter.

This issue also then crops up with ContinuousSpace.update_vel!. Here, the most viable options would be to:

  • Save the name of the function as a Symbol
  • Convert the entire ABM hierarchy to it's serializable state before sending it to JLD2 without using the custom serialization functionality (also solves the scheduler issue)

@Libbum
Copy link
Member

Libbum commented Jun 6, 2021

I wonder if using accessors.jl would be good for this. I've had success with it setting model.rng to a new RandomDevice(). Will be a good discussion for tomorrow.

- Added JLD2 to dependencies
- Reworked serialization to use custom conversion methods before sending to JLD2
- Reworkd deserialization to use custom conversion methods
- Use of undefined variable in AStar constructor
- Also removed @info about GraphSpace
@AayushSabharwal
Copy link
Collaborator Author

I'll cover what I've written in tests before moving on to tackling OSMSpace.

I think the to_serializable, from_serializable API should be documented too, as a sort of replacement for JLD2's JLD2.wconvert and JLD2.rconvert if keywords need to be passed

@AayushSabharwal
Copy link
Collaborator Author

AayushSabharwal commented Jun 8, 2021

Is it an acceptable pattern to encapsulate repetitive tests in a function, or does that reduce traceability in the case that those tests fail? For example,

function check_model_properties(model, other)
    @test model.scheduler == other.scheduler
    @test model.rng == other.rng
    @test model.maxid.x == other.maxid.x
end

- Tests for no, grid and continuous space models
@AayushSabharwal
Copy link
Collaborator Author

There's some weird behaviour with comparing GridSpace.hoods, which I plan on looking into. Comparing the structs doesn't work, but comparing their fields passes

@Datseris
Copy link
Member

Datseris commented Jun 8, 2021

I'll cover what I've written in tests before moving on to tackling OSMSpace.

I propose to do this in a different PR. OSMSpace is a bit "special" so to speak

@Datseris
Copy link
Member

Datseris commented Jun 8, 2021

Is it an acceptable pattern to encapsulate repetitive tests in a function, or does that reduce traceability in the case that those tests fail?

From my end this is fine, I do something similar in DynamicalSystems.jl

- Added tests for GraphSpace
- Order within space.s isn't maintained during (de)serialization, so tests
  don't assume it
- GraphSpace deserialization fix
@codecov-commenter
Copy link

codecov-commenter commented Jun 9, 2021

Codecov Report

Merging #505 (d5bd7c5) into master (07115c7) will increase coverage by 0.51%.
The diff coverage is 97.43%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #505      +/-   ##
==========================================
+ Coverage   93.04%   93.55%   +0.51%     
==========================================
  Files          20       21       +1     
  Lines        1265     1304      +39     
==========================================
+ Hits         1177     1220      +43     
+ Misses         88       84       -4     
Impacted Files Coverage Δ
src/submodules/io/csv_integration.jl 100.00% <ø> (ø)
src/submodules/pathfinding/grid_pathfinder.jl 80.90% <0.00%> (+3.63%) ⬆️
src/submodules/io/jld2_integration.jl 100.00% <100.00%> (ø)
src/spaces/openstreetmap.jl 91.85% <0.00%> (+0.03%) ⬆️

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 07115c7...d5bd7c5. Read the comment docs.

- Type parameter fix for GridSpace serialization due to pathfinders
@AayushSabharwal
Copy link
Collaborator Author

All that's left to test now is serialization of multi-agent models. 325 tests racked up already just for JLD2 (was ~3k at one point, while I was testing GridSpace.s by having a @test macro in a loop over eachindex)

- Multi agent uses daisyworld
- Daisyworld scheduler moved outside of initialization function
- dump_to_jld2 @asserts that model.space isn't OSMSpace
- OSMSpace test checks for error
@AayushSabharwal
Copy link
Collaborator Author

I moved daisyworld's scheduler outside of the initialization function, so it's accessible while deserializing during tests. Is this fine, or should it remain local?

@Libbum
Copy link
Member

Libbum commented Jun 10, 2021

Sure, that's not a requirement to be internal as far as I remember.

- Added docstrings for dump_to_jld2 and load_from_jld2
- to_serializable doesn't require keyword arguments
- dump_to_jld2 doesn't require keyword arguments
@AayushSabharwal
Copy link
Collaborator Author

I'm not fully happy with how dump_to_jld2's docstring is phrased. I'll work on improving it. Should it also specify what fields are not saved (space.s), or how they're saved (model.agents)?

- Docstrings added for to_serializable and from_serializable
- Changes to docstrings for dump_to_jld2 and load_from_jld2
- model.properties now goes through to_serializable and from_serializable
examples/schelling.jl Outdated Show resolved Hide resolved
Copy link
Member

@Libbum Libbum left a comment

Choose a reason for hiding this comment

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

No real issues with implementation at all—looking good!!

There are a few suggestions to improve documentation and user interactions, but most are minor. We can perhaps work through some of the doc fixes tomorrow in the meeting.

@AayushSabharwal
Copy link
Collaborator Author

AayushSabharwal commented Jun 13, 2021

It seems ../path wasn't the issue. Now it can't see the file. "schelling.jld2" seems to be the correct location of the file. The issue is still that JLD2 doesn't see SchellingAgent as a type while loading the file, so it creates its own reconstructed type which wreaks havoc.

@Libbum
Copy link
Member

Libbum commented Jun 13, 2021

OK, so that's a bit more complicated. Is this a problem only in CI, only when building documentation, or is it the same locally?

@AayushSabharwal
Copy link
Collaborator Author

It's a problem when building docs, both in CI and locally

@AayushSabharwal
Copy link
Collaborator Author

I should add, I tried creating a file with a submodule, defining an agent and model, and save/loading it within the module. Didn't create any issues. For some reason it's only when building docs

@Libbum
Copy link
Member

Libbum commented Jun 13, 2021

Alright. That'll take some investigation. I'll be out for the afternoon so don't know when I'll be able to focus on it.

docs/src/api.md Outdated Show resolved Hide resolved
docs/src/api.md Outdated Show resolved Hide resolved
@Libbum
Copy link
Member

Libbum commented Jun 14, 2021

Following our weekly meeting, the decision has been made to drop the additions to the Schelling Example from this PR and merge the rest once the documentation is up to scratch. A new PR will be opened with the Schelling Example additions as-is, and we'll investigate the Documenter/JLD2 issue as time permits.

We've also decided to support OSM space by saving agent lat/long coordinates and expecting the user to know the map path to deserialize their model: we will rebuild the mapspace on-load.

- (De)Serialization section of API renamed to Save/Load
- Added description for Save/Load section, removed AgentsIO doc
- Moved to_serializable and from_serializable to devdocs
- Updated AgentsIO docstring
@Libbum
Copy link
Member

Libbum commented Jun 14, 2021

These doc changes look good. So the only outstanding thing is OSMSpace from my perspective.

@AayushSabharwal
Copy link
Collaborator Author

I'm removing hoods serialization, but apart from that OSMSpace is the only thing left. If I remember correctly, we planned to handle that in a separate PR

@Datseris
Copy link
Member

yes go ahead and merge when tests pass but do not tag a new release. New releases should be tagged only when documentation exists. Feel free to open a tracking issue with the docs code pasted there.

@AayushSabharwal
Copy link
Collaborator Author

AayushSabharwal commented Jun 14, 2021

Ah. I just missed your comment.
I'll revert this commit then. The only docs missing is the example right?

@AayushSabharwal
Copy link
Collaborator Author

I think this branch can be kept for now? Since OSMSpace is coming up, along with the fix to schelling

@AayushSabharwal AayushSabharwal deleted the jld2_integration branch June 16, 2021 10:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants