在fmpy中无法找出哪个FMU有错误

Unable to find out which FMU has error in fmpy

我通过将包含 fmpy 模拟的函数放入循环中来模拟一批 5 个 FMU。 其中4个模拟正确。第五个因参数错误显示错误

我的问题是,有什么办法可以找出仿真过程中哪个FMU出错了

理想情况下,输出应如下所示: FMU1:好的 FMU2:好的 FMI3: 'Error' 依此类推

def wf(i):
    result = simulate_fmu(
        fmupath[i],
        validate=False,
        start_time=0,
        stop_time=endtime,
        solver='CVode',
        output_interval=stepsize,
        record_events=False,
        start_values = parameters[i],
        output = resultvariables,
    )
    dfindres = pd.DataFrame.from_dict(result)
    return dfindres

results = [wf(i) for i in range(5)]

您可以像这样捕获异常和 return 状态消息以及结果

def wf(i):
    try:
        result = simulate_fmu(
            fmupath[i],
            validate=False,
            start_time=0,
            stop_time=endtime,
            solver='CVode',
            output_interval=stepsize,
            record_events=False,
            start_values=parameters[i],
            output=resultvariables,
        )
    except Exception as e:
        return None, "FMU%d: Error" % i

    dfindres = pd.DataFrame.from_dict(result)
    return dfindres, "FMU%d: OK" % i

# list of tuples (result, status)
results = [wf(i) for i in range(5)]