Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions .github/workflows/Downstream.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: IntegrationTest
on:
push:
branches: [master]
tags: [v*]
pull_request:

jobs:
test:
name: ${{ matrix.package.repo }}/${{ matrix.package.group }}/${{ matrix.julia-version }}
runs-on: ${{ matrix.os }}
env:
GROUP: ${{ matrix.package.group }}
strategy:
fail-fast: false
matrix:
julia-version: [1,1.6]
os: [ubuntu-latest]
package:
- {user: SciML, repo: RecursiveArrayTools.jl, group: All}
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.julia-version }}
arch: x64
- uses: julia-actions/julia-buildpkg@latest
- name: Clone Downstream
uses: actions/checkout@v2
with:
repository: ${{ matrix.package.user }}/${{ matrix.package.repo }}
path: downstream
- name: Load this and run the downstream tests
shell: julia --color=yes --project=downstream {0}
run: |
using Pkg
try
# force it to use this PR's version of the package
Pkg.develop(PackageSpec(path=".")) # resolver may fail with main deps
Pkg.update()
Pkg.test(coverage=true) # resolver may fail with test time deps
catch err
err isa Pkg.Resolve.ResolverError || rethrow()
# If we can't resolve that means this is incompatible by SemVer and this is fine
# It means we marked this as a breaking change, so we don't need to worry about
# Mistakenly introducing a breaking change, as we have intentionally made one
@info "Not compatible with this release. No problem." exception=err
exit(0) # Exit immediately, as a success
end
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v1
with:
file: lcov.info
2 changes: 1 addition & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"

[compat]
Documenter = "0.27"
SymbolicIndexingInterface = "0.1"
SymbolicIndexingInterface = "0.2"
2 changes: 2 additions & 0 deletions docs/src/api.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Interface Functions

Default methods cast all symbols to `Symbol` before comparing.

```@docs
independent_variables
is_indep_sym
Expand Down
47 changes: 36 additions & 11 deletions src/interface.jl
Original file line number Diff line number Diff line change
@@ -1,58 +1,83 @@
"""
$(TYPEDSIGNATURES)

Get the set of independent variables for the given system.
Get an iterable over the independent variables for the given system. Default to an empty
vector.
"""
function independent_variables end
independent_variables(::Any) = []

"""
$(TYPEDSIGNATURES)

Check if the given sym is an independent variable in the given system. Defaults
to `false` if not implemented for the given system/container type.
Check if the given sym is an independent variable in the given system. Default to checking
if the given `sym` exists in the iterable returned by `independent_variables`.
"""
function is_indep_sym end

function is_indep_sym(store, sym)
any(isequal(Symbol(sym)), Symbol.(independent_variables(store)))
end

"""
$(TYPEDSIGNATURES)

Get the set of states for the given system.
Get an iterable over the states for the given system. Default to an empty vector.
"""
function states end

states(::Any) = []

"""
$(TYPEDSIGNATURES)

Find the index of the given sym in the given system.
Find the index of the given sym in the given system. Default to the index of the first
symbol in the iterable returned by `states` which matches the given `sym`. Return
`nothing` if the given `sym` does not match.
"""
function state_sym_to_index end

function state_sym_to_index(store, sym)
findfirst(isequal(Symbol(sym)), Symbol.(states(store)))
end

"""
$(TYPEDSIGNATURES)

Check if the given sym is a state variable in the given system. Defaults
to `false` if not implemented for the given system/container type.
Check if the given sym is a state variable in the given system. Default to checking if
the value returned by `state_sym_to_index` is not `nothing`.
"""
function is_state_sym end

is_state_sym(store, sym) = !isnothing(state_sym_to_index(store, sym))

"""
$(TYPEDSIGNATURES)

Get the set of parameters variables for the given system.
Get an iterable over the parameters variables for the given system. Default to an empty
vector.
"""
function parameters end

parameters(::Any) = []

"""
$(TYPEDSIGNATURES)

Find the index of the given sym in the given system.
Find the index of the given sym in the given system. Default to the index of the first
symbol in the iterable retruned by `parameters` which matches the given `sym`. Return
`nothing` if the given `sym` does not match.
"""
function param_sym_to_index end

param_sym_to_index(store, sym) = findfirst(isequal(Symbol(sym)), Symbol.(parameters(store)))

"""
$(TYPEDSIGNATURES)

Check if the given sym is a parameter variable in the given system. Defaults
to `false` if not implemented for the given system/container type.
Check if the given sym is a parameter variable in the given system. Default
to checking if the value returned by `param_sym_to_index` is not `nothing`.
"""
function is_param_sym end

is_param_sym(store, sym) = !isnothing(param_sym_to_index(store, sym))
13 changes: 5 additions & 8 deletions src/symbolcache.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
"""
SymbolCache(syms, indepsym, paramsyms)

A container that simply stores a vector of all syms, indepsym and paramsyms.
"""
struct SymbolCache{S, T, U}
syms::S
indepsym::T
Expand All @@ -6,21 +11,13 @@ end

independent_variables(sc::SymbolCache) = sc.indepsym
independent_variables(::SymbolCache{S, Nothing}) where {S} = []
is_indep_sum(::Any, _) = false
is_indep_sym(sc::SymbolCache, sym) = any(isequal(sym), sc.indepsym)
is_indep_sym(::SymbolCache{S, Nothing}, _) where {S} = false
states(sc::SymbolCache) = sc.syms
states(::SymbolCache{Nothing}) = []
state_sym_to_index(sc::SymbolCache, sym) = findfirst(isequal(sym), sc.syms)
state_sym_to_index(::SymbolCache{Nothing}, _) = nothing
is_state_sym(::Any, _) = false
is_state_sym(sc::SymbolCache, sym) = !isnothing(state_sym_to_index(sc, sym))
parameters(sc::SymbolCache) = sc.paramsyms
parameters(::SymbolCache{S, T, Nothing}) where {S, T} = []
param_sym_to_index(sc::SymbolCache, sym) = findfirst(isequal(sym), sc.paramsyms)
param_sym_to_index(::SymbolCache{S, T, Nothing}, _) where {S, T} = nothing
is_param_sym(::Any, _) = false
is_param_sym(sc::SymbolCache, sym) = !isnothing(param_sym_to_index(sc, sym))

function Base.copy(VA::SymbolCache)
typeof(VA)((VA.syms === nothing) ? nothing : copy(VA.syms),
Expand Down
10 changes: 10 additions & 0 deletions test/default_function_test.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using SymbolicIndexingInterface, Test

@test independent_variables(nothing) == []
@test states(nothing) == []
@test parameters(nothing) == []
@test !is_indep_sym(nothing, :a)
@test !is_state_sym(nothing, :a)
@test !is_param_sym(nothing, :a)
@test isnothing(state_sym_to_index(nothing, :a))
@test isnothing(param_sym_to_index(nothing, :a))
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ using SymbolicIndexingInterface
using Test

@time begin @time @testset begin include("symbolcache.jl") end end
@time begin @time @testset begin include("default_function_test.jl") end end