Skip to content

Commit

Permalink
Merge pull request #78 from cesaraustralia/improvements
Browse files Browse the repository at this point in the history
Improvements
  • Loading branch information
rafaqz authored Nov 8, 2020
2 parents 96d03f0 + 9d926a0 commit eb569b0
Show file tree
Hide file tree
Showing 27 changed files with 1,276 additions and 570 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: CI
on:
- push
- pull_request
defaults:
run:
shell: bash
jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
version:
- '1.3'
- '1.5'
os:
- ubuntu-latest
- macOS-latest
- windows-latest
arch:
- x64
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: julia-actions/julia-buildpkg@latest
- uses: julia-actions/julia-runtest@latest
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v1
with:
file: lcov.info
fail_ci_if_error: true
docs:
name: Documentation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
with:
version: '1.5'
- run: |
julia --project=docs -e '
using Pkg
Pkg.develop(PackageSpec(path=pwd()))
Pkg.instantiate()'
- run: julia --project=docs docs/make.jl
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }}
16 changes: 7 additions & 9 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "DynamicGrids"
uuid = "a5dba43e-3abc-5203-bfc5-584ca68d3f5b"
authors = ["Rafael Schouten <[email protected]>"]
version = "0.10.9"
version = "0.11.0"

[deps]
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
Expand All @@ -10,14 +10,14 @@ Crayons = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
DimensionalData = "0703355e-b756-11e9-17c0-8b28908087d0"
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
FieldDefaults = "49426c49-986f-5969-8844-d5cc96441cfc"
FieldDocTables = "a5d692f0-33f0-11e9-293e-eb83c8d6177d"
FieldMetadata = "bf96fef3-21d2-5d20-8afa-0e7d4c32a885"
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
FreeTypeAbstraction = "663a7486-cb36-511b-a19d-713bb74d65c9"
Mixers = "2a8e4939-dab8-5edc-8f64-72a8776f13de"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
ModelParameters = "4744a3fa-6c31-4707-899e-a3298e4618ad"
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
Setfield = "efcf1570-3423-57d1-acb7-fd33fddbac46"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
UnicodeGraphics = "ebadf6b4-db70-5817-83da-4a19ad584e34"
Expand All @@ -28,13 +28,11 @@ ConstructionBase = "1"
Crayons = "4"
DimensionalData = "0.11, 0.12, 0.13"
DocStringExtensions = "0.8"
FieldDefaults = "0.3.1"
FieldDocTables = "0.1"
FieldMetadata = "0.3"
FileIO = "1"
FreeTypeAbstraction = "^0.6.5, 0.8"
Mixers = "0.1"
ModelParameters = "0.2"
OffsetArrays = "0.11, 1.0"
Reexport = "0.2"
Setfield = "0.6, 0.7"
UnicodeGraphics = "0.1"
julia = "1.2, 1.3, 1.4, 1.5"
Expand Down
1 change: 1 addition & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[deps]
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
DynamicGrids = "a5dba43e-3abc-5203-bfc5-584ca68d3f5b"
24 changes: 22 additions & 2 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@ CellRule
Cell
NeighborhoodRule
Neighbors
Convolution
Life
ManualRule
Manual
ManualNeighborhoodRule
SetNeighbors
GridRule
Grid
Chain
```

Expand All @@ -37,15 +41,17 @@ Chain
```@docs
DynamicGrids.applyrule
DynamicGrids.applyrule!
DynamicGrids.precalcrules
DynamicGrids.precalcrule
isinferred
```

### Data objects and methods for use in `applyrule`

```@docs
SimData
DynamicGrids.init
DynamicGrids.aux
DynamicGrids.mask
DynamicGrids.tspan
DynamicGrids.timestep
DynamicGrids.currenttimestep
Expand All @@ -63,7 +69,9 @@ and how they are combined to update the value of the current cell.

```@docs
Neighborhood
AbstractRadialNeighborhood
RadialNeighborhood
AbstractKernel
Kernel
Moore
VonNeumann
AbstractPositional
Expand All @@ -76,13 +84,25 @@ LayeredPositional
```@docs
DynamicGrids.radius
DynamicGrids.neighbors
DynamicGrids.positions
DynamicGrids.offsets
DynamicGrids.sumneighbors
DynamicGrids.mapsetneighbor!
DynamicGrids.setneighbor!
DynamicGrids.allocbuffers
DynamicGrids.hoodsize
```

## Manual Rules

```@docs
add!
sub!
and!
or!
xor!
```


## Output

Expand Down
32 changes: 12 additions & 20 deletions src/DynamicGrids.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,40 @@ using Colors,
Crayons,
DimensionalData,
DocStringExtensions,
FieldDefaults,
FieldMetadata,
FieldDocTables,
FreeTypeAbstraction,
FileIO,
Mixers,
LinearAlgebra,
OffsetArrays,
REPL,
Reexport,
Setfield,
Test,
UnicodeGraphics

@reexport using ModelParameters

const DG = DynamicGrids

using Base: tail
using Base: tail, @propagate_inbounds

import Base: show, getindex, setindex!, lastindex, size, length, push!, append!,
broadcast, broadcast!, similar, eltype, iterate

import FieldMetadata: @description, description,
@bounds, bounds,
@flattenable, flattenable,
@default, default
export sim!, resume!, savegif, isinferred, isinferred

export rules, neighbors, offsets, positions, radius, inbounds, isinbounds

export sim!, resume!, savegif, isinferred, isinferred
export gridsize, currenttime, currenttimestep, timestep

export rules, neighbors, inbounds, isinbounds, radius, gridsize,
currenttime, currenttimestep, timestep
export add!, sub!, and!, or!, xor!

export Rule, NeighborhoodRule, CellRule, ManualRule, ManualNeighborhoodRule
export Rule, NeighborhoodRule, CellRule, ManualRule, ManualNeighborhoodRule, GridRule

export Chain, Cell, Neighbors, Manual, Life
export Cell, Neighbors, SetNeighbors, Convolution, Manual, Chain, Life, Grid

export AbstractRuleset, Ruleset

export Neighborhood, AbstractRadialNeighborhood, Moore,
export Neighborhood, RadialNeighborhood, AbstractKernel, Kernel, Moore,
AbstractPositional, Positional, VonNeumann, LayeredPositional

export PerformanceOpt, NoOpt, SparseOpt
Expand All @@ -67,11 +64,6 @@ export Greyscale, Grayscale

export CharStyle, Block, Braile


const FIELDDOCTABLE = FieldDocTable((:Description, :Default, :Bounds),
(description, default, bounds);
truncation=(100,40,100))

# Documentation templates
@template TYPES =
"""
Expand Down
12 changes: 6 additions & 6 deletions src/chain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ radius(chain::Chain) = radius(chain[1])
neighborhoodkey(chain::Chain) = neighborhoodkey(chain[1])
neighborhood(chain::Chain) = neighborhood(chain[1])

Base.tail(chain::Chain{R,W}) where {R,W} = begin
ch = tail(rules(chain))
Chain{R,W,typeof(ch)}(ch)
function Base.tail(chain::Chain{R,W}) where {R,W}
chaintail = tail(rules(chain))
Chain{R,W,typeof(chaintail)}(chaintail)
end
Base.getindex(chain::Chain, i) = getindex(rules(chain), i)
Base.iterate(chain::Chain) = iterate(rules(chain))
Base.length(chain::Chain) = length(rules(chain))
Base.firstindex(chain::Chain) = firstindex(rules(chain))
Base.lastindex(chain::Chain) = lastindex(rules(chain))

@generated applyrule(data::SimData, chain::Chain{R,W,T}, state, index) where {R,W,T} = begin
@generated function applyrule(data::SimData, chain::Chain{R,W,T}, state, index) where {R,W,T}
expr = Expr(:block)
for i in 1:length(T.parameters)
rule_expr = quote
Expand All @@ -62,7 +62,7 @@ end
Get the state to pass to the specific rule as a `NamedTuple` or single value
"""
@generated filter_readstate(::Rule{R,W}, state::NamedTuple) where {R<:Tuple,W} = begin
@generated function filter_readstate(::Rule{R,W}, state::NamedTuple) where {R<:Tuple,W}
expr = Expr(:tuple)
keys = Tuple(R.parameters)
for k in keys
Expand All @@ -77,7 +77,7 @@ end
Get the state to write for the specific rule
"""
@generated filter_writestate(::Rule{R,W}, state::NamedTuple) where {R<:Tuple,W} = begin
@generated function filter_writestate(::Rule{R,W}, state::NamedTuple) where {R<:Tuple,W}
expr = Expr(:tuple)
keys = Tuple(W.parameters)
for k in keys
Expand Down
27 changes: 22 additions & 5 deletions src/extent.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

"""
Extent(init, mask, aux, tspan, tstopped)
Extent(init::Union{AbstractArray,NamedTuple},
mask::Union{AbstractArray,Nothing},
aux::Union{NamedTuple,Nothing},
tspan::AbstractRange)
Extent(; init, mask=nothing, aux=nothing, tspan, kwargs...)
Container for extensive variables: spatial and timeseries data.
Expand All @@ -9,8 +12,16 @@ of rules to alternate spatial and temporal contexts.
Extent is not usually constructed directly by users, but it can be passed
to `Output` constructors instead of `init`, `mask`, `aux` and `tspan`.
- `init`: initialisation `Array`/`NamedTuple` for grid/s.
- `mask`: `BitArray` for defining cells that will/will not be run.
- `aux`: NamedTuple of arbitrary input data. Use `aux(data, Vale{:key})` to access from
a `Rule` in a type-stable way.
- `tspan`: Time span range. Never type-stable, only access this in `precalc` methods
"""
mutable struct Extent{I,M,A}
mutable struct Extent{I<:Union{AbstractArray,NamedTuple},
M<:Union{AbstractArray,Nothing},
A<:Union{NamedTuple,Nothing}}
init::I
mask::M
aux::A
Expand All @@ -20,11 +31,15 @@ Extent(init::I, mask::M, aux::A, tspan::T) where {I,M,A,T} = begin
# Check grid sizes match
gridsize = if init isa NamedTuple
size_ = size(first(init_))
all(map(i -> size(i) == size_, init)) || throw(ArgumentError("`init` grid sizes do not match"))
if !all(map(i -> size(i) == size_, init))
throw(ArgumentError("`init` grid sizes do not match"))
end
else
size_ = size(init_)
end
(mask !== nothing) && (size(mask) != size_) && throw(ArgumentError("`mask` size do not match `init`"))
if (mask !== nothing) && (size(mask) != size_)
throw(ArgumentError("`mask` size do not match `init`"))
end
Extent{I,M,A,T}(init, mask, aux, tspan)
end
Extent(; init, mask=nothing, aux=nothing, tspan, kwargs...) =
Expand All @@ -33,7 +48,9 @@ Extent(; init, mask=nothing, aux=nothing, tspan, kwargs...) =
init(e::Extent) = e.init
mask(e::Extent) = e.mask
aux(e::Extent) = e.aux
tspan(e::Extent) = e.tspan
@inline aux(e::Extent, key::Symbol) = aux(e)[key] # Should not be used in rules
@inline aux(e::Extent, ::Val{Key}) where Key = aux(e)[Key] # Fast compile-time version
tspan(e::Extent) = e.tspan # Never type-stable, only access in `precalc` methods

settspan!(e::Extent, tspan) = e.tspan = tspan

Expand Down
Loading

2 comments on commit eb569b0

@rafaqz
Copy link
Member Author

@rafaqz rafaqz commented on eb569b0 Nov 8, 2020

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/24325

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.11.0 -m "<description of version>" eb569b07ae7200635dd7f4d64e602bbc0ecb9332
git push origin v0.11.0

Please sign in to comment.