Small cleanup

This commit is contained in:
Brandon Rozek 2024-12-10 18:34:43 -05:00
parent b06dd8ee01
commit 70cd1cfa7f

View file

@ -2,12 +2,9 @@
from os import cpu_count from os import cpu_count
import argparse import argparse
import multiprocessing as mp import multiprocessing as mp
from logic import Implication, Conjunction, Disjunction
from parse_magic import ( from logic import Conjunction, Disjunction, Implication
SourceFile, from parse_magic import SourceFile, parse_matrices
parse_matrices
)
from vsp import has_vsp, VSP_Result from vsp import has_vsp, VSP_Result
if __name__ == "__main__": if __name__ == "__main__":
@ -25,18 +22,21 @@ if __name__ == "__main__":
solutions = parse_matrices(SourceFile(data_file)) solutions = parse_matrices(SourceFile(data_file))
print(f"Parsed {len(solutions)} matrices") 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: for model, interpretation in solutions:
impfunction = interpretation[Implication] impfunction = interpretation[Implication]
mconjunction = interpretation.get(Conjunction) mconjunction = interpretation.get(Conjunction)
mdisjunction = interpretation.get(Disjunction) mdisjunction = interpretation.get(Disjunction)
solutions_prep.append((model, impfunction, mconjunction, mdisjunction)) solutions_expanded.append((model, impfunction, mconjunction, mdisjunction))
num_has_vsp = 0 num_has_vsp = 0
with mp.Pool(processes=max(cpu_count() - 2, 1)) as pool: with mp.Pool(processes=max(cpu_count() - 2, 1)) as pool:
results = [ results = [
pool.apply_async(has_vsp, (model, impfunction, mconjunction, mdisjunction,)) 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): for i, result in enumerate(results):