text:
"""
    fabricate(file::String, cb...)

Fabricate the sequence(s) planned in a number chromosome blueprints.

The fabricated sequences will be written out to the FASTA formatted file `file`.

`cb...` should be provided as a series of blueprint, seed-sequence pairs.
E.g. `fabricate("mygenome.fasta", chr1plan => ch1seq, ch2plan => ch2seq)`.
"""
function fabricate(file::String, cb...)
    @info string("Opening FASTA file at: ", file)
    open(FASTA.Writer, file) do wtr
        fabricate(wtr, cb...)
    end
end

"""
    fabricate(fw::FASTA.Writer, cb...)

Fabricate the sequence(s) planned in a number chromosome blueprints.

The fabricated sequences will be written out to the FASTA formatted file `fw`.

`cb...` should be provided as a series of blueprint, seed-sequence pairs.
E.g. `fabricate("mygenome.fasta", chr1plan => ch1seq, ch2plan => ch2seq)`.
"""
function fabricate(fw::FASTA.Writer, cb...)
    chromno = 0
    for bp in cb
        sequences = fabricate(bp)
        chromno += 1
        for (i, seq) in enumerate(sequences)
            rec = FASTA.Record(string("Chromosome_", chromno, "_copy_", i), seq)
            write(fw, rec)
        end
    end
    @info string("Fabricated ", chromno, " chromosomes and written to file")
end

"""
    fabricate(cb::ChromosomeBlueprint)

Fabricate the sequence(s) planned in the chromosome blueprint.

A random DNA sequence will be generated to use as a seed sequence.

A sequence will be built for each chromosome copy in the blueprint.
"""
function fabricate(cb::ChromosomeBlueprint)
    seed = LongSequence{DNAAlphabet{2}}(randdnaseq(length(cb)))
    return fabricate(cb, seed)
end

"""
    fabricate(cb::ChromosomeBlueprint, seed::LongSequence{DNAAlphabet{2}})

Fabricate a DNA sequence by applying the planned features in a chromosome blueprint,
to some initial starting seed sequence.

A sequence will be built for each chromosome copy in the blueprint.
"""
function fabricate(cb::ChromosomeBlueprint, seed::LongSequence{DNAAlphabet{2}})
    apply_repeats!(seed, cb)
    copies = [copy(seed) for _ in 1:ncopies(cb)]
    apply_hets!(copies, cb)
    return copies
end
fabricate(p::Pair{ChromosomeBlueprint, LongSequence{DNAAlphabet{2}}}) = fabricate(p.first, p.second)
fabricate(p::Pair{LongSequence{DNAAlphabet{2}}, ChromosomeBlueprint}) = fabricate(p.second, p.first)

function apply_repeats!(seq::LongSequence{DNAAlphabet{2}}, cb::ChromosomeBlueprint)
    for repeat in repetitions_unsafe(cb)
        copyto!(seq, repeat.destination, seq, repeat.origin, repeat.size)
    end
    return seq
end

function apply_hets!(seqs::Vector{LongSequence{DNAAlphabet{2}}}, cb::ChromosomeBlueprint)
    for het in hets_unsafe(cb)
        @assert length(seqs) == length(het.alleles)
        p = het.position
        for (i, a) in enumerate(het.alleles)
            seqs[i][p] = a
        end
    end
end


text:
#-----------------------------------------------------------------------------------
# Matching.Environment;
#-----------------------------------------------------------------------------------
import ..Matching.Environment: Variables, match_variable!, unmatch_variable!, extract!

"""
  Variables(vars::Set{Symbol}) creates an environment that
  can be used to check the consistency of pattern variables.
  Use match_variable!(vars, name, value) to do so.

"""
Variables;

"""
`match_variable!(vars::Variables, name::Symbol, val) -> Bool`

Tries to match the pattern variable `name`
(as defined in `vars`) with `val`.
If the variable is not defined in vars, then the
variable is mutable and the match returns true.
If the variable has no value, attribute `val` to
it and return true.
If the variable has a value `val`, then the match is true
if and only if `val` is that value.

"""
match_variable!;

"""
extract!(v::Variables, tree::PatternNode, args, from, to, ranges)

Given a pattern `tree`, extracts from `args[from:to]` the values corresponding
to the bindings found in `tree`, and assign them in `v`, e.g.
```
extract(v, pattern`(*{x,y},)`, [1,2,3,4], 1, 2, ranges) ->
  v[:x] = [1,3];
  v[:y] = [2,4]

```

`ranges` is a mapping of `PatternNode`s to ranges, used to determine which
arguments to extract when reaching a slurp.

"""
extract!;

#-----------------------------------------------------------------------------------
# Matching.Function;
#-----------------------------------------------------------------------------------
import ..Matching.Function: exprhead, matcher

"""
`exprhead(ex) -> Symbol`

Returns `:quote` if `ex` is a `QuoteNode`, `ex.head` if
`ex` is an `Expr`, and `notexpr` for anything else.
Used to simplify algorithms by having `QuoteNode`s be
treated as `Expr`s with one argument.

"""
exprhead;

"""
`matcher(pattern) -> (ex) -> Bool`

Given a pattern `P`, creates a `match` function that will tell
if an expression is matched by `P`. See [Language.md](../../Language.md)
to learn to create patterns.

examples:
```julia
match_anything = matcher(:x)
match_addition = matcher(:(x+y))
match_forloop  = matcher(:(for x=coll; body... end))
match_9s_tuple = matcher(:(*{9},)) # e.g. (9,9), (9,9,9,9,9), ()
# more examples in the tests

```

"""
matcher;

#-----------------------------------------------------------------------------------
# Matching.Comparison;
#-----------------------------------------------------------------------------------
import ..Matching.Comparison: conflicts, compare_trees

"""
`compare_trees(a::PatternTree, b::PatternTree) -> Symbol`

Compare two pattern trees `a` and `b` and return
a symbol that describes their relationship.

`:equal` means `a` and `b` match the exact same set of expressions.
can be checked with `a == b`.

`:unequal` means `a` and `b` matches disjoint sets of expressions.
Can be checked with `a != b`.

`:superset` means `a` matches all expressions that `b` match.
Can be checked with `a ⊇ b`.

`:subset` means `b` matches all expressions that `a` match.
Can be checked with `a ⊆ b`.

`:conflicts` means that there is a intersection between the sets of expressions `a` and `b` match,
but `a` also matches some expressions that `b` don't, and virce versa. Can be checked with `conflicts(a,b)`.

"""
compare_trees;

"""
`conflicts(a::PatternTree, b::PatternTree) -> Bool`

Uses `compare_trees` to check if `a` conflicts with `b`.

"""
conflicts;

ext: jl


text:
include("init.jl")

@testset "ValueFederate Creation" begin
    broker = createBroker()
    vFed, fedinfo = createValueFederate()
    destroyFederate(vFed, fedinfo)
    destroyBroker(broker)
end

@testset "ValueFederate State" begin

    broker = createBroker()
    vFed, fedinfo = createValueFederate()

    state = h.helicsFederateGetState(vFed)
    @test state == 0

    h.helicsFederateEnterExecutingMode(vFed)

    state = h.helicsFederateGetState(vFed)
    @test state == 2

    destroyFederate(vFed, fedinfo)
    destroyBroker(broker)
end

@testset "ValueFederate publication registration" begin
    broker = createBroker()
    vFed, fedinfo = createValueFederate()

    pubid1 = h.helicsFederateRegisterTypePublication(vFed, "pub1", "string", "")
    pubid2 = h.helicsFederateRegisterGlobalTypePublication(vFed, "pub2", "int", "")
    pubid3 = h.helicsFederateRegisterTypePublication(vFed, "pub3", "double", "V")

    h.helicsFederateEnterExecutingMode(vFed)

    @test h.helicsPublicationGetKey(pubid1) == "TestA Federate/pub1"
    @test h.helicsPublicationGetKey(pubid2) == "pub2"

    @test h.helicsPublicationGetKey(pubid3) == "TestA Federate/pub3"
    @test h.helicsPublicationGetType(pubid3) == "double"
    @test h.helicsPublicationGetUnits(pubid3) == "V"

    destroyFederate(vFed, fedinfo)
    destroyBroker(broker)
end

@testset "ValueFederate named point" begin
    broker = createBroker()
    vFed, fedinfo = createValueFederate()

    defaultValue = "start of a longer string in place of the shorter one and now this should be very long"
    defVal = 5.3
    #testValue1 = "inside of the functional relationship of helics"
    testValue1 = "short string"
    testVal1 = 45.7823
    testValue2 = "I am a string"
    testVal2 = 0.0

    pubid = h.helicsFederateRegisterGlobalPublication(vFed, "pub1", h.HELICS_DATA_TYPE_NAMED_POINT, "")
    subid = h.helicsFederateRegisterSubscription(vFed, "pub1", "")

    h.helicsInputSetDefaultNamedPoint(subid, defaultValue, defVal)

    h.helicsFederateEnterExecutingMode(vFed)

    # publish string1 at time=0.0
    h.helicsPublicationPublishNamedPoint(pubid, testValue1, testVal1)

    @test h.helicsInputGetNamedPoint(subid) == (defaultValue, defVal)

    @test h.helicsFederateRequestTime(vFed, 1.0) == 0.01

    # # get the value
    @test h.helicsInputGetNamedPoint(subid) == (testValue1, testVal1)

    # publish a second string
    h.helicsPublicationPublishNamedPoint(pubid, testValue2, testVal2)

    # # make sure the value is still what we expect
    @test h.helicsInputGetNamedPoint(subid) == (testValue1, testVal1)
    # # make sure the string is what we expect
    # # @test value3 == testValue1
    # @test val3 == [testValue1, testVal1]

    # # advance time
    @test h.helicsFederateRequestTime(vFed, 2.0) == 0.02

    # # make sure the value was updated
    @test h.helicsInputGetNamedPoint(subid) == (testValue2, testVal2)

    destroyFederate(vFed, fedinfo)
    destroyBroker(broker)

end

@testset "ValueFederate Test Bool" begin
    broker = createBroker()
    vFed, fedinfo = createValueFederate()

    defaultValue = true
    testValue1 = true
    testValue2 = false

    # register the publications
    pubid = h.helicsFederateRegisterGlobalPublication(vFed, "pub1", h.HELICS_DATA_TYPE_BOOLEAN, "")
    subid = h.helicsFederateRegisterSubscription(vFed, "pub1", "")

    h.helicsInputSetDefaultBoolean(subid, defaultValue)

    h.helicsFederateEnterExecutingMode(vFed)

    # publish string1 at time=0.0
    h.helicsPublicationPublishBoolean(pubid, testValue1)
    val = h.helicsInputGetBoolean(subid)

    @test val == defaultValue

    grantedtime = h.helicsFederateRequestTime(vFed, 1.0)
    @test grantedtime == 0.01

    # get the value
    val = h.helicsInputGetBoolean(subid)

    # make sure the string is what we expect
    @test val == testValue1

    # publish a second string
    h.helicsPublicationPublishBoolean(pubid, testValue2)

    # make sure the value is still what we expect
    val = h.helicsInputGetBoolean(subid)
    @test val == testValue1
    # advance time
    grantedtime = h.helicsFederateRequestTime(vFed, 2.0)
    # make sure the value was updated
    @test grantedtime == 0.02

    val = h.helicsInputGetBoolean(subid)
    @test val == testValue2

    destroyFederate(vFed, fedinfo)
    destroyBroker(broker)

end

@testset "ValueFederate publisher registration" begin
    broker = createBroker()
    vFed, fedinfo = createValueFederate()

    pubid1 = h.helicsFederateRegisterPublication(vFed, "pub1", h.HELICS_DATA_TYPE_STRING, "")
    pubid2 = h.helicsFederateRegisterGlobalPublication(vFed, "pub2", h.HELICS_DATA_TYPE_INT, "")
    pubid3 = h.helicsFederateRegisterPublication(vFed, "pub3", h.HELICS_DATA_TYPE_DOUBLE, "V")
    h.helicsFederateEnterExecutingMode(vFed)

    publication_key = h.helicsPublicationGetKey(pubid1)
    @test publication_key == "TestA Federate/pub1"
    publication_type = h.helicsPublicationGetType(pubid1)
    @test publication_type == "string"
    publication_key = h.helicsPublicationGetKey(pubid2)
    @test publication_key == "pub2"
    publication_key = h.helicsPublicationGetKey(pubid3)
    @test publication_key == "TestA Federate/pub3"
    publication_type = h.helicsPublicationGetType(pubid3)
    @test publication_type == "double"
    publication_units = h.helicsPublicationGetUnits(pubid3)
    @test publication_units == "V"
    publication_type = h.helicsPublicationGetType(pubid2)
    @test publication_type == "int64"

    destroyFederate(vFed, fedinfo)
    destroyBroker(broker)
end

@testset "ValueFederate subscription and publication registration" begin

    broker = createBroker()
    vFed, fedinfo = createValueFederate()

    pubid3 = h.helicsFederateRegisterTypePublication(vFed, "pub3", "double", "V")

    subid1 = h.helicsFederateRegisterSubscription(vFed, "sub1", "")
    subid2 = h.helicsFederateRegisterSubscription(vFed, "sub2", "")
    subid3 = h.helicsFederateRegisterSubscription(vFed, "sub3", "V")

    h.helicsFederateEnterExecutingMode(vFed)

    publication_type = h.helicsPublicationGetType(pubid3)
    @test publication_type == "double"

    sub_key = h.helicsSubscriptionGetKey(subid1)
    @test sub_key == "sub1"
    sub_type = h.helicsInputGetType(subid1)
    @test sub_type == ""
    sub_key = h.helicsSubscriptionGetKey(subid2)
    @test sub_key == "sub2"
    sub_key = h.helicsSubscriptionGetKey(subid3)
    @test sub_key == "sub3"
    sub_type = h.helicsInputGetType(subid3)
    @test sub_type == ""
    sub_units = h.helicsInputGetUnits(subid3)
    @test sub_units == "V"
    sub_type = h.helicsInputGetType(subid2)
    @test sub_type == ""

    destroyFederate(vFed, fedinfo)
    destroyBroker(broker)

end

@testset "ValueFederate single transfer" begin

    broker = createBroker()
    vFed, fedinfo = createValueFederate()

    pubid = h.helicsFederateRegisterGlobalPublication(vFed, "pub1", h.HELICS_DATA_TYPE_STRING, "")
    subid = h.helicsFederateRegisterSubscription(vFed, "pub1", "")

    h.helicsFederateEnterExecutingMode(vFed)

    h.helicsPublicationPublishString(pubid, "string1")

    grantedtime = h.helicsFederateRequestTime(vFed, 1.0)
    @test grantedtime == 0.01

    s = h.helicsInputGetString(subid)
    @test s == "string1"

    destroyFederate(vFed, fedinfo)
    destroyBroker(broker)
end

@testset "ValueFederate test double" begin
    broker = createBroker()
    vFed, fedinfo = createValueFederate()

    defaultValue = 1.0
    testValue = 2.0
    pubid = h.helicsFederateRegisterGlobalPublication(vFed, "pub1", h.HELICS_DATA_TYPE_DOUBLE, "")
    subid = h.helicsFederateRegisterSubscription(vFed, "pub1", "")
    h.helicsInputSetDefaultDouble(subid, defaultValue)

    h.helicsFederateEnterExecutingMode(vFed)

    # publish string1 at time=0.0
    h.helicsPublicationPublishDouble(pubid, testValue)

    value = h.helicsInputGetDouble(subid)
    @test value == defaultValue

    grantedtime = h.helicsFederateRequestTime(vFed, 1.0)
    @test grantedtime == 0.01

    value = h.helicsInputGetDouble(subid)
    @test value == testValue

    # publish string1 at time=0.0
    h.helicsPublicationPublishDouble(pubid, testValue + 1)

    grantedtime = h.helicsFederateRequestTime(vFed, 2.0)
    @test grantedtime == 0.02

    value = h.helicsInputGetDouble(subid)
    @test value == testValue + 1

    destroyFederate(vFed, fedinfo)
    destroyBroker(broker)
end

@testset "ValueFederate test complex" begin
    broker = createBroker()
    vFed, fedinfo = createValueFederate()

    rDefaultValue = 1.0
    iDefaultValue = 1.0
    rTestValue = 2.0
    iTestValue = 2.0
    pubid = h.helicsFederateRegisterGlobalPublication(vFed, "pub1", h.HELICS_DATA_TYPE_COMPLEX, "")
    subid = h.helicsFederateRegisterSubscription(vFed, "pub1", "")
    h.helicsInputSetDefaultComplex(subid, (rDefaultValue + im * iDefaultValue))

    h.helicsFederateEnterExecutingMode(vFed)

    # publish string1 at time=0.0
    h.helicsPublicationPublishComplex(pubid, (rTestValue + im * iTestValue))

    @test rDefaultValue + im * iDefaultValue == h.helicsInputGetComplex(subid)

    grantedtime = h.helicsFederateRequestTime(vFed, 1.0)
    @test grantedtime == 0.01

    @test (rTestValue + im * iTestValue) == h.helicsInputGetComplex(subid)

    destroyFederate(vFed, fedinfo)
    destroyBroker(broker)
end

@testset "ValueFederate test integer" begin
    broker = createBroker()
    vFed, fedinfo = createValueFederate()

    defaultValue = 1
    testValue = 2
    pubid = h.helicsFederateRegisterGlobalPublication(vFed, "pub1", h.HELICS_DATA_TYPE_INT, "")
    subid = h.helicsFederateRegisterSubscription(vFed, "pub1", "")
    h.helicsInputSetDefaultInteger(subid, defaultValue)

    h.helicsFederateEnterExecutingMode(vFed)

    h.helicsPublicationPublishInteger(pubid, testValue)

    value = h.helicsInputGetInteger(subid)
    @test value == defaultValue

    grantedtime = h.helicsFederateRequestTime(vFed, 1.0)
    @test grantedtime == 0.01

    value = h.helicsInputGetInteger(subid)
    @test value == testValue

    h.helicsPublicationPublishInteger(pubid, testValue + 1)

    grantedtime = h.helicsFederateRequestTime(vFed, 2.0)
    @test grantedtime == 0.02

    value = h.helicsInputGetInteger(subid)
    @test value == testValue + 1

    destroyFederate(vFed, fedinfo)
    destroyBroker(broker)
end

@testset "ValueFederate test string" begin
    broker = createBroker()
    vFed, fedinfo = createValueFederate()

    defaultValue = "String1"
    testValue = "String2"
    pubid = h.helicsFederateRegisterGlobalPublication(vFed, "pub1", h.HELICS_DATA_TYPE_STRING, "")
    subid = h.helicsFederateRegisterSubscription(vFed, "pub1", "")
    h.helicsInputSetDefaultString(subid, defaultValue)

    h.helicsFederateEnterExecutingMode(vFed)

    h.helicsPublicationPublishString(pubid, testValue)

    value = h.helicsInputGetString(subid)
    @test value == defaultValue

    grantedtime = h.helicsFederateRequestTime(vFed, 1.0)
    @test grantedtime == 0.01

    value = h.helicsInputGetString(subid)
    @test value == testValue

    destroyFederate(vFed, fedinfo)
    destroyBroker(broker)
end

@testset "ValueFederate test vectorD" begin
    broker = createBroker()
    vFed, fedinfo = createValueFederate()

    defaultValue = [0.0, 1.0, 2.0]
    testValue = [3.0, 4.0, 5.0]
    pubid = h.helicsFederateRegisterGlobalPublication(vFed, "pub1", h.HELICS_DATA_TYPE_VECTOR, "")
    subid = h.helicsFederateRegisterSubscription(vFed, "pub1", "")
    h.helicsInputSetDefaultVector(subid, defaultValue)

    h.helicsFederateEnterExecutingMode(vFed)

    h.helicsPublicationPublishVector(pubid, testValue)

    @test h.helicsInputGetVector(subid) == defaultValue

    grantedtime = h.helicsFederateRequestTime(vFed, 1.0)
    @test grantedtime == 0.01

    value = h.helicsInputGetVector(subid)

    @test value == testValue

    destroyFederate(vFed, fedinfo)
    destroyBroker(broker)
end

@testset "ValueFederate test single transfer" begin
    broker = createBroker()
    vFed, fedinfo = createValueFederate()

    s = "n2"

    pubid = h.helicsFederateRegisterGlobalPublication(vFed, "pub1", h.HELICS_DATA_TYPE_STRING, "")
    subid = h.helicsFederateRegisterSubscription(vFed, "pub1", "")

    h.helicsFederateEnterExecutingMode(vFed)

    h.helicsPublicationPublishString(pubid, "string1")

    grantedtime = h.helicsFederateRequestTime(vFed, 1.0)
    @test grantedtime == 0.01

    s = h.helicsInputGetString(subid)

    @test s == "string1"

    time = h.helicsInputLastUpdateTime(subid)
    @test time == 0.01

    h.helicsPublicationPublishString(pubid, "string2")

    destroyFederate(vFed, fedinfo)
    destroyBroker(broker)

end


text:
module TestDelete

include("preamble.jl")

@testset begin
    @test delete!!((a = 1,), :a) === NamedTuple()
    @test delete!!((a = 1,), :b) === (a = 1,)
    @test delete!!(Dict(:a => 1), :a) == Dict()
    @test delete!!(Dict(:a => 1), :b) == Dict(:a => 1)
end

end  # module


text:
function main()
    # Part 1: compute "FFT" on input
    input = open(f -> parse.(Int64, collect(readline(f))), "day16_input.txt")
    base(i, n) = [0, 1, 0, -1][(i ÷ n) % 4 + 1]
    fft(input, n) = abs(sum([d * base(i, n) for (i, d) in enumerate(input)])) % 10
    result = foldl((x, y) -> [fft(x, n) for n in 1:length(input)], 1:3, init=input)
    println("Part 1: After 100 iterations: $(join(result[1:8], ""))")

    # Part 2: repeat input 10000 times and then use first 7 digits as offset to find 8 digit message
    # Note that in each phase, a digit only relies on digits in its position or later from prev phase
    big_input = repeat(input, 10000)
    N = length(big_input)
    offset = parse(Int64, join(input[1:7]))
    if offset < N÷2
        println("Oh dear, my clever accumulator hack won't work")
        return
    end
    current = copy(big_input)
    for phase in 1:100
        # Last half of output only relies on the [00001111]-style base sequence, i.e. upper triangular type
        # We can just compute backwards for the digits we need
        result = zeros(Int64, N)
        for d in N:-1:(N÷2 + 1)
            result[d] = (d == N) ? current[d] : ((current[d] + result[d+1]) % 10)
        end
        current = result
    end
    println("Part 2: After 100 iterations, message: $(join(current[offset+1:offset+8]))")
end
main()

max_stars_repo_name: ericgreveson/adventofcode

max_issues_repo_name: ericgreveson/adventofcode

max_forks_repo_name: ericgreveson/adventofcode


text:
module Model

# add the "using ..Simulation" if any of the includes below need access
# to any outside objects for example Simulation.AbstractBitStream etc.
using ..Simulation

function print_trace(trace, stop_at::String)
    println("------- trace ---------")
    for tr in trace
        if string(tr.func) == stop_at
            break
        end
        println(tr)
    end
    println("-----------------------")
end

const SpanArray = Array{UInt8,2}

# For 1D Float64/UInt8 array streams.
mutable struct SampleData{T <: Number}
    samples::Array{T,1}
    min::Float64
    max::Float64
    t::Int64

    function SampleData{T}() where {T <: Number}
        o = new()
        o.t = 1
        o
    end
end

mutable struct SynapticData
    samples::Array{Float64,1}
    min::Float64
    max::Float64
    id::Int64

    function SynapticData(len::Int64)
        o = new()
        o.id = -1
        o.samples = Array{Float64,1}(undef, len)
        fill!(o.samples, 0)
        o.min = typemax(Float64)
        o.max = typemin(Float64)
        o
    end
end

mutable struct SynapticSamples
    syn_cnt::Int64

    data::Dict{Int64,SynapticData}
    synapses::Int64
    t::Int64

    function SynapticSamples(len::Int64)
        o = new()
        o.data = Dict{Int64,SynapticData}()
        o
    end
end

mutable struct Samples
    # -_---_---_---_---_---_---_---_---_---_---_---_---_---_---_---_---_--
    # Input data
    # -_---_---_---_---_---_---_---_---_---_---_---_---_---_---_---_---_--
    # Holds a single span during simulation. It is written to disk
    # at the end of span simulation then reset for the next span.
    # It is also used by the client to collect all spans
    poi_samples::SpanArray
    stimulus_samples::SpanArray

    # Spikes: ex psp
    cell_samples::SampleData

    soma_psp_samples::SampleData
    soma_apFast_samples::SampleData
    soma_apSlow_samples::SampleData
    dendrite_avg_samples::SampleData

    # Synaptic data
    synapses::Int64
    syn_weight_samples::SynapticSamples
    syn_surge_samples::SynapticSamples
    syn_psp_samples::SynapticSamples

    # Mostly for validating the merger streams.
    syn_input_samples::SynapticSamples

    # State managment during simulation run and between spans.
    # Start index of each span
    poi_t::Int64
    stim_t::Int64

    function Samples()
        o = new()
        o.cell_samples = SampleData{UInt8}()
        o.soma_apFast_samples = SampleData{Float64}()
        o.soma_apSlow_samples = SampleData{Float64}()
        o.soma_psp_samples = SampleData{Float64}()
        o.dendrite_avg_samples = SampleData{Float64}()
        o
    end
end

include("model_data.jl")
include("sample_writers.jl")
include("sample_readers.jl")
include("samples.jl")
include("app_data.jl")

end # Module --------------------------------------------


text:
# TODO:
# Modify:
# - [ ] Make K more interesting across scenarios (but `K <= 5`).
# - [ ] make Ni = 100_000
# - [ ] Change gamma in the different scenarios.

function scenarios(n::Int; seed=nothing, Ni=1000)
  seed == nothing || Random.seed!(seed)

  if n == 0  # TEST CASE!
    return scenarios(1, seed=seed, Ni=100)
  elseif n == 1
    return simulate_ftilde(NC=Ni, NT=Ni,
                           etaC=[.25, .75, 0, 0],
                           etaT=[.1, .1, .8, 0],
                           loc = [-1.5, 3.5, 5.1, 5],
                           scale = [1.6, 1.76, 1.76, 1.6],
                           df = [12, 10, 10, 15.],
                           skew = [0, -10, -10, 0.],
                           gammaC=0.1, gammaT=0.1)
  elseif n == 2
    return simulate_ftilde(NC=Ni, NT=Ni,
                           etaC=[.1, .1, .5, .3],
                           etaT=[.1, .1, .8, 0],
                           loc = [-1.5, 3.5, 5.1, 4.3],
                           scale = [1.6, 1.76, 1.76, 1.6],
                           df = [12, 10, 10, 15.],
                           skew = [0, -10, -10, -11.],
                           gammaC=0.1, gammaT=0.1)
  elseif n == 3
    return simulate_ftilde(NC=Ni, NT=Ni,
                           etaC=[.05, .05, .5, .4],
                           etaT=[.05, .05, .5, .4],
                           loc = [-1.5, 3.5, 5.1, 4.3],
                           scale = [1.6, 1.76, 1.76, 1.6],
                           df = [12, 10, 10, 15.],
                           skew = [0, -10, -10, -11.],
                           gammaC=0.1, gammaT=0.2)
  elseif n == 4
    return simulate_ftilde(NC=Ni, NT=Ni,
                           etaC=[.05, .05, .5, .4],
                           etaT=[.05, .05, .5, .4],
                           loc = [-1.5, 3.5, 5.1, 4.3],
                           scale = [1.6, 1.76, 1.76, 1.6],
                           df = [12, 10, 10, 15.],
                           skew = [0, -10, -10, -11.],
                           gammaC=0.15, gammaT=0.15)
  elseif n == 5  # a test case
    return simulate_ftilde(NC=Ni, NT=Ni,
                           etaC=[0, 1., 0, 0],
                           etaT=[0, 0, 1., 0],
                           loc = [-1.5, 3.5, 5.1, 4.3],
                           scale = [1.6, 1.76, 1.76, 1.6],
                           df = [12, 10, 10, 15.],
                           skew = [0, -10, -10, -11.],
                           gammaC=0.1, gammaT=0.1)
  else
    throw(ArgumentError("n=$(n) was provided. But n must be an integer between 0 and 5."))
  end
end


text:
using BibTeX

import Documenter
Documenter.makedocs(
    modules = [BibTeX],
    format = Documenter.HTML(),
    sitename = "BibTeX.jl",
    root = joinpath(dirname(dirname(@__FILE__)), "docs"),
    pages = Any["Home" => "index.md"],
    strict = true,
    linkcheck = true,
    checkdocs = :exports,
    authors = "Brandon Taylor"
)

# just test if it parses (for now)
joinpath((@__FILE__) |> dirname |> dirname, "example", "examples.bib") |> f -> read(f, String) |> parse_bibtex


text:
include("testutils.jl")
tests = ["pdmtypes", "addition", "generics", "kron", "staticarrays"]
println("Running tests ...")

for t in tests
    println("* $t ")
    include("$t.jl")
end


text:
# This file was generated by the Julia Swagger Code Generator
# Do not modify this file directly. Modify the swagger specification instead.

@doc raw"""PortworxVolumeSource represents a Portworx volume resource.

    IoK8sApiCoreV1PortworxVolumeSource(;
        fsType=nothing,
        readOnly=nothing,
        volumeID=nothing,
    )

    - fsType::String : FSType represents the filesystem type to mount Must be a filesystem type supported by the host operating system. Ex. \"ext4\", \"xfs\". Implicitly inferred to be \"ext4\" if unspecified.
    - readOnly::Bool : Defaults to false (read/write). ReadOnly here will force the ReadOnly setting in VolumeMounts.
    - volumeID::String : VolumeID uniquely identifies a Portworx volume
"""
mutable struct IoK8sApiCoreV1PortworxVolumeSource <: SwaggerModel
    fsType::Any # spec type: Union{ Nothing, String } # spec name: fsType
    readOnly::Any # spec type: Union{ Nothing, Bool } # spec name: readOnly
    volumeID::Any # spec type: Union{ Nothing, String } # spec name: volumeID

    function IoK8sApiCoreV1PortworxVolumeSource(;fsType=nothing, readOnly=nothing, volumeID=nothing)
        o = new()
        validate_property(IoK8sApiCoreV1PortworxVolumeSource, Symbol("fsType"), fsType)
        setfield!(o, Symbol("fsType"), fsType)
        validate_property(IoK8sApiCoreV1PortworxVolumeSource, Symbol("readOnly"), readOnly)
        setfield!(o, Symbol("readOnly"), readOnly)
        validate_property(IoK8sApiCoreV1PortworxVolumeSource, Symbol("volumeID"), volumeID)
        setfield!(o, Symbol("volumeID"), volumeID)
        o
    end
end # type IoK8sApiCoreV1PortworxVolumeSource

const _property_map_IoK8sApiCoreV1PortworxVolumeSource = Dict{Symbol,Symbol}(Symbol("fsType")=>Symbol("fsType"), Symbol("readOnly")=>Symbol("readOnly"), Symbol("volumeID")=>Symbol("volumeID"))
const _property_types_IoK8sApiCoreV1PortworxVolumeSource = Dict{Symbol,String}(Symbol("fsType")=>"String", Symbol("readOnly")=>"Bool", Symbol("volumeID")=>"String")
Base.propertynames(::Type{ IoK8sApiCoreV1PortworxVolumeSource }) = collect(keys(_property_map_IoK8sApiCoreV1PortworxVolumeSource))
Swagger.property_type(::Type{ IoK8sApiCoreV1PortworxVolumeSource }, name::Symbol) = Union{Nothing,eval(Base.Meta.parse(_property_types_IoK8sApiCoreV1PortworxVolumeSource[name]))}
Swagger.field_name(::Type{ IoK8sApiCoreV1PortworxVolumeSource }, property_name::Symbol) =  _property_map_IoK8sApiCoreV1PortworxVolumeSource[property_name]

function check_required(o::IoK8sApiCoreV1PortworxVolumeSource)
    (getproperty(o, Symbol("volumeID")) === nothing) && (return false)
    true
end

function validate_property(::Type{ IoK8sApiCoreV1PortworxVolumeSource }, name::Symbol, val)
end


text:
################################################################################
#VERSION 1
#linesearch is an intermediary between NewtonStopLS and a 1D solver.
function preparelinesearch(stp  :: NLPStopping,
                           x₀   :: AbstractVector,
                           d    :: AbstractVector,
                           f₀   :: AbstractFloat,
                           ∇f₀  :: AbstractVector,
                           τ₀   :: Real,
                           τ₁   :: Real)

    # initialize the LSModel
    g₀ = dot(∇f₀,d)
    ϕ = LSModel(stp.pb, x₀, d, τ₀, f₀, g₀ )

    # convert the Armijo and Wolfe criteria to an asymetric interval [α,β]
    α =  (τ₁-τ₀)*g₀
    β = -(τ₁+τ₀)*g₀

    # reuse the stopping
    ϕstp = LS_Stopping(ϕ, LSAtT(0.0, ht = f₀, gt = ∇f₀),
                       optimality_check = (p,s) -> optim_check_LS(p,s,α,β),
                       main_stp = stp,
                       max_iter = 40,
                       atol = 0.0, # to rely only on the Armijo-Wolfe conditions
                       rtol = 0.0, # otherwise, tolerance may prohibit convergence
                       unbounded_threshold = 1e100)

    # optimize in the interval [0.0,Inf]
    ϕstp = min_1D(ϕ, 0.0, Inf, α, β, stp = ϕstp)

    # unpack the results
    if ϕstp.meta.optimal
        t, ft, gt = ϕstp.current_state.x, ϕstp.current_state.ht, ϕstp.current_state.gt
    else
        t, ft, gt = 0.0, f₀, ∇f₀
        stp.meta.fail_sub_pb =  true
    end

    return t, ft, gt
end

function optim_check_LS(p, s :: LSAtT, α :: Float64, β :: Float64)
    return max(α - s.gt, s.gt - β, 0.0)
end

################################################################################
#VERSION 2
#Not an equivalent way would be with tol_check:
function preparelinesearch(stp  :: NLPStopping,
                           x₀   :: AbstractVector,
                           d    :: AbstractVector,
                           f₀   :: AbstractFloat,
                           ∇f₀  :: AbstractVector,
                           τ₀   :: Real,
                           τ₁   :: Real)

    # initialize the LSModel
    g₀ = dot(∇f₀,d)
    ϕ = LSModel(stp.pb, x₀, d, τ₀, f₀, g₀ )
    #Instead of redefining LSModel we can use the known ADNLPModel ? (not optimal though)
    #ϕ = ADNLPModel(t -> (obj(stp.pb, x₀ + t*d) - f₀ - τ₀ * t * g₀), [0.0], lvar = [0.0], uvar = [Inf])

    # convert the Armijo and Wolfe criteria to an asymetric interval [α,β]
    α =  (τ₁-τ₀)*g₀
    β = -(τ₁+τ₀)*g₀

    # reuse the stopping
    ϕstp = NLPStopping(ϕ, NLPAtX([0.0], fx = f₀, gx = ∇f₀),
                       optimality_check = unconstrained_check,
                       main_stp = stp,
                       max_iter = 40,
                       unbounded_threshold = 1e100,
                       tol_check = (a,b,c)     -> β,
                       tol_check_neg = (a,b,c) -> α)

    # optimize in the interval [0.0,Inf]
    ϕstp = min_1D(ϕ, 0.0, Inf, stp = ϕstp)

    # unpack the results
    if ϕstp.meta.optimal
        t, ft, gt = ϕstp.current_state.x, ϕstp.current_state.ht, ϕstp.current_state.gt
    else
        t, ft, gt = 0.0, f₀, ∇f₀
        stp.meta.fail_sub_pb =  true
    end

    return t, ft, gt
end


text:
"""
    is_palindrome(s)
A set of functions to check if a given string
is a palindrome.

Arguments:
 - s - a string =#
"""

function is_palindrome(s) # Named function
    s = lowercase(s)
    s == reverse(s)
end

max_stars_repo_name: gohpeijin/Julia

max_issues_repo_name: gohpeijin/Julia

max_forks_repo_name: gohpeijin/Julia


text:
# Autogenerated wrapper script for Spot_julia_jll for x86_64-w64-mingw32-cxx11
export autcross, autfilt, dstar2tgba, genaut, genltl, libbddx, libspot, libspot_julia, libspotgen, libspotltsmin, ltl2tgba, ltl2tgta, ltlcross, ltldo, ltlfilt, ltlgrind, ltlsynt, randaut, randltl

using libcxxwrap_julia_jll
JLLWrappers.@generate_wrapper_header("Spot_julia")
JLLWrappers.@declare_executable_product(autcross)
JLLWrappers.@declare_executable_product(autfilt)
JLLWrappers.@declare_executable_product(dstar2tgba)
JLLWrappers.@declare_executable_product(genaut)
JLLWrappers.@declare_executable_product(genltl)
JLLWrappers.@declare_library_product(libbddx, "libbddx-0.dll")
JLLWrappers.@declare_library_product(libspot, "libspot-0.dll")
JLLWrappers.@declare_library_product(libspot_julia, "libspot_julia.dll")
JLLWrappers.@declare_library_product(libspotgen, "libspotgen-0.dll")
JLLWrappers.@declare_library_product(libspotltsmin, "libspotltsmin-0.dll")
JLLWrappers.@declare_executable_product(ltl2tgba)
JLLWrappers.@declare_executable_product(ltl2tgta)
JLLWrappers.@declare_executable_product(ltlcross)
JLLWrappers.@declare_executable_product(ltldo)
JLLWrappers.@declare_executable_product(ltlfilt)
JLLWrappers.@declare_executable_product(ltlgrind)
JLLWrappers.@declare_executable_product(ltlsynt)
JLLWrappers.@declare_executable_product(randaut)
JLLWrappers.@declare_executable_product(randltl)
function __init__()
    JLLWrappers.@generate_init_header(libcxxwrap_julia_jll)
    JLLWrappers.@init_executable_product(
        autcross,
        "bin\\autcross.exe",
    )

    JLLWrappers.@init_executable_product(
        autfilt,
        "bin\\autfilt.exe",
    )

    JLLWrappers.@init_executable_product(
        dstar2tgba,
        "bin\\dstar2tgba.exe",
    )

    JLLWrappers.@init_executable_product(
        genaut,
        "bin\\genaut.exe",
    )

    JLLWrappers.@init_executable_product(
        genltl,
        "bin\\genltl.exe",
    )

    JLLWrappers.@init_library_product(
        libbddx,
        "bin\\libbddx-0.dll",
        RTLD_LAZY | RTLD_DEEPBIND,
    )

    JLLWrappers.@init_library_product(
        libspot,
        "bin\\libspot-0.dll",
        RTLD_LAZY | RTLD_DEEPBIND,
    )

    JLLWrappers.@init_library_product(
        libspot_julia,
        "bin\\libspot_julia.dll",
        RTLD_LAZY | RTLD_DEEPBIND,
    )

    JLLWrappers.@init_library_product(
        libspotgen,
        "bin\\libspotgen-0.dll",
        RTLD_LAZY | RTLD_DEEPBIND,
    )

    JLLWrappers.@init_library_product(
        libspotltsmin,
        "bin\\libspotltsmin-0.dll",
        RTLD_LAZY | RTLD_DEEPBIND,
    )

    JLLWrappers.@init_executable_product(
        ltl2tgba,
        "bin\\ltl2tgba.exe",
    )

    JLLWrappers.@init_executable_product(
        ltl2tgta,
        "bin\\ltl2tgta.exe",
    )

    JLLWrappers.@init_executable_product(
        ltlcross,
        "bin\\ltlcross.exe",
    )

    JLLWrappers.@init_executable_product(
        ltldo,
        "bin\\ltldo.exe",
    )

    JLLWrappers.@init_executable_product(
        ltlfilt,
        "bin\\ltlfilt.exe",
    )

    JLLWrappers.@init_executable_product(
        ltlgrind,
        "bin\\ltlgrind.exe",
    )

    JLLWrappers.@init_executable_product(
        ltlsynt,
        "bin\\ltlsynt.exe",
    )

    JLLWrappers.@init_executable_product(
        randaut,
        "bin\\randaut.exe",
    )

    JLLWrappers.@init_executable_product(
        randltl,
        "bin\\randltl.exe",
    )

    JLLWrappers.@generate_init_footer()
end  # __init__()