Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for multiprocessing on Linux #927

Merged
merged 2 commits into from
Jun 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions gridpath/get_scenario_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

from argparse import ArgumentParser
import csv
from multiprocessing import Pool
from multiprocessing import get_context
import os.path
import pandas as pd
import sys
Expand Down Expand Up @@ -132,7 +132,8 @@ def write_model_inputs(
]
)

pool = Pool(n_parallel_subproblems)
# Pool must use spawn to work properly on Linux
pool = get_context("spawn").Pool(n_parallel_subproblems)
pool.map(get_inputs_for_subproblem_pool, pool_data)
pool.close()

Expand Down
5 changes: 3 additions & 2 deletions gridpath/run_scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import argparse
from csv import reader, writer
import datetime
from multiprocessing import Pool, Manager
from multiprocessing import get_context, Manager
import os.path
from pyomo.environ import (
AbstractModel,
Expand Down Expand Up @@ -406,7 +406,8 @@ def run_scenario(scenario_directory, subproblem_structure, parsed_arguments):
for subproblem in subproblem_structure.SUBPROBLEM_STAGES.keys():
objective_values[subproblem] = manager.dict()

pool = Pool(n_parallel_subproblems)
# Pool must use spawn to work properly on Linux
pool = get_context("spawn").Pool(n_parallel_subproblems)
pool_data = tuple(
[
[
Expand Down
50 changes: 21 additions & 29 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,38 +530,30 @@ def test_example_single_stage_prod_cost_cycle_select(self):
def test_example_multi_stage_prod_cost_parallel(self):
"""
Check validation and objective function values of
"multi_stage_prod_cost" example
"multi_stage_prod_cost" example running subproblems in parallel
:return:
"""
# TODO: figure why run_e2e processed gets terminated on linux when
# using parallel processing; skip test on linux for the time being
if platform.system() == "Linux":
print(
"Skipping test_example_multi_stage_prod_cost_parallel on ",
platform.system(),
)
else:
self.run_and_check_objective(
"multi_stage_prod_cost",
{
1: {
1: -1265436373826.0408,
2: -1265436373826.0408,
3: -1265436373826.099,
},
2: {
1: -1265436373826.0408,
2: -1265436373826.0408,
3: -1265436373826.099,
},
3: {
1: -1265436373826.0408,
2: -1265436373826.0408,
3: -1265436373826.099,
},
self.run_and_check_objective(
"multi_stage_prod_cost",
{
1: {
1: -1265436373826.0408,
2: -1265436373826.0408,
3: -1265436373826.099,
},
parallel=3,
)
2: {
1: -1265436373826.0408,
2: -1265436373826.0408,
3: -1265436373826.099,
},
3: {
1: -1265436373826.0408,
2: -1265436373826.0408,
3: -1265436373826.099,
},
},
parallel=3,
)

def test_example_multi_stage_prod_cost_w_hydro(self):
"""
Expand Down