feat: 外部引擎实时进度条 + C引擎read_bonds rewind修复

1. 引擎端:C/C++/Fortran 主循环每 1% 输出 progress 到 stdout
2. compute.py:读取 "[xxx] progress: N/total" 行更新 tqdm
3. 移除不准的时间估算逻辑,改用真实引擎进度
4. C引擎 read_bonds:rewind 后补 fgets 跳表头
5. gitignore 添加 output_test/
This commit is contained in:
2026-06-11 21:36:30 +08:00
parent 42c6776eff
commit db50ac6d4d
5 changed files with 27 additions and 5 deletions
+9 -3
View File
@@ -10,6 +10,7 @@ compute.py
"""
import json
import re
import numpy as np
import os
import platform
@@ -760,6 +761,14 @@ def run_engine(engine, input_dir, output_dir, config):
_line = _line.strip()
if _line:
_engine_lines.append(_line)
# 读取外部引擎真实进度:格式 "[xxx-engine] progress: N/total"
_prog_match = re.search(r'progress:\s*(\d+)/(\d+)', _line)
if _pbar is not None and _prog_match:
_prog_done = int(_prog_match.group(1))
_prog_total = int(_prog_match.group(2))
if _prog_total > 0:
_pbar.n = min(_prog_done, total_steps)
_pbar.refresh()
if _p.poll() is not None:
if _p.stdout:
for _r in _p.stdout:
@@ -767,9 +776,6 @@ def run_engine(engine, input_dir, output_dir, config):
if _r:
_engine_lines.append(_r)
break
if _pbar is not None and _est_total > 0:
_pbar.n = int(min((time.time() - t_start) / _est_total, 0.99) * total_steps)
_pbar.refresh()
time.sleep(0.2)
finally:
if _pbar is not None:
+6
View File
@@ -926,7 +926,13 @@ int main(int argc, char **argv) {
}
/* 记录 */
int _prog_interval = record_steps / 100;
if (_prog_interval < 1) _prog_interval = 1;
for (int s = 0; s < record_steps; s++) {
if (s % _prog_interval == 0 && s > 0) {
printf("[C-engine] progress: %d/%d\n", s, record_steps);
fflush(stdout);
}
double t = (s + params.warmup_steps) * params.DT;
if (params.driving_force) apply_driving_force(n, x, y, z, vx, vy, vz, t, s, params.DT, &drivers);
for (int i = 0; i < n; i++) {
+5
View File
@@ -843,7 +843,12 @@ int main(int argc, char **argv) {
}
// 记录
int _prog_int = record_steps / 100;
if (_prog_int < 1) _prog_int = 1;
for (int s = 0; s < record_steps; s++) {
if (s % _prog_int == 0 && s > 0) {
std::cout << "[Cpp-engine] progress: " << s << "/" << record_steps << std::endl;
}
double t = (s + params.warmup_steps) * params.DT;
if (params.driving_force)
apply_driving_force(n, x.data(), y.data(), z.data(), vx.data(), vy.data(), vz.data(), t, s, params.DT, drivers);
+6 -1
View File
@@ -34,7 +34,7 @@ program dynamics_f90
double precision, allocatable :: bond_stiffness(:), bond_rest_lengths(:)
!
integer :: n_drivers
integer :: n_drivers, prog_step
integer, allocatable :: drv_atom_idx(:)
double precision, allocatable :: drv_amp_x(:), drv_amp_y(:), drv_amp_z(:)
double precision, allocatable :: drv_freq_x(:), drv_freq_y(:), drv_freq_z(:)
@@ -139,7 +139,12 @@ program dynamics_f90
end do
!
prog_step = record_steps / 100
if (prog_step < 1) prog_step = 1
do s = 1, record_steps
if (mod(s, prog_step) == 0 .and. s > 0) then
write(*, '("[Fortran-engine] progress: ", i0, "/", i0)') s, record_steps
end if
if (driving_force /= 0 .and. n_drivers > 0) then
tw = ((s-1 + warmup_steps) * 1.0d0) * DT
call apply_driving(n, x, y, z, vx, vy, vz, tw, s-1, DT, &
+1 -1
View File
@@ -63,7 +63,7 @@ warmup_steps: 0 # 默认 0(立即开始记录)
# 总模拟时间(秒),程序自动计算 NT = T_total / DT
# 如果同时指定了 NT,以 NT 为准
T_total: 10.0
T_total: 50.0
# 抽帧间隔(每 NSTEP 步取一帧用于动画)
NSTEP: 100