Skip to content

mc

mc

InputGenerator

InputGenerator(output_dir: Path, num_simulations: int)

Bases: BaseProcess

Generates input files for the MID solver

Source code in src/process_manager/workflow/mc.py
def __init__(self, output_dir: Path, num_simulations: int):
    super().__init__(ProcessConfig(
        process_type=ProcessType.THREAD,
        process_id="input_generator"
    ))
    self.output_dir = output_dir
    self.num_simulations = num_simulations
    self.file_handler = FileHandler(output_dir)

MIDSolver

MIDSolver(mid_executable: Path)

Bases: BaseProcess

Runs the MID solver on input files

Source code in src/process_manager/workflow/mc.py
def __init__(self, mid_executable: Path):
    super().__init__(ProcessConfig(
        process_type=ProcessType.PROCESS,  # Use process pool for parallel execution
        process_id="mid_solver"
    ))
    self.mid_executable = mid_executable

ResultsAnalyzer

ResultsAnalyzer(output_dir: Path)

Bases: BaseProcess

Analyzes results from all Monte Carlo simulations

Source code in src/process_manager/workflow/mc.py
def __init__(self, output_dir: Path):
    super().__init__(ProcessConfig(
        process_type=ProcessType.THREAD,
        process_id="results_analyzer"
    ))
    self.output_dir = output_dir
    self.file_handler = FileHandler(output_dir)

SimulationParams dataclass

SimulationParams(temperature: float, pressure: float, flow_rate: float, sim_time: float)

Parameters for a single Monte Carlo simulation

run_monte_carlo_study async

run_monte_carlo_study(output_dir: Path, mid_executable: Path, num_simulations: int) -> DataFrame

Run complete Monte Carlo study workflow

Parameters:

Name Type Description Default
output_dir Path

Directory for all output files

required
mid_executable Path

Path to MID solver executable

required
num_simulations int

Number of Monte Carlo simulations to run

required

Returns:

Type Description
DataFrame

DataFrame with analysis results

Source code in src/process_manager/workflow/mc.py
async def run_monte_carlo_study(
    output_dir: Path,
    mid_executable: Path,
    num_simulations: int
) -> pd.DataFrame:
    """
    Run complete Monte Carlo study workflow

    Args:
        output_dir: Directory for all output files
        mid_executable: Path to MID solver executable
        num_simulations: Number of Monte Carlo simulations to run

    Returns:
        DataFrame with analysis results
    """
    # Create output directory
    output_dir.mkdir(parents=True, exist_ok=True)

    # Create processes
    input_gen = InputGenerator(output_dir, num_simulations)
    solver = MIDSolver(mid_executable)
    analyzer = ResultsAnalyzer(output_dir)

    # Create workflow nodes
    input_node = WorkflowNode(
        process=input_gen,
        dependencies=[]  # No dependencies
    )

    solver_node = WorkflowNode(
        process=solver,
        dependencies=[input_gen.config.process_id]
    )

    analyzer_node = WorkflowNode(
        process=analyzer,
        dependencies=[solver.config.process_id]
    )

    # Create and run workflow
    async with Workflow(
        max_processes=4,  # Adjust based on your system
        max_threads=2
    ) as workflow:
        # Add nodes
        workflow.add_node(input_node)
        workflow.add_node(solver_node)
        workflow.add_node(analyzer_node)

        # Execute workflow
        results = await workflow.execute()

        # Return analysis results
        return results[analyzer.config.process_id].data