RascalSoftware / python-RAT

Python interface for RAT
1 stars 5 forks source link

Modifies cells to make function handles pickleable #82

Closed StephenNneji closed 1 month ago

StephenNneji commented 1 month ago

I missed this in the PR to make the pybind classes pickleable. The function handles cannot be pickled so this defers the creation of the handles. The script below uses the languages example to test that all 3 languages pickle correctly and run in a process

from multiprocessing import Process

def f(problem_definition, cells, limits, priors, cpp_controls):

    start = time.time()
    problem_definition, output_results, bayes_results = RAT.rat_core.RATMain(
    problem_definition,
    cells,
    limits,
    cpp_controls,
    priors,
    )
    end = time.time()
    print(f"Run time is: {end-start}s\n")

if __name__ == '__main__':

    project = setup_problem.make_example_problem()
    # project.custom_files.set_fields(0, filename="custom_bilayer.m", language="matlab", path=path)
    # project.custom_files.set_fields(0, filename="custom_bilayer.dll", function_name="customBilayer", language="cpp", path=path)
    controls = RAT.Controls()
    problem_definition, cells, limits, priors, cpp_controls = RAT.inputs.make_input(project, controls)

    p = Process(target=f, args=(problem_definition, cells, limits, priors, cpp_controls,))
    p.start()
    p.join()