text:
module ClusterTests
import ..Einsum.@einsumnum
using LinearAlgebra
using Random
using Distributions
using LightGraphs

sumdim2(w) = reshape(sum(w, dims=2), size(w,1))

function find_cluster(U, precision)
    p, n = size(U)
    l_set = collect(1:n)
    C = zeros(Int, n)
    c = 1

    while length(l_set) > 0
    	m = length(l_set)
    	l1 = l_set[1]
    	C[l1] = c
    	for j = 2:m
    		l2 = l_set[j]
    		if norm(U[:,l1] - U[:,l2]) <= precision
    			C[l2] = c
    		end
    	end
    	l_set = findall(C .== 0)
    	c += 1
    end
    return C
end

function find_cluster_admm(mx_matrix)
    n, n = size(mx_matrix)
    C = zeros(Int, n)
    g = SimpleGraph(mx_matrix)
    con_components = connected_components(g)
    c = 1
    for component in con_components
        C[component] .= c
        c += 1
    end
    return C
end

function cluster_test(X, G_mat, Y_mat, Omega, a, gamma, tau, C_cand_pt, weight)
    d, n = size(X)
    C_cand_pt = reshape(C_cand_pt, :, )
    C_cand = unique(C_cand_pt)
    clustering_cond = true
    weighted_X = X * Diagonal(weight)

    # check the separation condition
    for C_ind1 = 1:length(C_cand)
        c1 = C_cand[C_ind1]
        C1_pt = findall(isequal(c1), C_cand_pt)
        m = length(C1_pt)
        if m != length(C_cand_pt)
            for C_ind2 = C_ind1 + 1 : length(C_cand)
                c2 = C_cand[C_ind2]
                C2_pt = findall(isequal(c2), C_cand_pt)
                C1C2 = vcat(C1_pt, C2_pt)
                sum_weighted_X = sumdim2(weighted_X[:, C1C2])
                sum_weight = sum(weight[C1C2])
                avg_weighted_X = sum_weighted_X ./ sum_weight
                tmp = (X[:, C1C2] .- repeat(avg_weighted_X, 1, length(C1C2))).^2
                squared_dist = sum((X[:, C1C2] .- repeat(avg_weighted_X, 1, length(C1C2))).^2 * Diagonal(weight[C1C2]))
                if squared_dist <= tau
                    C_cand_pt[C1C2] .= 0
                    clustering_cond = false
                end
            end
        end
    end

    for C_ind = 1:length(C_cand)

        c = C_cand[C_ind]
        notC_ind = setdiff(C_cand, C_ind)
        sameC = findall(isequal(c), C_cand_pt)
        weight_sum = sum(weight[sameC])
        diffC = setdiff(1:n, sameC)
        m = length(sameC)

        Chiquet_mult_mat = zeros(m, m, d);
        Chiquet_mult = zeros(d,)
        x_omega_diff = zeros(d)

        l1 = 1
        l2 = 1

        # check the CGR subgradients
        if m > 1
            gij = zeros(d)
            gik_sum = zeros(d)
            gjk_sum = zeros(d)

            for pos1 = 1:m, pos2 = pos1+1:m
                l1 = sameC[pos1]
                l2 = sameC[pos2]

                gij[:] = reshape(G_mat[l1, l2, :], :, )
                x_omega_diff[:] .= 1.0/weight_sum .* (X[:, l1] .- X[:, l2] .- Omega[:, l1] .+ Omega[:, l2])
                gik_sum[:] = reshape(sum(Diagonal(weight[diffC]) * G_mat[l1, diffC, :], dims = 1), :, )
                gjk_sum[:] = reshape(sum(Diagonal(weight[diffC]) * G_mat[l2, diffC, :], dims = 1), :, )
                Chiquet_mult[:] .= gij .+ x_omega_diff .+ 1.0/weight_sum .* (gik_sum .- gjk_sum)

                if norm(Chiquet_mult) <= gamma
                    Chiquet_mult_mat[pos1, pos2, :] .= Chiquet_mult
                    Chiquet_mult_mat[pos2, pos1, :] .= - Chiquet_mult
                else
                    clustering_cond = false
                    #println("CGR fails")
                    C_cand_pt[sameC] .= 0
                end

            end
        end
    end
    return clustering_cond, C_cand_pt
end

function admm_Chi_Lange_wtest(X, gamma, weight, maxit)
	p, n = size(X)
	numterms = div(n * (n - 1), 2)
	index_set = zeros(Int, 2, numterms)
	pos = 1

	nu = 1.0
    weight_l = zeros(numterms)

    for i = 1 : n - 1
        for j = i + 1 : n
            index_set[1,pos] = i
            index_set[2,pos] = j
            weight_ij = weight[i] * weight[j]
            weight_l[pos] = weight_ij
            pos += 1
        end
    end

	scfac = norm(X)

    sigma = gamma / nu
    X_sum = sumdim2(X * Diagonal(weight))
    X_bar = repeat(X_sum, 1, n)

    weight_sum = sum(weight)

    U = zeros(p, n)
    V = zeros(p, numterms)
    y_term = zeros(p, numterms)
    Lambda = zeros(p, numterms)
    Lambda_sum = zeros(p)
    Unew = zeros(p, n)
    Vnew = zeros(p, numterms)
    U_diff = zeros(p)
    s_term = zeros(p, numterms)
    Lambdanew = zeros(p, numterms)
    Optimality_cond = zeros(p, n)

    z = zeros(p,)
    s = zeros(p, n)
    r = zeros(p, numterms)
    Y = zeros(p, n)

    G_mat = zeros(n, n, p)
    Y_mat = zeros(n, n, p)

    X_s = zeros(p, n)
    Y_s = zeros(p, numterms)
    Z_s = zeros(p, n)
    s_s = zeros(1, n)
    u_s = zeros(1, n)
    t_s = zeros(1, numterms)
    Alpha_s = zeros(p, numterms)
    Beta_s = zeros(p, n)
    gamma_s = zeros(1, n)
    Optimality_cond = zeros(p, n)
    mu = 0.0
    clusterID = zeros(Int, n)

    l1_set = Vector{Vector{Int}}()
	l2_set = Vector{Vector{Int}}()
	for i = 1:n
    	push!(l1_set, findall(index_set[1,:] .== i))
    	push!(l2_set, findall(index_set[2,:] .== i))
	end

	tcount = 1
    clustering_cond = false;
    C_cand_pt = zeros(Int, n)
    loopsize = 8
    itcount = 0

    mx_array = Vector{Int}()
    mx_matrix = zeros(n, n)

    while clustering_cond==false

        for count = 1:loopsize

            # update U, V, Lambda
            y_term .= (Lambda .+ nu.*V) * Diagonal(weight_l)
            for i = 1 : n
                wi = weight[i]
                Y[:, i] .= X[:, i] .+
                    (1/wi) * sumdim2(y_term[:,l1_set[i]]) .-
                    (1/wi) * sumdim2(y_term[:,l2_set[i]])
            end
            Unew .= (1/(1+weight_sum*nu)).*Y .+ (nu/(1+weight_sum*nu)).*X_bar

            nurecip = 1/nu

            mx_array = Vector{Int}()

            for l = 1 : numterms
                @einsumnum Y_s[~1,l] = Unew[~1,index_set[1,l]] - Unew[~1,index_set[2,l]]
                @einsumnum z[~1] = Y_s[~1,l] - nurecip*Lambda[~1,l]
                mx = max(0.0, 1-sigma/(norm(z)))
                if mx == 0
                    push!(mx_array, l)
                end
                @einsumnum Vnew[~1,l] =  mx * z[~1]
                @einsumnum r[~1,l] = Y_s[~1,l] - Vnew[~1,l]
                @einsumnum Lambdanew[~1,l] = Lambda[~1,l] - nu * r[~1,l]
            end

            U .= Unew
            V .= Vnew
            Lambda .= Lambdanew
        end

        X_s = U;
        Z_s = X_s .- X
        s_s = 0.5 * (ones(1, n) .+ sum(Z_s.^2, dims = 1))
        u_s = 0.5 * (- ones(1, n) .+ sum(Z_s.^2, dims = 1))
        t_s = sqrt.(sum(Y_s.^2, dims = 1))
        Alpha_s = Lambda

		Beta_s = zeros(p, n)
        for i = 1:n
            wi = weight[i]
            Beta_s[:,i] = - (1/wi) * sumdim2(Alpha_s[:,l1_set[i]] * Diagonal(weight_l[l1_set[i]])) .+
                (1/wi) * sumdim2(Alpha_s[:,l2_set[i]] * Diagonal(weight_l[l2_set[i]]))
        end
        gamma_s = 0.5 .* (ones(1, n) - sum(Beta_s.^2, dims = 1))

        fx = sum(weight' .* s_s) + gamma * sum(weight_l' .* t_s)
        halpha = tr(transpose(X * Diagonal(weight)) * Beta_s) + sum(gamma_s' .* weight)
        mu = fx - halpha
        mu = max(mu, 1e-15 * scfac^2)
        #println("mu = ", mu)
        for l = 1 : size(index_set, 2)
            G_mat[index_set[1,l], index_set[2,l], :] .= -Alpha_s[:, l]
            G_mat[index_set[2,l], index_set[1,l], :] .= Alpha_s[:, l]
            Y_mat[index_set[1,l], index_set[2,l], :] .= Y_s[:, l]
            Y_mat[index_set[2,l], index_set[1,l], :] .= -Y_s[:, l]
        end

        Sigma2 = repeat(s_s, p, 1) .* Beta_s .+ repeat(ones(1, n) .- gamma_s, p, 1) .* Z_s
        sigma3 = s_s .* gamma_s .+ (ones(1, n) .- gamma_s) .* u_s
        Omega = (sigma3 ./ s_s) .* Z_s .+ (ones(1, n) ./ s_s) .* Sigma2

        tau = 2 * mu

        num_pair = length(mx_array)
        mx_matrix = zeros(n, n)
        for l = 1:num_pair
            mx_pair_ind = mx_array[l]
            mx_matrix[index_set[1, mx_pair_ind], index_set[2, mx_pair_ind]] = 1
            mx_matrix[index_set[2, mx_pair_ind], index_set[1, mx_pair_ind]] = 1
        end
        #C_cand_pt = find_cluster(X_s, mu^0.5)
        C_cand_pt = find_cluster_admm(mx_matrix)
        clustering_cond, C_cand_pt = cluster_test(X_s, G_mat, Y_mat, Omega, X, gamma, tau, C_cand_pt, weight)

        tcount = tcount + 1
        itcount += loopsize
        if itcount >= maxit
            break
        end
    end

    min_strict_comp = Inf
    for l = 1 : size(index_set,2)
        strict_comp = (t_s[l] + gamma)  -
            sqrt(sum((Alpha_s[:,l] + Y_s[:,l]).^2))
        min_strict_comp = min(strict_comp, min_strict_comp)
    end

    clusterID = C_cand_pt
    #println(mx_matrix)
    return X_s, Y_s, Z_s, s_s, u_s, t_s, Alpha_s, Beta_s, gamma_s, Optimality_cond, mu, clusterID, itcount, clustering_cond, min_strict_comp
end

end

max_stars_repo_name: taotolojiang/Certifying-clusters-SON

max_issues_repo_name: taotolojiang/Certifying-clusters-SON

max_forks_repo_name: taotolojiang/Certifying-clusters-SON


text:
# Note that this script can accept some limited command-line arguments, run
# `julia build_tarballs.jl --help` to see a usage message.
using BinaryBuilder, Pkg

name = "NOVAS"
version = v"3.1"

# Collection of sources required to complete build
sources = [
    ArchiveSource("https://www.usno.navy.mil/USNO/astronomical-applications/software-products/novas/novas-c/novasc3.1.zip",
                  "86ab6eae9d5cfbcb75ee0d2443b83d0955f05e95510e9300b6248d56c3ab3f0f"),
    DirectorySource("./bundled")
]

# Bash recipe for building across all platforms
script = raw"""
cd $WORKSPACE/srcdir/novasc3.1
cp $WORKSPACE/srcdir/extras/meson.build .
mkdir build && cd build
meson .. --cross-file="${MESON_TARGET_TOOLCHAIN}"
ninja -j${nproc}
ninja install
install_license ${WORKSPACE}/srcdir/extras/LICENSE
"""

# These are the platforms we will build for by default, unless further
# platforms are passed in on the command line
platforms = supported_platforms(;experimental=true)

# The products that we will ensure are always built
products = [LibraryProduct("libnovas", :libnovas)]

# Dependencies that must be installed before this package can be built
dependencies = Dependency[]

# Build the tarballs, and possibly a `build.jl` as well.
build_tarballs(ARGS, name, version, sources, script, platforms, products, dependencies; julia_compat="1.6")

ext: jl

max_stars_repo_name: sharanry/Yggdrasil

max_issues_repo_name: sharanry/Yggdrasil

max_forks_repo_name: sharanry/Yggdrasil


text:
using UUIDs

using TeaFiles.Header: ContentDescriptionSection, Field, ItemSection,
    NameValue, NameValueSection, TeaFileMetadata, TimeSection, MAGIC_VALUE,
    _read_tea, _write_tea

"""
Write the given value to a buffer, followed by some garbage, and check we read it back
correctly.
"""
function _test_rw_loop(value)
    buf = IOBuffer()
    _write_tea(buf, value)
    write(buf, 42)  # some garbage we should ignore
    seekstart(buf)
    @test _read_tea(buf, typeof(value)) == value
end

@testset "read" begin
    @testset "read_byte_swapped_magic" begin
        buf = IOBuffer()
        write(buf, bswap(MAGIC_VALUE))
        seekstart(buf)
        @test_throws ArgumentError read(buf, TeaFileMetadata)
    end

    @testset "read_incorrect_magic" begin
        buf = IOBuffer()
        write(buf, 42)
        seekstart(buf)
        @test_throws ArgumentError read(buf, TeaFileMetadata)
    end

    @testset "read_string" begin
        for value in ("", "mooo")
            _test_rw_loop(value)
        end
    end

    @testset "read_field" begin
        for field_type_id in 1:10
            _test_rw_loop(Field(field_type_id, 0, "moo"))
        end
    end

    @testset "read_name_value" begin
        @testset "int32" begin _test_rw_loop(NameValue("moo", Int32(32))) end
        @testset "float64" begin _test_rw_loop(NameValue("moo", 42.0)) end
        @testset "string" begin _test_rw_loop(NameValue("moo", "lowing")) end
        @testset "uuid" begin _test_rw_loop(NameValue("moo", UUIDs.uuid1())) end
    end

    @testset "read_item_section" begin
        _test_rw_loop(ItemSection("", Field[]))
        _test_rw_loop(ItemSection("Plop", _make_fields([Float64, Float64, Int32])))
        _test_rw_loop(ItemSection(
            "Mooo",
            _make_fields(["a" => Float64, "b" => Float64, "c" => Int32])
        ))
    end

    @testset "read_time_section" begin
        _test_rw_loop(TimeSection(0, 0, Int32[]))
        _test_rw_loop(TimeSection(
            719162,  # 1970-01-01
            86400,  # Seconds
            Int32[0]  # First field
        ))
    end

    @testset "read_content_description_section" begin
        _test_rw_loop(ContentDescriptionSection(""))
        _test_rw_loop(ContentDescriptionSection("some description"))
    end

    @testset "read_name_value_section" begin
        _test_rw_loop(NameValueSection([]))
        _test_rw_loop(NameValueSection([NameValue("a", Int32(1))]))
        _test_rw_loop(NameValueSection([
            NameValue("a", Int32(1)),
            NameValue("b", Float64(42.0)),
            NameValue("c", "coo"),
            NameValue("d", UUIDs.uuid1()),
        ]))
    end

    @testset "read_metadata" begin
        example_metadata = _get_example_metadata()
        _test_rw_loop(example_metadata)
    end
end


text:
#Multi-threaded:
#julia -t <number-of-threads> --project=@. main.jl
#Single thread:
#julia --project=@. main.jl
using NEOs
using Dates
using TaylorIntegration
using JLD
using SPICE: furnsh
@show Threads.nthreads()

#script parameters (TODO: use ArgParse.jl instead)
const varorder = 5 # 1 # varorder is the order corresponding to the jet transport perturbation
const nv = 7 #number of TaylorN variables
const objname = "Apophis"
const maxsteps = 10000
const nyears = 6.0 #-5.0 #21.0
const dense = false #true
const quadmath = false # use quadruple precision
const debias_table = "2018" # "2014", "hires2018"
const apophisjlpath = pkgdir(NEOs)
# const dynamics = RNp1BP_pN_A_J23E_J2S_ng_eph!
const dynamics = RNp1BP_pN_A_J23E_J2S_ng_eph_threads!
const jd0 = datetime2julian(DateTime(2008,9,24,0,0,0)) #Julian date of integration initial time
@show jd0 == 2454733.5
const t0 = 0.0 # integration initial time

#### observation data files (ra/dec, del/dop)
const opticalobsfile = ""
const radarobsfile = ""
#const opticalobsfile = joinpath(apophisjlpath, "data", "tholen13_mpc_formatted.dat")
#const radarobsfile = joinpath(apophisjlpath, "data", "Apophis_JPL_data_2005_2006.dat")
#const opticalobsfile = joinpath(apophisjlpath, "data", "vokr15_mpc_formatted.dat")
#const radarobsfile = joinpath(apophisjlpath, "data", "Apophis_JPL_data_2012_2013.dat")

# path to local Solar System ephemeris file
#ss_eph_file = joinpath(apophisjlpath, "jldeph", "ss16ast343_eph_m5y_et.jld")
ss_eph_file = joinpath(apophisjlpath, "jldeph", "ss16ast343_eph_p6y_et.jld")

#### dq: perturbation to nominal initial condition (Taylor1 jet transport)
#dq = Taylor1.(zeros(7), varorder)
#dq[end][1] = 1e-14

#### dq: perturbation to nominal initial condition (TaylorN jet transport)
dq = set_variables("δx", order=varorder, numvars=nv)
for i in 1:6
    dq[i][1][i] = 1e-8
end
if get_numvars() == 7
    dq[7][1][7] = 1e-14
end

####integrator warmup
propagate(objname, dynamics, 1, t0, nyears, ss_eph_file, output=false, dense=dense, dq=dq, quadmath=quadmath)
println("*** Finished warmup")

#propagate(objname, dynamics, 300 #=5=#, t0, nyears, ss_eph_file, dense=dense, dq=dq, quadmath=quadmath)
#println("*** Finished 5 steps")

######Full jet transport integration until ~2038: about 8,000 steps
###propagate(objname, dynamics, maxsteps, t0, nyears, ss_eph_file, dense=dense, dq=dq) # no obs ephemeris computation
propagate(objname, dynamics, maxsteps, t0, nyears, ss_eph_file, dense=dense, dq=dq, quadmath=quadmath, radarobsfile=radarobsfile, opticalobsfile=opticalobsfile, debias_table=debias_table)
println("*** Finished full jet transport integration")


text:
include("new_SimulationFunctions.jl")

data_dictionary=Dict()

TSTART = 0.0;
Ts = 1.0;
TSTOP = 100;

# Rate constants for TGFb12 addition

XSS =  EstimateSteadyState(data_dictionary)

writedlm("/Users/dbassen/work/varner_gould_emt_model/emt_grn_bassen_model/Results/SteadyStateEpithelialTest/xss.dat", XSS)


text:
@testset "variables.jl" begin
    include("IntDomain.jl")
    include("IntVar.jl")
    include("IntVarView.jl")
    include("BoolVar.jl")
    include("BoolDomain.jl")
    include("IntSetDomain.jl")
    include("IntSetVar.jl")
    include("BoolVarView.jl")
end


text:
using SurrogateCube
# Define some Parameters
Ncomp = 3 #We want 3 independent components
Nvar  = 10 # we want 10 measured variables
noise = WhiteNoise(0.2) #Each component has a noise with sigma=0.5
means = [TrendBaseline(0.0,0.0,2.0),ConstantBaseline(0.0),ConstantBaseline(0.0)] # All Baselines are flat
dists = [TrendEvent(CubeEvent(0.2)),EmptyEvent(),EmptyEvent()] # Only one of the components is disturbed with a size of 20% in each dimension
varNoise = WhiteNoise(0.1) # each variable generated has some independent white noise
kb=0.0
kn=0.0
ks=-5.0  # How strongly do we want to perturb
#Set dimensions
Nlon = 10
Nlat = 10
Ntime =100
ds = genDataCube(means,noise,dists,varNoise,Ncomp,Nvar,Ntime,Nlat,Nlon,kb,kn,ks);
#Save the datacube to a file
save_cube(ds)
#Plot something
using PyPlot
pygui(true)
f=figure()
p=subplot()
for i=1:Nvar
plot(ds.variables[:,5,5,i][:])
end
p[:set_title]("Variables")
p[:set_xlabel]("Time")

f=figure()
p=subplot()
for i=1:Ncomp
plot(ds.components[:,5,5,i][:])
end
p[:set_title]("Components")
p[:set_xlabel]("Time")

f=figure()
p=subplot()
for i=1:Ncomp
plot(ds.eventmap[:,5,5,i][:])
end
p[:set_title]("Events")
p[:set_xlabel]("Time")
p[:set_ylim]([-0.1,2.1])

max_stars_repo_name: CAB-LAB/DataFarm

max_issues_repo_name: esa-esdl/DataFarm

max_forks_repo_name: esa-esdl/DataFarm


text:
using Mimi
using Distributions
using Test

@defcomp test1 begin
    p = Parameter(default = 5)
    function run_timestep(p, v, d, t) end
end

@defcomp test2 begin
    p = Parameter(default = 5)
    function run_timestep(p, v, d, t) end
end

@defcomp test3 begin
    a = Parameter(default = 5)
    function run_timestep(p, v, d, t) end
end

##
## Tests for set_translist_modelparams
##

sd = @defsim begin
    sampling(LHSData)
    p = Normal(0, 1)
end

#------------------------------------------------------------------------------
# Test a failure to find the unshared parameter in any components
m = Model()
set_dimension!(m, :time, 2000:10:2050)
add_comp!(m, test3)

fail_expr1 = :(
    run(sd, m, 100)
)

err1 = try eval(fail_expr1) catch err err end
@test occursin("Cannot resolve because p not found in any of the components of Model1.", sprint(showerror, err1))

#------------------------------------------------------------------------------
# Test a failure due to finding the unshared parameter in more than one component
m = Model()
set_dimension!(m, :time, 2000:10:2050)
add_comp!(m, test1)
add_comp!(m, test2)

fail_expr2 = :(
    run(sd, m, 100)
)

err2 = try eval(fail_expr2) catch err err end
@test occursin("Cannot resolve because parameter name p found in more than one component of Model1", sprint(showerror, err2))

#------------------------------------------------------------------
# Test a failure due to finding an unshared parameter in one model, but not
# the other

m1 = Model()
set_dimension!(m1, :time, 2000:10:2050)
add_comp!(m1, test1)

m2 = Model()
set_dimension!(m2, :time, 2000:10:2050)
add_comp!(m2, test3)

fail_expr3 = :(
    run(sd, [m1, m2], 100)
)

err3 = try eval(fail_expr3) catch err err end
@test occursin("Cannot resolve because p not found in any of the components of Model2", sprint(showerror, err3))

#------------------------------------------------------------------------------
# Test success cases

# unshared parameter set by default
m = Model()
set_dimension!(m, :time, 2000:10:2050)
add_comp!(m, test1)
run(sd, m, 100)

# shared parameter
m1 = Model()
set_dimension!(m1, :time, 2000:10:2050)
add_comp!(m1, test1)
add_comp!(m1, test2)
add_shared_param!(m1, :model_p, 5)
connect_param!(m1, :test1, :p, :model_p)
connect_param!(m1, :test2, :p, :model_p)
run(sd, m, 100)

# unshared parameter in both models with different names
m1 = Model()
set_dimension!(m1, :time, 2000:10:2050)
add_comp!(m1, test1)

m2 = Model()
set_dimension!(m2, :time, 2000:10:2050)
add_comp!(m2, test2)

run(sd, [m1, m2], 100)

##
## Tests for set_translist_modelparams with a default (not shared)
##

sd = @defsim begin
    sampling(LHSData)
    test1.p = Normal(0, 1)
end

# simple case
m = Model()
set_dimension!(m, :time, 2000:10:2050)
add_comp!(m, test1)
run(sd, m, 100)

# component not found
m = Model()
set_dimension!(m, :time, 2000:10:2050)
add_comp!(m, test2)
fail_expr = :(run(sd, m, 100))
err4 = try eval(fail_expr) catch err err end
@test occursin("Component test1 does not exist in Model1.", sprint(showerror, err4))

m1 = Model()
set_dimension!(m1, :time, 2000:10:2050)
add_comp!(m1, test2)
m2 = Model()
set_dimension!(m2, :time, 2000:10:2050)
add_comp!(m2, test1)
fail_expr = :(run(sd, [m1, m2], 100))
err5 = try eval(fail_expr) catch err err end
@test occursin("Component test1 does not exist in Model1.", sprint(showerror, err5))

# transform used only for one of the component's parameters p
m = Model()
set_dimension!(m, :time, 2000:10:2050)
add_comp!(m, test1)
add_comp!(m, test2) # no transform used
run(sd, m, 100)

# two models, both with component parameter pair
m1 = Model()
set_dimension!(m1, :time, 2000:10:2050)
add_comp!(m1, test1)

m2 = Model()
set_dimension!(m2, :time, 2000:10:2050)
add_comp!(m2, test1)

run(sd, [m1, m2], 100)


text:
@testset "round_etc" begin
  for I in (UInt8, UInt16, UInt32, UInt64, UInt128,
            Int8, Int16, Int32, Int64, Int128, BigInt)
    @eval begin
      sq = Rational{$I}(33, 32)
      fq = FastRational{$I}(33, 32)
      @test floor($I, sq) == floor($I, fq)
      @test ceil($I, sq) == ceil($I, fq)
      @test trunc($I, sq) == trunc($I, fq)
      @test round($I, sq) == round($I, fq)
    end
  end
end

@testset "enhanced rounding" begin
  for I in (UInt8, UInt16, UInt32, UInt64, UInt128,
            Int8, Int16, Int32, Int64, Int128, BigInt)
    @eval begin
      fq = FastRational{$I}(33, 32)
      fqf = float(fq)
      @test round($I, fq, RoundUp) == round($I, fqf, RoundUp)
      @test round($I, fq, RoundDown) == round($I, fqf, RoundDown)
      @test round($I, fq, RoundToZero) == round($I, fqf, RoundToZero)
      @test round($I, fq, RoundNearest) == round($I, fqf, RoundNearest)
    end
  end
  fq = FastRational{Int64}(33, 32)
  fqf = float(fq)
  @test round(Integer, fq, RoundUp) == round(Integer, fqf, RoundUp)
  @test round(Integer, fq, RoundDown) == round(Integer, fqf, RoundDown)
  @test round(Integer, fq, RoundToZero) == round(Integer, fqf, RoundToZero)
  @test round(Integer, fq, RoundNearest) == round(Integer, fqf, RoundNearest)
end