mirror of
https://github.com/Brandon-Rozek/matmod.git
synced 2025-07-29 20:52:01 +00:00
Fix Multiprocessing on Windows (#27)
This commit is contained in:
commit
9f80fb8bba
2 changed files with 17 additions and 12 deletions
5
vsp.py
5
vsp.py
|
@ -98,14 +98,11 @@ Subalgebra 1: {set_to_str(self.subalgebra1)}
|
||||||
Subalgebra 2: {set_to_str(self.subalgebra2)}
|
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
|
Checks whether a model has the variable
|
||||||
sharing property.
|
sharing property.
|
||||||
"""
|
"""
|
||||||
impfunction = interpretation[Implication]
|
|
||||||
mconjunction = interpretation.get(Conjunction)
|
|
||||||
mdisjunction = interpretation.get(Disjunction)
|
|
||||||
top = find_top(model.carrier_set, mconjunction, mdisjunction)
|
top = find_top(model.carrier_set, mconjunction, mdisjunction)
|
||||||
bottom = find_bottom(model.carrier_set, mconjunction, mdisjunction)
|
bottom = find_bottom(model.carrier_set, mconjunction, mdisjunction)
|
||||||
|
|
||||||
|
|
24
vspursuer.py
24
vspursuer.py
|
@ -1,12 +1,10 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
from os import cpu_count
|
from os import cpu_count
|
||||||
import argparse
|
import argparse
|
||||||
import multiprocessing
|
import multiprocessing as mp
|
||||||
|
|
||||||
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__":
|
||||||
|
@ -24,11 +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")
|
||||||
|
|
||||||
|
# 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_expanded.append((model, impfunction, mconjunction, mdisjunction))
|
||||||
|
|
||||||
num_has_vsp = 0
|
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 = [
|
results = [
|
||||||
pool.apply_async(has_vsp, (model, interpretation,))
|
pool.apply_async(has_vsp, (model, impfunction, mconjunction, mdisjunction,))
|
||||||
for model, interpretation in solutions
|
for model, impfunction, mconjunction, mdisjunction in solutions_expanded
|
||||||
]
|
]
|
||||||
|
|
||||||
for i, result in enumerate(results):
|
for i, result in enumerate(results):
|
||||||
|
|
Loading…
Add table
Reference in a new issue