Skip to content

Commit fecc042

Browse files
mortenpipfitzseb
andauthored
fix: show methods for ComputeConfig and NodeSpec (#34)
* fix: show methods for ComputeConfig and NodeSpec * add changelog * update doctests --------- Co-authored-by: Sebastian Pfitzner <[email protected]>
1 parent 91a7664 commit fecc042

File tree

5 files changed

+41
-12
lines changed

5 files changed

+41
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
88

99
* Fixed the submission of application-type jobs. (#31, #32, #33, #35)
1010
* `JuliaHub.applications()` no longer throws a type error when the user has no registered and user applications. (#33)
11+
* Fixed the `show(io, x)` methods for `ComputeConfig` and `NodeSpec`. (#34)
1112

1213
## Version v0.1.4 - 2023-08-21
1314

docs/src/reference/job-submission.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ A list of these node specifications can be obtained with the [`nodespecs`](@ref)
4646
```jldoctest
4747
julia> JuliaHub.nodespecs()
4848
9-element Vector{JuliaHub.NodeSpec}:
49-
JuliaHub.nodespec(#= m6: 3.5 GHz Intel Xeon Platinum 8375C, 0.33/hr =#; ncpu=4, memory=16, gpu=false)
50-
JuliaHub.nodespec(#= m6: 3.5 GHz Intel Xeon Platinum 8375C, 0.65/hr =#; ncpu=8, memory=32, gpu=false)
51-
JuliaHub.nodespec(#= m6: 3.5 GHz Intel Xeon Platinum 8375C, 2.4/hr =#; ncpu=32, memory=128, gpu=false)
52-
JuliaHub.nodespec(#= r6: 3.5 GHz Intel Xeon Platinum 8375C, 0.22/hr =#; ncpu=2, memory=16, gpu=false)
53-
JuliaHub.nodespec(#= r6: 3.5 GHz Intel Xeon Platinum 8375C, 0.42/hr =#; ncpu=4, memory=32, gpu=false)
54-
JuliaHub.nodespec(#= m6: 3.5 GHz Intel Xeon Platinum 8375C, 0.17/hr =#; ncpu=2, memory=8, gpu=false)
55-
JuliaHub.nodespec(#= r6: 3.5 GHz Intel Xeon Platinum 8375C, 1.3/hr =#; ncpu=8, memory=64, gpu=false)
56-
JuliaHub.nodespec(#= p2: Intel Xeon E5-2686 v4 (Broadwell), 1.4/hr =#; ncpu=4, memory=61, gpu=true)
57-
JuliaHub.nodespec(#= p3: Intel Xeon E5-2686 v4 (Broadwell), 4.5/hr =#; ncpu=8, memory=61, gpu=true)
49+
JuliaHub.nodespec(#= m6: 3.5 GHz Intel Xeon Platinum 8375C, 0.33/hr =#; ncpu=4, memory=16, ngpu=false, exactmatch=true)
50+
JuliaHub.nodespec(#= m6: 3.5 GHz Intel Xeon Platinum 8375C, 0.65/hr =#; ncpu=8, memory=32, ngpu=false, exactmatch=true)
51+
JuliaHub.nodespec(#= m6: 3.5 GHz Intel Xeon Platinum 8375C, 2.4/hr =#; ncpu=32, memory=128, ngpu=false, exactmatch=true)
52+
JuliaHub.nodespec(#= r6: 3.5 GHz Intel Xeon Platinum 8375C, 0.22/hr =#; ncpu=2, memory=16, ngpu=false, exactmatch=true)
53+
JuliaHub.nodespec(#= r6: 3.5 GHz Intel Xeon Platinum 8375C, 0.42/hr =#; ncpu=4, memory=32, ngpu=false, exactmatch=true)
54+
JuliaHub.nodespec(#= m6: 3.5 GHz Intel Xeon Platinum 8375C, 0.17/hr =#; ncpu=2, memory=8, ngpu=false, exactmatch=true)
55+
JuliaHub.nodespec(#= r6: 3.5 GHz Intel Xeon Platinum 8375C, 1.3/hr =#; ncpu=8, memory=64, ngpu=false, exactmatch=true)
56+
JuliaHub.nodespec(#= p2: Intel Xeon E5-2686 v4 (Broadwell), 1.4/hr =#; ncpu=4, memory=61, ngpu=true, exactmatch=true)
57+
JuliaHub.nodespec(#= p3: Intel Xeon E5-2686 v4 (Broadwell), 4.5/hr =#; ncpu=8, memory=61, ngpu=true, exactmatch=true)
5858
```
5959

6060
While you can manually index into the list returned by [`nodespecs`](@ref), that is generally inconvenient.

src/jobsubmission.jl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,15 @@ end
262262

263263
function Base.show(io::IO, c::ComputeConfig)
264264
print(io, typeof(c), "(", c.node, "; ")
265-
print(io, "nnodes = ", c.nnodes, ", ")
266-
print(io, "process_per_node = ", c.process_per_node)
265+
print(io, "nnodes = ")
266+
if !isnothing(c.nnodes_min)
267+
print(io, "(", c.nnodes_min, ", ", c.nnodes_max, ")")
268+
else
269+
print(io, c.nnodes_max)
270+
end
271+
print(io, ", ")
272+
print(io, "process_per_node = ", c.process_per_node, ", ")
273+
print(io, "elastic = ", c.elastic)
267274
print(io, ")")
268275
end
269276

src/node.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ end
5555
function Base.show(io::IO, node::NodeSpec)
5656
print(io, "JuliaHub.nodespec(")
5757
print(io, "#= $(node.nodeClass): $(node.desc), $(node.priceHr)/hr =#")
58-
print(io, "; ncpu=$(node.vcores), memory=$(node.mem), gpu=$(node.hasGPU))")
58+
print(io, "; ncpu=$(node.vcores), memory=$(node.mem), ngpu=$(node.hasGPU), exactmatch=true)")
5959
end
6060

6161
function Base.show(io::IO, ::MIME"text/plain", node::NodeSpec)

test/jobs.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,24 +149,45 @@ end
149149
end
150150
end
151151

152+
# This testset uses the show(::IO, ::JuliaHub.ComputeConfig) representation of ComputeConfig,
153+
# makes sure it parses, and then also makes sure it parses into the same object (i.e. all
154+
# fields are restored accurately).
155+
function ComputeConfig_eval_tests(cc::JuliaHub.ComputeConfig)
156+
cc_expr = Meta.parse(string(cc))
157+
@test cc_expr.head == :call
158+
@test cc_expr.args[1] == :(JuliaHub.ComputeConfig)
159+
@test cc_expr.args[3].head == :call
160+
# Indirectly, we're also testing the parsing of the nodespec() function
161+
cc_eval = Mocking.apply(mocking_patch) do
162+
eval(cc_expr)
163+
end
164+
@test cc_eval isa JuliaHub.ComputeConfig
165+
for fieldname in fieldnames(JuliaHub.ComputeConfig)
166+
@test getfield(cc_eval, fieldname) == getfield(cc, fieldname)
167+
end
168+
end
169+
152170
@testset "JuliaHub.ComputeConfig" begin
153171
let cc = JuliaHub.ComputeConfig(ns_cheapest)
154172
@test cc.nnodes_max === 1
155173
@test cc.nnodes_min === nothing
156174
@test cc.process_per_node === true
157175
@test cc.elastic === false
176+
ComputeConfig_eval_tests(cc)
158177
end
159178
let cc = JuliaHub.ComputeConfig(ns_cheapest; nnodes = 5, elastic=true)
160179
@test cc.nnodes_max === 5
161180
@test cc.nnodes_min === nothing
162181
@test cc.process_per_node === true
163182
@test cc.elastic === true
183+
ComputeConfig_eval_tests(cc)
164184
end
165185
let cc = JuliaHub.ComputeConfig(ns_cheapest; nnodes = (10, 20))
166186
@test cc.nnodes_max === 20
167187
@test cc.nnodes_min === 10
168188
@test cc.process_per_node === true
169189
@test cc.elastic === false
190+
ComputeConfig_eval_tests(cc)
170191
end
171192
@test_throws ArgumentError JuliaHub.ComputeConfig(ns_cheapest; nnodes=-20)
172193
@test_throws ArgumentError JuliaHub.ComputeConfig(ns_cheapest; nnodes=(-5, 3))

0 commit comments

Comments
 (0)