Skip to content

Commit 224621d

Browse files
authored
Merge pull request #70 from JuliaGraphs/hw/fix_rng
fix rng pr
2 parents 4b085ae + 465d170 commit 224621d

File tree

7 files changed

+20
-28
lines changed

7 files changed

+20
-28
lines changed

.github/workflows/CI.yml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,7 @@ jobs:
2626
with:
2727
version: ${{ matrix.version }}
2828
arch: ${{ matrix.arch }}
29-
- uses: actions/cache@v1
30-
env:
31-
cache-name: cache-artifacts
32-
with:
33-
path: ~/.julia/artifacts
34-
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
35-
restore-keys: |
36-
${{ runner.os }}-test-${{ env.cache-name }}-
37-
${{ runner.os }}-test-
38-
${{ runner.os }}-
29+
- uses: julia-actions/cache@v2
3930
- uses: julia-actions/julia-buildpkg@v1
4031
- uses: julia-actions/julia-runtest@v1
4132
- uses: julia-actions/julia-processcoverage@v1
@@ -50,6 +41,7 @@ jobs:
5041
- uses: julia-actions/setup-julia@v2
5142
with:
5243
version: '1'
44+
- uses: julia-actions/cache@v2
5345
- uses: julia-actions/julia-buildpkg@v1
5446
- uses: julia-actions/julia-docdeploy@v1
5547
env:

.github/workflows/CompatHelper.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
run: which julia
1616
continue-on-error: true
1717
- name: Install Julia, but only if it is not already available in the PATH
18-
uses: julia-actions/setup-julia@v1
18+
uses: julia-actions/setup-julia@v2
1919
with:
2020
version: '1'
2121
arch: ${{ runner.arch }}

docs/Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ GraphMakie = "1ecd5474-83a3-4783-bb4f-06765db800d2"
55
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
66
NetworkLayout = "46757867-2c16-5918-afeb-47bfcb05e46a"
77
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
8+
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
89

910
[compat]
10-
CairoMakie = "0.10"
11+
CairoMakie = "0.11"
1112
Documenter = "1"
1213
GraphMakie = "0.5"
1314
Graphs = "1.9"
1415
NetworkLayout = "0.4"
16+
StableRNGs = "1.0.1"

docs/make.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ using NetworkLayout
33
using Graphs
44
using GraphMakie
55
using CairoMakie
6+
using StableRNGs
67

8+
NetworkLayout.DEFAULT_RNG[] = StableRNG
79
DocMeta.setdocmeta!(NetworkLayout, :DocTestSetup, :(using NetworkLayout); recursive=true)
810

911
makedocs(; modules=[NetworkLayout],

docs/src/index.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ All example images on this page are created using [`Makie.jl`](https://github.co
1010
```@example layouts
1111
using CairoMakie
1212
CairoMakie.activate!(type="png") # hide
13-
set_theme!(resolution=(800, 400)) #hide
13+
set_theme!(size=(800, 400)) #hide
1414
using NetworkLayout
1515
using GraphMakie, Graphs
1616
nothing #hide
@@ -167,7 +167,7 @@ hidedecorations!(ax); hidespines!(ax); f #hide
167167
f #hide
168168
```
169169
```@example layouts
170-
set_theme!(resolution=(800, 800)) #hide
170+
set_theme!(size=(800, 800)) #hide
171171
using Random; Random.seed!(5) # hide
172172
layout = Spectral()
173173
f, ax, p = graphplot(g, layout=layout, node_size=0.0, edge_width=1.0)
@@ -201,11 +201,11 @@ nothing #hide
201201
```
202202
Example animation on how those keyword arguments effect different iterative layouts:
203203
```@example layouts
204-
springl = Spring(;initialpos, pin, seed=11) #2
204+
springl = Spring(;initialpos, pin, seed=2)
205205
sfdpl = SFDP(;initialpos, pin, tol=0.0)
206206
stressl = Stress(;initialpos, pin, reltols=0.0, abstolx=0.0, iterations=100)
207207
208-
f = Figure(resolution=(1200,500))
208+
f = Figure(size=(1200,500))
209209
ax1 = f[1,1] = Axis(f; title="Spring")
210210
ax2 = f[1,2] = Axis(f; title="SFDP")
211211
ax3 = f[1,3] = Axis(f; title="Stress")

src/sfdp.jl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ function Base.iterate(iter::LayoutIterator{<:SFDP{Dim,Ptype,T}}) where {Dim,Ptyp
7676
pin = [get(algo.pin, i, SVector{Dim,Bool}(false for _ in 1:Dim)) for i in 1:N]
7777

7878
# iteratorstate: (#iter, energy, step, progress, old pos, pin, stopflag)
79-
return startpos, (1, typemax(T), one(T), 0, startpos, pin, false)
79+
return startpos, (1, typemax(T), one(T), 0, startpos, pin, rng, false)
8080
end
8181

8282
function Base.iterate(iter::LayoutIterator{<:SFDP}, state)
8383
algo, adj_matrix = iter.algorithm, iter.adj_matrix
84-
iter, energy0, step, progress, locs0, pin, stopflag = state
84+
iter, energy0, step, progress, locs0, pin, rng, stopflag = state
8585
K, C, tol = algo.K, algo.C, algo.tol
8686

8787
# stop if stopflag (tol reached) or nr of iterations reached
@@ -109,9 +109,7 @@ function Base.iterate(iter::LayoutIterator{<:SFDP}, state)
109109
end
110110
if any(isnan, force)
111111
# if two points are at the exact same location use random force in any direction
112-
# copy rng from alg struct to not advance the "initial" rng state
113-
# otherwise algo(g)==algo(g) might be broken
114-
force += randn(copy(algo.rng), Ftype)
112+
force = randn(rng, Ftype)
115113
end
116114
mask = (!).(pin[i]) # where pin=true mask will multiply with 0
117115
locs[i] = locs[i] .+ (step .* (force ./ norm(force))) .* mask
@@ -124,7 +122,7 @@ function Base.iterate(iter::LayoutIterator{<:SFDP}, state)
124122
stopflag = true
125123
end
126124

127-
return locs, (iter + 1, energy, step, progress, locs, pin, stopflag)
125+
return locs, (iter + 1, energy, step, progress, locs, pin, rng, stopflag)
128126
end
129127

130128
# Calculate Attractive force

src/spring.jl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ function Base.iterate(iter::LayoutIterator{<:Spring{Dim,Ptype}}) where {Dim,Ptyp
7575
pin = [get(algo.pin, i, SVector{Dim,Bool}(false for _ in 1:Dim)) for i in 1:N]
7676

7777
# iteratorstate: #iter nr, old pos, pin
78-
return (startpos, (1, startpos, pin))
78+
return (startpos, (1, startpos, pin, rng))
7979
end
8080

8181
function Base.iterate(iter::LayoutIterator{<:Spring}, state)
8282
algo, adj_matrix = iter.algorithm, iter.adj_matrix
83-
iteration, old_pos, pin = state
83+
iteration, old_pos, pin, rng = state
8484
iteration >= algo.iterations && return nothing
8585

8686
# The optimal distance bewteen vertices
@@ -114,9 +114,7 @@ function Base.iterate(iter::LayoutIterator{<:Spring}, state)
114114
else
115115
# if two points are at the exact same location
116116
# use random force in any direction
117-
# copy rng from alg struct to not advance the "initial" rng state
118-
# otherwise algo(g)==algo(g) might be broken
119-
force_vec += randn(copy(algo.rng), Ftype)
117+
force_vec += randn(rng, Ftype)
120118
end
121119

122120
end
@@ -134,5 +132,5 @@ function Base.iterate(iter::LayoutIterator{<:Spring}, state)
134132
locs[i] += force[i] .* scale .* mask
135133
end
136134

137-
return locs, (iteration + 1, locs, pin)
135+
return locs, (iteration + 1, locs, pin, rng)
138136
end

0 commit comments

Comments
 (0)