统一代理模型与相态场景路径

- 按实验标签解析T1到T4融合模型和T5专用模型
- 移除C++硬编码路径和Python旧路径回退
- 仅保存按相态命名的scene文件,避免覆盖通用scene.bin
feature/Model-20260625
lvjunjie 22 hours ago
parent 54ea2ef32d
commit 9ba0df411d

@ -70,27 +70,8 @@ def resolve_paths(args: argparse.Namespace) -> tuple[Path, Path, Path]:
config_path = Path(args.config) if args.config else config_for_stage(args.stage)
if config_path is None:
raise ValueError(f"Cannot resolve config for stage={args.stage!r}; pass --config explicitly")
cfg = Config(config_path)
if args.processed:
processed_path = Path(args.processed)
else:
processed_candidates = [
processed_path_for_tag(tag),
cfg.paths.processed_dir / f"dataset_{tag}.pkl",
cfg.paths.processed_dir / f"processed_{tag}.pkl",
]
processed_path = next((path for path in processed_candidates if path.exists()), processed_candidates[0])
if args.model:
model_path = Path(args.model)
else:
model_candidates = [
model_checkpoint_for_tag(tag, use_schedule=True),
cfg.paths.models_dir / str(tag) / "forward_surrogate_best.pt",
cfg.paths.models_dir / f"forward_surrogate_{tag}" / "forward_surrogate_best.pt",
]
model_path = next((path for path in model_candidates if path.exists()), model_candidates[0])
processed_path = Path(args.processed) if args.processed else processed_path_for_tag(tag)
model_path = Path(args.model) if args.model else model_checkpoint_for_tag(tag, use_schedule=True)
return config_path.resolve(), processed_path.resolve(), model_path.resolve()

@ -80,10 +80,6 @@ static const double kSurrogateConstPvtCtFixed = 1.0e-2; // T1/T3 训练数据
static const double kSurrogateFixedParamRelTol = 1.0e-4; // 固定参数仅允许 0.01% 相对偏差。
static const double kSurrogateCfMin = 1.0e-5; // T2/T4 训练数据中的 Cf 下界。
static const double kSurrogateCfMax = 1.0e-2; // T2/T4 训练数据中的 Cf 上界。
static const char kSurrogateProcessedPath[] = "C:/Users/Asus/Desktop/test/data/processed/dataset_T1_T4_fixed_time_40000.pkl";
static const char kSurrogateModelPath[] = "C:/Users/Asus/Desktop/test/models/T1_T4_fixed_time_40000_autofit_v1/forward_surrogate_best.pt";
static const char kT5SurrogateProcessedPath[] = "C:/Users/Asus/Desktop/test/data/processed/dataset_T5_fixedcf_random_18448.pkl";
static const char kT5SurrogateModelPath[] = "C:/Users/Asus/Desktop/test/models/T5_fixedcf_random_18448_delta_v1/forward_surrogate_best.pt";
static const double kSurrogateTrainingInitialPressure = 34.47;
static const int kSurrogateMinProdSections = 3; // 代理训练流量制度:生产段数量下界。
static const int kSurrogateMaxProdSections = 5; // 代理训练流量制度:生产段数量上界。
@ -129,24 +125,6 @@ static NM_SOLVER_MODEL_TYPE currentSolverModelType()
return dataManager ? dataManager->getSolverModelType() : SMT_Oil_ConstPvt;
}
static QString surrogateProcessedPath(NM_SOLVER_MODEL_TYPE solverModelType)
{
if(solverModelType == SMT_Gas_VariablePvt) {
return QDir::cleanPath(QString::fromLatin1(kT5SurrogateProcessedPath));
}
return QDir::cleanPath(QString::fromLatin1(kSurrogateProcessedPath));
}
static QString surrogateModelPath(NM_SOLVER_MODEL_TYPE solverModelType)
{
if(solverModelType == SMT_Gas_VariablePvt) {
return QDir::cleanPath(QString::fromLatin1(kT5SurrogateModelPath));
}
return QDir::cleanPath(QString::fromLatin1(kSurrogateModelPath));
}
struct SurrogateParameterDomain
{
double kMin;
@ -1352,10 +1330,10 @@ QString nmCalculationAutoFitPSO::getSurrogateTag() const
// 当前 C++ 绑定的代理模型实验标识,对应 ML 侧训练输出目录/checkpoint 命名。
// 如果以后换模型,需要同步更新这里和 ML 脚本可识别的 tag。
if(currentSolverModelType() == SMT_Gas_VariablePvt) {
return "T5_fixedcf_random_18448_delta_v1";
return "T5_family_random_18448_local_delta";
}
return "T1_T4_fixed_time_40000_autofit_v1";
return "T1_T4_family_random_40k_merged_autofit";
}
QString nmCalculationAutoFitPSO::getSurrogateStage() const
@ -1504,7 +1482,7 @@ bool nmCalculationAutoFitPSO::ensureSurrogateScoringServer(QString* failureReaso
{
// 确保常驻代理评分 server 已启动且与当前 run 配置匹配。
//
// serverKey 由 Python 路径、脚本路径、跟踪元数据、模型数据路径、模型标识和阶段组成。
// serverKey 由 Python 路径、脚本路径、跟踪元数据、模型标识和阶段组成。
// 只要其中任何一个变化,就停止旧进程并启动新进程,避免拿旧模型或旧目标曲线评分。
if(m_traceMetaFilePath.isEmpty() || !QFileInfo(m_traceMetaFilePath).exists()) {
QString reason = "trace meta file is missing";
@ -1532,15 +1510,10 @@ bool nmCalculationAutoFitPSO::ensureSurrogateScoringServer(QString* failureReaso
}
QString pythonPath = getPythonExecutablePath();
NM_SOLVER_MODEL_TYPE solverModelType = currentSolverModelType();
QString processedPath = surrogateProcessedPath(solverModelType);
QString modelPath = surrogateModelPath(solverModelType);
QString serverKey = QString("%1|%2|%3|%4|%5|%6|%7")
QString serverKey = QString("%1|%2|%3|%4|%5")
.arg(pythonPath)
.arg(scriptPath)
.arg(m_traceMetaFilePath)
.arg(processedPath)
.arg(modelPath)
.arg(getSurrogateTag())
.arg(getSurrogateStage());
@ -1556,8 +1529,6 @@ bool nmCalculationAutoFitPSO::ensureSurrogateScoringServer(QString* failureReaso
args << "-u"
<< scriptPath
<< "--trace-meta" << m_traceMetaFilePath
<< "--processed" << processedPath
<< "--model" << modelPath
<< "--tag" << getSurrogateTag()
<< "--stage" << getSurrogateStage();
@ -1837,16 +1808,11 @@ bool nmCalculationAutoFitPSO::runSurrogateScoringScriptOnce(const QString& candi
}
QString pythonPath = getPythonExecutablePath();
NM_SOLVER_MODEL_TYPE solverModelType = currentSolverModelType();
QString processedPath = surrogateProcessedPath(solverModelType);
QString modelPath = surrogateModelPath(solverModelType);
QStringList args;
args << scriptPath
<< "--candidates" << candidatePath
<< "--trace-meta" << m_traceMetaFilePath
<< "--output" << scorePath
<< "--processed" << processedPath
<< "--model" << modelPath
<< "--tag" << getSurrogateTag()
<< "--stage" << getSurrogateStage();

@ -908,7 +908,7 @@ bool nmCalculationPebiGrid::generateOutputPara()
this->meshGenPebiFault(p0);
this->meshGenPebiCrack(p0);
// ===== 导出 scene.bin =====
// ===== 导出当前相态 scene =====
{
nmDataBinaryTools::NM_PEBI_SCENE scene;
nmDataAnalyzeManager* dm = nmDataAnalyzeManager::getCurrentInstance();
@ -1091,17 +1091,7 @@ bool nmCalculationPebiGrid::generateOutputPara()
return false;
}
// 保留固定文件名作为当前场景入口兼容现有Training和Python数据生成流程。
QString latestOutPath = dataDir.filePath("scene.bin");
ok = nmDataBinaryTools::savePebiSceneBin(latestOutPath, scene);
if(!ok) {
zxLogInstance::getInstance()->writeLogF("savePebiSceneBin failed: " + nmDataBinaryTools::getLastError());
FreeLibrary(dll);
return false;
}
zxLogInstance::getInstance()->writeLogF("scene exported: " + typedOutPath);
zxLogInstance::getInstance()->writeLogF("latest scene exported: " + latestOutPath);
}
// ===== 导出所有井loglog + rate + pressure 到 temp 目录 =====

Loading…
Cancel
Save