Commit 02069098 authored by Mads M. Pedersen's avatar Mads M. Pedersen Committed by Mads M. Pedersen
Browse files

add seed to smartstart and update parallel_runner

parent c48634ee
Pipeline #17763 passed with stages
in 3 minutes and 36 seconds
......@@ -45,6 +45,7 @@ class ParallelRunner():
seq_lst = [state_lst[i1:i2] for i1, i2 in zip(indexes[:-1], indexes[1:])]
results = self.pool.map(seq_runner, seq_lst)
results = [r for r_seq in results for r in r_seq]
best = results[np.argmin([r[0] for r in results])]
return best, results
......@@ -63,8 +64,8 @@ def get_InitialXYZOptimizationProblem(driver):
def seq_runner_example(lst):
print("%d cases executed by thread: %s" % (len(lst), threading.get_ident()))
return get_InitialXYZOptimizationProblem(lst).optimize()
print("%d cases executed by thread: %s" % (len(lst), threading.current_thread().ident))
return [get_InitialXYZOptimizationProblem(lst).optimize()]
# ===============================================================================
#
# ===============================================================================
......@@ -83,7 +84,7 @@ def main():
print("\nRun on one processor")
# run sequential
cost, state, recorder = seq_runner_example(lst)
cost, state, recorder = seq_runner_example(lst)[0]
print("Minimum cost: %.2f" % cost)
......
......@@ -227,7 +227,7 @@ def test_smart_start():
except AssertionError:
# wt2 and wt3 may switch
npt.assert_array_almost_equal(tf.turbine_positions, np.array([ys_ref, xs_ref]).T)
if 1:
if 0:
import matplotlib.pyplot as plt
plt.contourf(XX, YY, ZZ, 100)
for x, y in tf.turbine_positions:
......
......@@ -7,7 +7,7 @@ from topfarm.constraint_components.boundary import XYBoundaryConstraint
from topfarm import TopFarmProblem
@pytest.fixture("module")
@pytest.fixture(scope="module")
def parallelRunner():
return ParallelRunner()
......@@ -27,12 +27,12 @@ def lst():
def seq_runner_example(lst):
return get_InitialXYZOptimizationProblem(lst).optimize()
return [get_InitialXYZOptimizationProblem(lst).optimize()]
def test_parallel_run(lst, parallelRunner):
# run sequential
s_cost, s_state, s_recorder = seq_runner_example(lst)
s_cost, s_state, s_recorder = seq_runner_example(lst)[0]
# run in parallel
(p_cost, p_state, p_recorder), results = parallelRunner(lst, seq_runner_example)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment