Spaces:
Sleeping
Sleeping
MilesCranmer
commited on
Commit
•
eefdfef
1
Parent(s):
ebba171
Remove problematic math-mode=fast; add back extra threads
Browse files- julia/sr.jl +41 -14
- pysr/sr.py +0 -1
julia/sr.jl
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import Optim
|
2 |
import Printf: @printf
|
|
|
3 |
|
4 |
const maxdegree = 2
|
5 |
const actualMaxsize = maxsize + maxdegree
|
@@ -623,21 +624,47 @@ function bestSubPop(pop::Population; topn::Integer=10)::Population
|
|
623 |
return Population(pop.members[best_idx[1:topn]])
|
624 |
end
|
625 |
|
626 |
-
# Mutate the best sampled member of the population
|
627 |
-
function iterateSample(pop::Population, T::Float32)::PopMember
|
628 |
-
allstar = bestOfSample(pop)
|
629 |
-
return iterate(allstar, T)
|
630 |
-
end
|
631 |
-
|
632 |
# Pass through the population several times, replacing the oldest
|
633 |
# with the fittest of a small subsample
|
634 |
function regEvolCycle(pop::Population, T::Float32)::Population
|
635 |
-
for
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
pop.members
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
640 |
end
|
|
|
641 |
return pop
|
642 |
end
|
643 |
|
@@ -799,13 +826,13 @@ function fullRun(niterations::Integer;
|
|
799 |
hallOfFame = HallOfFame()
|
800 |
|
801 |
for i=1:npopulations
|
802 |
-
future = @
|
803 |
push!(allPops, future)
|
804 |
end
|
805 |
|
806 |
# # 2. Start the cycle on every process:
|
807 |
@sync for i=1:npopulations
|
808 |
-
@async allPops[i] = @
|
809 |
end
|
810 |
println("Started!")
|
811 |
cycles_complete = npopulations * niterations
|
@@ -883,7 +910,7 @@ function fullRun(niterations::Integer;
|
|
883 |
end
|
884 |
|
885 |
@async begin
|
886 |
-
allPops[i] = @
|
887 |
tmp_pop = run(cur_pop, ncyclesperiteration, verbosity=verbosity)
|
888 |
for j=1:tmp_pop.n
|
889 |
if rand() < 0.1
|
|
|
1 |
import Optim
|
2 |
import Printf: @printf
|
3 |
+
import Random: shuffle!
|
4 |
|
5 |
const maxdegree = 2
|
6 |
const actualMaxsize = maxsize + maxdegree
|
|
|
624 |
return Population(pop.members[best_idx[1:topn]])
|
625 |
end
|
626 |
|
|
|
|
|
|
|
|
|
|
|
|
|
627 |
# Pass through the population several times, replacing the oldest
|
628 |
# with the fittest of a small subsample
|
629 |
function regEvolCycle(pop::Population, T::Float32)::Population
|
630 |
+
# Batch over each subsample. Can give 15% improvement in speed; probably moreso for large pops.
|
631 |
+
# but is ultimately a different algorithm than regularized evolution, and might not be
|
632 |
+
# as good.
|
633 |
+
if fast_cycle
|
634 |
+
shuffle!(pop.members)
|
635 |
+
n_evol_cycles = round(Integer, pop.n/ns)
|
636 |
+
babies = Array{PopMember}(undef, n_evol_cycles)
|
637 |
+
|
638 |
+
# Iterate each ns-member sub-sample
|
639 |
+
@inbounds Threads.@threads for i=1:n_evol_cycles
|
640 |
+
best_score = Inf32
|
641 |
+
best_idx = 1+(i-1)*ns
|
642 |
+
# Calculate best member of the subsample:
|
643 |
+
for sub_i=1+(i-1)*ns:i*ns
|
644 |
+
if pop.members[sub_i].score < best_score
|
645 |
+
best_score = pop.members[sub_i].score
|
646 |
+
best_idx = sub_i
|
647 |
+
end
|
648 |
+
end
|
649 |
+
allstar = pop.members[best_idx]
|
650 |
+
babies[i] = iterate(allstar, T)
|
651 |
+
end
|
652 |
+
|
653 |
+
# Replace the n_evol_cycles-oldest members of each population
|
654 |
+
@inbounds for i=1:n_evol_cycles
|
655 |
+
oldest = argmin([pop.members[member].birth for member=1:pop.n])
|
656 |
+
pop.members[oldest] = babies[i]
|
657 |
+
end
|
658 |
+
else
|
659 |
+
for i=1:round(Integer, pop.n/ns)
|
660 |
+
allstar = bestOfSample(pop)
|
661 |
+
baby = iterate(allstar, T)
|
662 |
+
#printTree(baby.tree)
|
663 |
+
oldest = argmin([pop.members[member].birth for member=1:pop.n])
|
664 |
+
pop.members[oldest] = baby
|
665 |
+
end
|
666 |
end
|
667 |
+
|
668 |
return pop
|
669 |
end
|
670 |
|
|
|
826 |
hallOfFame = HallOfFame()
|
827 |
|
828 |
for i=1:npopulations
|
829 |
+
future = @spawnat :any Population(npop, 3)
|
830 |
push!(allPops, future)
|
831 |
end
|
832 |
|
833 |
# # 2. Start the cycle on every process:
|
834 |
@sync for i=1:npopulations
|
835 |
+
@async allPops[i] = @spawnat :any run(fetch(allPops[i]), ncyclesperiteration, verbosity=verbosity)
|
836 |
end
|
837 |
println("Started!")
|
838 |
cycles_complete = npopulations * niterations
|
|
|
910 |
end
|
911 |
|
912 |
@async begin
|
913 |
+
allPops[i] = @spawnat :any let
|
914 |
tmp_pop = run(cur_pop, ncyclesperiteration, verbosity=verbosity)
|
915 |
for j=1:tmp_pop.n
|
916 |
if rand() < 0.1
|
pysr/sr.py
CHANGED
@@ -264,7 +264,6 @@ const weights = convert(Array{Float32, 1}, """f"{weight_str})"
|
|
264 |
|
265 |
command = [
|
266 |
f'julia -O{julia_optimization:d}',
|
267 |
-
f'--math-mode=fast',
|
268 |
f'-p {procs}',
|
269 |
f'/tmp/.runfile_{rand_string}.jl',
|
270 |
]
|
|
|
264 |
|
265 |
command = [
|
266 |
f'julia -O{julia_optimization:d}',
|
|
|
267 |
f'-p {procs}',
|
268 |
f'/tmp/.runfile_{rand_string}.jl',
|
269 |
]
|