Skip to content

Commit

Permalink
added actual tests, slight code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
nsimakov committed May 14, 2024
1 parent bed2933 commit 9f4cfda
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 13 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# VSCode
/.vscode
/HPCMod.code-workspace
# some temp internal tests
/bridges2
/simple1
/stampede2skx
Expand Down
26 changes: 25 additions & 1 deletion Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

julia_version = "1.10.2"
manifest_format = "2.0"
project_hash = "69e29d7e779e741eeaa651e0585734a6311d1402"
project_hash = "4a0a359147081e21854cb9fc59dfd4b6ff618869"

[[deps.ANSIColoredPrinters]]
git-tree-sha1 = "574baf8110975760d391c710b6341da1afa48d8c"
Expand Down Expand Up @@ -229,6 +229,12 @@ git-tree-sha1 = "5e38a8aa2868dbd4e15804c1caff4f9c3b0aa7f5"
uuid = "caabdcdb-0ab6-47cf-9f62-08858e44f38f"
version = "1.1.0"

[[deps.CodeTracking]]
deps = ["InteractiveUtils", "UUIDs"]
git-tree-sha1 = "c0216e792f518b39b22212127d4a84dc31e4e386"
uuid = "da1fd8a2-8d9e-5ec2-8556-3022fb5608a2"
version = "1.3.5"

[[deps.CodecZlib]]
deps = ["TranscodingStreams", "Zlib_jll"]
git-tree-sha1 = "59939d8a997469ee05c4b4944560a820f9ba0d73"
Expand Down Expand Up @@ -861,6 +867,12 @@ git-tree-sha1 = "3336abae9a713d2210bb57ab484b1e065edd7d23"
uuid = "aacddb02-875f-59d6-b918-886e6ef4fbf8"
version = "3.0.2+0"

[[deps.JuliaInterpreter]]
deps = ["CodeTracking", "InteractiveUtils", "Random", "UUIDs"]
git-tree-sha1 = "e9648d90370e2d0317f9518c9c6e0841db54a90b"
uuid = "aa1ae85d-cabe-5617-a682-6adf51b2e16a"
version = "0.9.31"

[[deps.KernelDensity]]
deps = ["Distributions", "DocStringExtensions", "FFTW", "Interpolations", "StatsBase"]
git-tree-sha1 = "fee018a29b60733876eb557804b5b109dd3dd8a7"
Expand Down Expand Up @@ -1032,6 +1044,12 @@ git-tree-sha1 = "c1dd6d7978c12545b4179fb6153b9250c96b0075"
uuid = "e6f89c97-d47a-5376-807f-9c37f3926c36"
version = "1.0.3"

[[deps.LoweredCodeUtils]]
deps = ["JuliaInterpreter"]
git-tree-sha1 = "31e27f0b0bf0df3e3e951bfcc43fe8c730a219f6"
uuid = "6f1432cf-f94c-5a45-995e-cdbf5db27b0b"
version = "2.4.5"

[[deps.MKL_jll]]
deps = ["Artifacts", "IntelOpenMP_jll", "JLLWrappers", "LazyArtifacts", "Libdl"]
git-tree-sha1 = "72dc3cf284559eb8f53aa593fe62cb33f83ed0c0"
Expand Down Expand Up @@ -1473,6 +1491,12 @@ git-tree-sha1 = "754aeae612461da54756b83e9baf8583f910c0ae"
uuid = "c5292f4c-5179-55e1-98c5-05642aab7184"
version = "0.6.9"

[[deps.Revise]]
deps = ["CodeTracking", "Distributed", "FileWatching", "JuliaInterpreter", "LibGit2", "LoweredCodeUtils", "OrderedCollections", "Pkg", "REPL", "Requires", "UUIDs", "Unicode"]
git-tree-sha1 = "12aa2d7593df490c407a3bbd8b86b8b515017f3e"
uuid = "295af30f-e4ad-537b-8983-00126c2a3abe"
version = "3.5.14"

[[deps.RingLists]]
deps = ["Random"]
git-tree-sha1 = "f39da63aa6d2d88e0c1bd20ed6a3ff9ea7171ada"
Expand Down
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ DataFramesMeta = "1313f7d8-7da2-5740-9ea0-a2ca25f37964"
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Tidier = "f0413319-3358-4bb0-8e7c-0c83523a93bd"

Expand Down
14 changes: 14 additions & 0 deletions dev/dev.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#using Pkg
#Pkg.status()

#using Revise
using HPCMod

# run dev test
include("../examples/simple1.jl")

# run tests manually
include("../test/runtests.jl")

# run tests
Pkg.test()
5 changes: 0 additions & 5 deletions src/HPCMod.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
module HPCMod

export hello_world
function hello_world()
"Hello world"
end

export CompTask
export BatchJob
#export Base.isless
Expand Down
23 changes: 18 additions & 5 deletions src/hpc_user_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,22 @@ function CompTask(
return sim.task_list[sim.last_task_id]
end

function BatchJob(sim::Simulation, task::CompTask, nodes::Int64, walltime::Int64; submit_time::Int64=-1)
"""
Create a BatchJob for task
"""
function BatchJob(
sim::Simulation, task::CompTask;
nodes::Int64=1,
walltime::Int64=1,
submit_time::Int64=-1,
jobs_list::Union{SortedSet,Nothing}=nothing)::BatchJob

sim.last_job_id += 1
push!(sim.jobs_list, BatchJob(sim.last_job_id, task, nodes, walltime, submit_time, 0, 0, NotScheduled, []))

if jobs_list !== nothing
push!(jobs_list, sim.jobs_list[sim.last_job_id])
end
return sim.jobs_list[sim.last_job_id]
end

Expand All @@ -50,7 +63,7 @@ function User(
max_nodes_per_job::Int64=0,
max_time_per_job::Int64=0,
user_id::Int64=-1
)
)::User
if user_id == -1
sim.last_user_id += 1
else
Expand Down Expand Up @@ -84,7 +97,7 @@ function add_resource!(sim::Simulation;
max_time_per_job=24 * 3,
scheduler_fifo=true,
scheduler_backfill=true
)
)::HPCResource
sim.space = GridSpace((nodes,); periodic=false, metric=:manhattan)
sim.resource = HPCResource(
nodes,
Expand All @@ -110,7 +123,7 @@ function Simulation(
rng::AbstractRNG=Random.default_rng(123),
user_extra_step::Union{Function,Nothing}=nothing,
model_extra_step::Union{Function,Nothing}=nothing
)
)::Simulation
sim = Simulation(
id,
timeunits_per_day,
Expand Down Expand Up @@ -167,7 +180,7 @@ function task_split_maxnode_maxtime!(sim::Simulation, model::StandardABM, user::
walltime = max_time_per_job
end

BatchJob(sim, task, nodes, walltime)
BatchJob(sim, task; nodes, walltime)
end

task_split! = [
Expand Down
3 changes: 1 addition & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using HPCMod
using Test

@testset "HPCMod.jl" begin
@test HPCMod.hello_world() == "Hello world"
include("testset1.jl")
end
48 changes: 48 additions & 0 deletions test/testset1.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using HPCMod
using Random
using DataFrames

@testset "BatchJob Comparison" begin
sim = Simulation()
add_resource!(sim)
user = User(sim)
task = user.inividual_jobs_task
jobs = user.inividual_jobs

job1 = BatchJob(sim, task; nodes=2, walltime=10, submit_time=12, jobs_list=jobs)
job2 = BatchJob(sim, task; nodes=2, walltime=10, submit_time=15, jobs_list=jobs)
job3 = BatchJob(sim, task; nodes=2, walltime=10, submit_time=10, jobs_list=jobs)
job4 = BatchJob(sim, task; nodes=2, walltime=10, submit_time=14, jobs_list=jobs)
job5 = BatchJob(sim, task; nodes=2, walltime=10, submit_time=14, jobs_list=jobs)

# compare by submit_time
@test job1 < job2
@test job4 > job3
@test (job4 > job5) == false
@test (job4 < job5) == false
@test (job4 == job5) == false

# pop test for user's inividual_jobs, sooner jobs pops first
@test pop!(jobs).id==3
@test pop!(jobs).id==1
@test pop!(jobs).id==4
@test pop!(jobs).id==5
@test pop!(jobs).id==2

# jobs are still in sim.jobs_list
@test length(sim.jobs_list)==5

end


@testset "Simple Run" begin
include("../examples/simple1.jl")

# check that it at lest produce something
@test nrow(mdf) > 100
@test sum(mdf.used_nodes) > 0
@test sum(mdf.jobs_in_queue) > 0
@test sum(mdf.jobs_running) > 0
@test sum(mdf.jobs_done) > 0

end

0 comments on commit 9f4cfda

Please sign in to comment.