param( [ValidateSet('status','prepare','benchmark','benchmark-registration','lock','register','train','diagnostics','summarize','all')] [string]$Stage = 'all', [ValidatePattern('^(cuda:[0-9]+|cpu)$')][string]$Device = 'cuda:0', [ValidateRange(1,8)][int]$Workers = 4, [switch]$Detach, [switch]$Smoke, [switch]$Sections, [switch]$SkipVolume ) $ErrorActionPreference = 'Stop' $p3Workspace = Split-Path -Parent $PSScriptRoot $p3Python = Join-Path $p3Workspace '.venv/Scripts/python.exe' $env:OMP_NUM_THREADS = '2' $env:MKL_NUM_THREADS = '2' $env:OPENBLAS_NUM_THREADS = '2' $env:NUMBA_NUM_THREADS = '2' $env:PYTHONUTF8 = '1' $env:PYTHONHASHSEED = '0' $env:CUBLAS_WORKSPACE_CONFIG = ':4096:8' $p3Arguments = @('-X','utf8','-m','ml_porosity.runlog','-n',"p3_$Stage",'--', $p3Python,'-X','utf8',(Join-Path $PSScriptRoot '19_run_f3.py'),$Stage, '--device',$Device,'--workers',"$Workers") if ($Smoke) { $p3Arguments += '--smoke' } if ($Sections) { $p3Arguments += '--sections' } if ($SkipVolume) { $p3Arguments += '--skip-volume' } if ($Detach) { $p3LogDirectory = Join-Path $p3Workspace 'logs/runs' New-Item -ItemType Directory -Path $p3LogDirectory -Force | Out-Null $p3Stamp = Get-Date -Format 'yyyyMMdd-HHmmss' $p3QuotedArguments = $p3Arguments | ForEach-Object { '"' + $_.Replace('"','\"') + '"' } $p3Process = Start-Process -FilePath $p3Python -ArgumentList $p3QuotedArguments -WorkingDirectory $p3Workspace ` -WindowStyle Hidden -PassThru -RedirectStandardOutput (Join-Path $p3LogDirectory "${p3Stamp}_p3_stdout.log") ` -RedirectStandardError (Join-Path $p3LogDirectory "${p3Stamp}_p3_stderr.log") Write-Output "P3 detached: PID $($p3Process.Id). Track report.html and outputs/p3/progress.json." } else { Push-Location $p3Workspace try { & $p3Python @p3Arguments; if ($LASTEXITCODE -ne 0) { throw "P3 exited with code $LASTEXITCODE" } } finally { Pop-Location } }