From b06dd8ee013c6dbafa31fb3d40d5946d3b5a7f75 Mon Sep 17 00:00:00 2001 From: Brandon Rozek Date: Tue, 10 Dec 2024 17:17:14 -0800 Subject: [PATCH 1/2] Don't rely on shared memory for logic operators --- vsp.py | 5 +---- vspursuer.py | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/vsp.py b/vsp.py index 6a50c63..ad2849b 100644 --- a/vsp.py +++ b/vsp.py @@ -98,14 +98,11 @@ Subalgebra 1: {set_to_str(self.subalgebra1)} Subalgebra 2: {set_to_str(self.subalgebra2)} """ -def has_vsp(model: Model, interpretation: Dict[Operation, ModelFunction]) -> VSP_Result: +def has_vsp(model: Model, impfunction: ModelFunction, mconjunction: Optional[ModelFunction] = None, mdisjunction: Optional[ModelFunction] = None) -> VSP_Result: """ Checks whether a model has the variable sharing property. """ - impfunction = interpretation[Implication] - mconjunction = interpretation.get(Conjunction) - mdisjunction = interpretation.get(Disjunction) top = find_top(model.carrier_set, mconjunction, mdisjunction) bottom = find_bottom(model.carrier_set, mconjunction, mdisjunction) diff --git a/vspursuer.py b/vspursuer.py index 5a6ee55..70e0f02 100755 --- a/vspursuer.py +++ b/vspursuer.py @@ -1,7 +1,8 @@ #!/usr/bin/env python3 from os import cpu_count import argparse -import multiprocessing +import multiprocessing as mp +from logic import Implication, Conjunction, Disjunction from parse_magic import ( SourceFile, @@ -24,11 +25,18 @@ if __name__ == "__main__": solutions = parse_matrices(SourceFile(data_file)) print(f"Parsed {len(solutions)} matrices") + solutions_prep = [] + for model, interpretation in solutions: + impfunction = interpretation[Implication] + mconjunction = interpretation.get(Conjunction) + mdisjunction = interpretation.get(Disjunction) + solutions_prep.append((model, impfunction, mconjunction, mdisjunction)) + num_has_vsp = 0 - with multiprocessing.Pool(processes=max(cpu_count() - 2, 1)) as pool: + with mp.Pool(processes=max(cpu_count() - 2, 1)) as pool: results = [ - pool.apply_async(has_vsp, (model, interpretation,)) - for model, interpretation in solutions + pool.apply_async(has_vsp, (model, impfunction, mconjunction, mdisjunction,)) + for model, impfunction, mconjunction, mdisjunction in solutions_prep ] for i, result in enumerate(results): From 70cd1cfa7f02bf737c9d6c9e48374571573792c4 Mon Sep 17 00:00:00 2001 From: Brandon Rozek Date: Tue, 10 Dec 2024 18:34:43 -0500 Subject: [PATCH 2/2] Small cleanup --- vspursuer.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/vspursuer.py b/vspursuer.py index 70e0f02..66716a3 100755 --- a/vspursuer.py +++ b/vspursuer.py @@ -2,12 +2,9 @@ from os import cpu_count import argparse import multiprocessing as mp -from logic import Implication, Conjunction, Disjunction -from parse_magic import ( - SourceFile, - parse_matrices -) +from logic import Conjunction, Disjunction, Implication +from parse_magic import SourceFile, parse_matrices from vsp import has_vsp, VSP_Result if __name__ == "__main__": @@ -25,18 +22,21 @@ if __name__ == "__main__": solutions = parse_matrices(SourceFile(data_file)) print(f"Parsed {len(solutions)} matrices") - solutions_prep = [] + # NOTE: When subprocess gets spawned, the logical operations will + # have a different memory address than what's expected in interpretation. + # This will make it so that we can pass the model functions directly instead. + solutions_expanded = [] for model, interpretation in solutions: impfunction = interpretation[Implication] mconjunction = interpretation.get(Conjunction) mdisjunction = interpretation.get(Disjunction) - solutions_prep.append((model, impfunction, mconjunction, mdisjunction)) + solutions_expanded.append((model, impfunction, mconjunction, mdisjunction)) num_has_vsp = 0 with mp.Pool(processes=max(cpu_count() - 2, 1)) as pool: results = [ pool.apply_async(has_vsp, (model, impfunction, mconjunction, mdisjunction,)) - for model, impfunction, mconjunction, mdisjunction in solutions_prep + for model, impfunction, mconjunction, mdisjunction in solutions_expanded ] for i, result in enumerate(results):