Skip to content

Commit 7cb816e

Browse files
author
SamoraHunter
committed
implemented default single thread to avoid h2o and multiprocessing errors.
1 parent 780e228 commit 7cb816e

1 file changed

Lines changed: 71 additions & 15 deletions

File tree

notebooks/unit_test_synthetic.ipynb

Lines changed: 71 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -927,13 +927,6 @@
927927
" outcome_var_list"
928928
]
929929
},
930-
{
931-
"cell_type": "code",
932-
"execution_count": null,
933-
"metadata": {},
934-
"outputs": [],
935-
"source": []
936-
},
937930
{
938931
"cell_type": "code",
939932
"execution_count": null,
@@ -961,6 +954,10 @@
961954
" from ml_grid.pipeline.main import run\n",
962955
" from ml_grid.util.create_experiment_directory import create_experiment_directory\n",
963956
"\n",
957+
" # ========== TOGGLE FOR SINGLE-THREADED MODE ==========\n",
958+
" USE_SINGLE_THREADED = True # Set to True for single-threaded execution\n",
959+
" # =====================================================\n",
960+
"\n",
964961
" # 1. --- Load Configuration from YAML ---\n",
965962
" # This assumes 'config_hyperopt.yml' is in a location accessible from the notebook\n",
966963
" config = load_config('config_hyperopt.yml')\n",
@@ -1090,15 +1087,28 @@
10901087
" return (outcome_var, best)\n",
10911088
"\n",
10921089
" # 8. --- Main Execution Block ---\n",
1093-
" num_cores = max(1, multiprocessing.cpu_count() - 2)\n",
10941090
" start_total = datetime.now()\n",
1095-
" print(f\"Starting all optimizations at {start_total} using {num_cores} cores.\")\n",
1091+
" \n",
1092+
" if USE_SINGLE_THREADED:\n",
1093+
" # ========== SINGLE-THREADED EXECUTION ==========\n",
1094+
" print(f\"Starting all optimizations at {start_total} using SINGLE-THREADED mode.\")\n",
1095+
" \n",
1096+
" results = []\n",
1097+
" for outcome in outcome_var_list:\n",
1098+
" result = process_single_outcome(outcome)\n",
1099+
" results.append(result)\n",
1100+
" \n",
1101+
" else:\n",
1102+
" # ========== PARALLEL EXECUTION ==========\n",
1103+
" num_cores = max(1, multiprocessing.cpu_count() - 2)\n",
1104+
" \n",
1105+
" print(f\"Starting all optimizations at {start_total} using {num_cores} cores.\")\n",
10961106
"\n",
1097-
" # Parallel will raise exceptions from workers automatically\n",
1098-
" results = Parallel(n_jobs=num_cores, verbose=10)(\n",
1099-
" delayed(process_single_outcome)(outcome)\n",
1100-
" for outcome in outcome_var_list\n",
1101-
" )\n",
1107+
" # Parallel will raise exceptions from workers automatically\n",
1108+
" results = Parallel(n_jobs=num_cores, verbose=10)(\n",
1109+
" delayed(process_single_outcome)(outcome)\n",
1110+
" for outcome in outcome_var_list\n",
1111+
" )\n",
11021112
"\n",
11031113
" # --- Process and display final results ---\n",
11041114
" print(\"\\n\" + \"=\"*70)\n",
@@ -1294,6 +1304,13 @@
12941304
" print(f\" - In any timestamped subfolder within {experiments_base_dir.resolve()}\")"
12951305
]
12961306
},
1307+
{
1308+
"cell_type": "code",
1309+
"execution_count": null,
1310+
"metadata": {},
1311+
"outputs": [],
1312+
"source": []
1313+
},
12971314
{
12981315
"cell_type": "code",
12991316
"execution_count": null,
@@ -1476,7 +1493,46 @@
14761493
"cell_type": "code",
14771494
"execution_count": null,
14781495
"metadata": {},
1479-
"outputs": [],
1496+
"outputs": [
1497+
{
1498+
"name": "stdout",
1499+
"output_type": "stream",
1500+
"text": [
1501+
"Closing connection _sid_abe8 at exit\n",
1502+
"H2O session _sid_abe8 closed.\n",
1503+
"Closing connection _sid_b630 at exit\n",
1504+
"H2O session _sid_b630 closed.\n",
1505+
"Closing connection _sid_bdbe at exit\n",
1506+
"H2O session _sid_bdbe closed.\n",
1507+
"Closing connection _sid_b41b at exit\n",
1508+
"H2O session _sid_b41b closed.\n",
1509+
"Closing connection _sid_818c at exit\n",
1510+
"H2O session _sid_818c closed.\n",
1511+
"Closing connection _sid_9eef at exit\n",
1512+
"H2O session _sid_9eef closed.\n",
1513+
"Closing connection _sid_beac at exit\n",
1514+
"H2O session _sid_beac closed.\n",
1515+
"Closing connection _sid_93b5 at exit\n",
1516+
"H2O session _sid_93b5 closed.\n",
1517+
"Closing connection _sid_8746 at exit\n",
1518+
"H2O session _sid_8746 closed.\n",
1519+
"Closing connection _sid_a12e at exit\n",
1520+
"H2O session _sid_a12e closed.\n",
1521+
"Closing connection _sid_9419 at exit\n",
1522+
"H2O session _sid_9419 closed.\n",
1523+
"Closing connection _sid_90b5 at exit\n",
1524+
"H2O session _sid_90b5 closed.\n",
1525+
"Closing connection _sid_9b76 at exit\n",
1526+
"H2O session _sid_9b76 closed.\n",
1527+
"Closing connection _sid_a500 at exit\n",
1528+
"H2O session _sid_a500 closed.\n",
1529+
"Closing connection _sid_a1f4 at exit\n",
1530+
"H2O session _sid_a1f4 closed.\n",
1531+
"Closing connection _sid_acb7 at exit\n",
1532+
"H2O session _sid_acb7 closed.\n"
1533+
]
1534+
}
1535+
],
14801536
"source": [
14811537
"display(config)"
14821538
]

0 commit comments

Comments
 (0)