From 0ef3e2da909aa6da46f91d37df2c12c2df6430fd Mon Sep 17 00:00:00 2001 From: haksunli Date: Tue, 3 Nov 2026 21:54:05 -0500 Subject: [PATCH 1/2] Pin Commons benchmark dependencies to released 4.0-beta1 artifacts --- benchmark/dependencies.lock.tsv | 8 +-- benchmark/scripts/repair-commons.ps1 | 57 +++++++++++++++++++ .../nm/benchmark/OriginValidationMain.java | 4 +- benchmark/versions.json | 4 +- 4 files changed, 65 insertions(+), 8 deletions(-) create mode 100644 benchmark/scripts/repair-commons.ps1 diff --git a/benchmark/dependencies.lock.tsv b/benchmark/dependencies.lock.tsv index 7de43fd..3f3a919 100644 --- a/benchmark/dependencies.lock.tsv +++ b/benchmark/dependencies.lock.tsv @@ -18,10 +18,10 @@ netlib-java-0.9.3.jar f997d8f84de8de6fbf38b25a2b0ad7cd317f9245f47144557d6aaf415a ojalgo-57.5.0.jar 603dbc26c8d625699ab631b6d56240fd6c488260e3d5db498f9ac71944cb9b3f https://repo.maven.apache.org/maven2/org/ojalgo/ojalgo/57.5.0/ojalgo-57.5.0.jar ujmp-core-0.3.0.jar e5cf6dbb7b7ebc6b4eb088a6f6f76162fd8c1ad8d222bf5777b59de8ea7e47a7 https://repo.maven.apache.org/maven2/org/ujmp/ujmp-core/0.3.0/ujmp-core-0.3.0.jar json-20141113.jar 87bbe48a7e93d6bcfe91c36f4e73a4a670b3843e0cc10aaf48a23ba40a99671b https://repo.maven.apache.org/maven2/org/json/json/20141113/json-20141113.jar -commons-math4-core-4.0-SNAPSHOT.jar 7fcd23cbb4ddd9536f1cdbe761d528c707ab5590e245c2341ce990196ca6e0b0 https://repository.apache.org/content/repositories/snapshots/org/apache/commons/commons-math4-core/4.0-SNAPSHOT/commons-math4-core-4.0-20261018.085925-1447.jar -commons-math4-legacy-4.0-SNAPSHOT.jar 5db3d8096b42daffc5573ca78163d5461b2039dddd884c8e3e3c5d799b8aa144 https://repository.apache.org/content/repositories/snapshots/org/apache/commons/commons-math4-legacy/4.0-SNAPSHOT/commons-math4-legacy-4.0-20261018.085925-1575.jar -commons-math4-legacy-core-4.0-SNAPSHOT.jar 1ae582cd07f29abc3bb17877aa6a290d8bd8e7074adc762a330dd24ef569b9d8 https://repository.apache.org/content/repositories/snapshots/org/apache/commons/commons-math4-legacy-core/4.0-SNAPSHOT/commons-math4-legacy-core-4.0-20261018.085925-1586.jar -commons-math4-legacy-exception-4.0-SNAPSHOT.jar c48a58d12ca4eef6770591fa51349805644f934c376e43f4c68ffa6fefdbe36e https://repository.apache.org/content/repositories/snapshots/org/apache/commons/commons-math4-legacy-exception/4.0-SNAPSHOT/commons-math4-legacy-exception-4.0-20261018.085925-1597.jar +commons-math4-core-4.0-beta1.jar 0a694f3203cd94b0ea2804e0fd927c651a5120ceb8504d128cfb9e199783c188 https://repo.maven.apache.org/maven2/org/apache/commons/commons-math4-core/4.0-beta1/commons-math4-core-4.0-beta1.jar +commons-math4-legacy-4.0-beta1.jar c0d4bdedc85682630c20d7c751135ce958bc595e813647fbe7ee9038912e0337 https://repo.maven.apache.org/maven2/org/apache/commons/commons-math4-legacy/4.0-beta1/commons-math4-legacy-4.0-beta1.jar +commons-math4-legacy-core-4.0-beta1.jar c5bcc8d8f62f3797f5dc623fbfd4a2907383c513f91620a176868efb36aeb101 https://repo.maven.apache.org/maven2/org/apache/commons/commons-math4-legacy-core/4.0-beta1/commons-math4-legacy-core-4.0-beta1.jar +commons-math4-legacy-exception-4.0-beta1.jar eab5de858ddc35e55e9db0f2eff7621dafe36a92eb885aec2f9fe313ee55cb14 https://repo.maven.apache.org/maven2/org/apache/commons/commons-math4-legacy-exception/4.0-beta1/commons-math4-legacy-exception-4.0-beta1.jar commons-numbers-angle-1.3.jar 021369f205d6dc9a189db54c065f10d617541b58e05acf0c59a8de0995cdd122 https://repo.maven.apache.org/maven2/org/apache/commons/commons-numbers-angle/1.3/commons-numbers-angle-1.3.jar commons-numbers-arrays-1.3.jar 758460f666c1316a2bae58cce1ef5010c41761a2f2023f94f54842ecab85c41f https://repo.maven.apache.org/maven2/org/apache/commons/commons-numbers-arrays/1.3/commons-numbers-arrays-1.3.jar commons-numbers-combinatorics-1.3.jar 22485298bb05cae240460a5405848e0a6ba7883f95a1221144859346be0a0a1d https://repo.maven.apache.org/maven2/org/apache/commons/commons-numbers-combinatorics/1.3/commons-numbers-combinatorics-1.3.jar diff --git a/benchmark/scripts/repair-commons.ps1 b/benchmark/scripts/repair-commons.ps1 new file mode 100644 index 0000000..3ead9d8 --- /dev/null +++ b/benchmark/scripts/repair-commons.ps1 @@ -0,0 +1,57 @@ +param([string]$RepositoryPath = (Get-Location).Path) +Set-StrictMode -Version Latest +$ErrorActionPreference = 'Stop' +$repo = (Resolve-Path -LiteralPath $RepositoryPath).Path +$lockPath = Join-Path $repo 'benchmark/dependencies.lock.tsv' +$originPath = Join-Path $repo 'benchmark/src/main/java/dev/nm/benchmark/OriginValidationMain.java' +$versionsPath = Join-Path $repo 'benchmark/versions.json' +$pins = [ordered]@{ + 'commons-math4-core' = '0a694f3203cd94b0ea2804e0fd927c651a5120ceb8504d128cfb9e199783c188' + 'commons-math4-legacy' = 'c0d4bdedc85682630c20d7c751135ce958bc595e813647fbe7ee9038912e0337' + 'commons-math4-legacy-core' = 'c5bcc8d8f62f3797f5dc623fbfd4a2907383c513f91620a176868efb36aeb101' + 'commons-math4-legacy-exception' = 'eab5de858ddc35e55e9db0f2eff7621dafe36a92eb885aec2f9fe313ee55cb14' +} +foreach ($path in @($lockPath,$originPath,$versionsPath)) { + if (-not (Test-Path -LiteralPath $path -PathType Leaf)) { throw "Missing source file: $path" } +} + +# Prepare all edits before writing; retain every other library and the NMDEV pin. +$lock = [IO.File]::ReadAllText($lockPath) +foreach ($artifact in $pins.Keys) { + $pattern = '(?m)^' + [regex]::Escape($artifact) + '-4\.0-(?:SNAPSHOT|beta1)\.jar\t[^\r\n]*' + if ([regex]::Matches($lock,$pattern).Count -ne 1) { throw "Expected one lock entry for $artifact; no files changed." } + $name = "$artifact-4.0-beta1.jar" + $url = "https://repo.maven.apache.org/maven2/org/apache/commons/$artifact/4.0-beta1/$name" + $line = $name + "`t" + $pins[$artifact] + "`t" + $url + $lock = [regex]::Replace($lock,$pattern,$line) +} +$origin = [IO.File]::ReadAllText($originPath) +$originPattern = 'commons-math4-legacy-4\.0-(?:SNAPSHOT|beta1)\.jar' +if ([regex]::Matches($origin,$originPattern).Count -ne 2) { throw 'Expected two Commons origin checks; no files changed.' } +$origin = [regex]::Replace($origin,$originPattern,'commons-math4-legacy-4.0-beta1.jar') +$versions = [IO.File]::ReadAllText($versionsPath) | ConvertFrom-Json +foreach ($key in @('COMMONS','COMMONS_BLOCK')) { + if ($null -eq $versions.PSObject.Properties[$key]) { throw "Missing version label: $key; no files changed." } +} +$versions.COMMONS = 'Commons Math 4.0-beta1 - Array2DRowRealMatrix' +$versions.COMMONS_BLOCK = 'Commons Math 4.0-beta1 - BlockRealMatrix' +$updates = [ordered]@{} +$updates[$lockPath] = $lock +$updates[$originPath] = $origin +$updates[$versionsPath] = ($versions | ConvertTo-Json -Depth 20) + [Environment]::NewLine + +$backup = Join-Path $repo ('benchmark-commons-backup-' + [DateTime]::UtcNow.ToString('yyyyMMdd-HHmmss-fff')) +[IO.Directory]::CreateDirectory($backup) | Out-Null +foreach ($path in $updates.Keys) { + Copy-Item -LiteralPath $path -Destination (Join-Path $backup (Split-Path -Leaf $path)) +} +$utf8 = New-Object System.Text.UTF8Encoding($false) +foreach ($path in $updates.Keys) { [IO.File]::WriteAllText($path,[string]$updates[$path],$utf8) } +Write-Host 'Pinned all four Commons Math modules to released 4.0-beta1 artifacts with verified SHA-256 hashes.' +Write-Host "Source backups: $backup" +Write-Host 'NMDEV and all other dependency pins were preserved.' +Write-Host 'Commons differs from the previous snapshot comparison; the version labels now record this explicitly.' +Write-Host '' +Write-Host 'Build once, then use this NEW output directory to avoid stale snapshot JARs:' +Write-Host 'mvn -s benchmark/settings.xml -gs benchmark/settings.xml -f benchmark/pom.xml package' +Write-Host 'java -jar benchmark/target/nmdev-benchmark-1.2.0.jar --output nmdev-1.2.10-local-beta1' diff --git a/benchmark/src/main/java/dev/nm/benchmark/OriginValidationMain.java b/benchmark/src/main/java/dev/nm/benchmark/OriginValidationMain.java index 2e60517..ccf9893 100644 --- a/benchmark/src/main/java/dev/nm/benchmark/OriginValidationMain.java +++ b/benchmark/src/main/java/dev/nm/benchmark/OriginValidationMain.java @@ -7,8 +7,8 @@ public final class OriginValidationMain { public static void main(String[] args) throws Exception { String[][] cases={ {"NMDEV","dev.nm.algebra.linear.matrix.doubles.matrixtype.dense.DenseMatrix","nmdev-1.2.6.jar"}, - {"COMMONS_BLOCK","org.apache.commons.math4.legacy.linear.BlockRealMatrix","commons-math4-legacy-4.0-SNAPSHOT.jar"}, - {"COMMONS","org.apache.commons.math4.legacy.linear.Array2DRowRealMatrix","commons-math4-legacy-4.0-SNAPSHOT.jar"}, + {"COMMONS_BLOCK","org.apache.commons.math4.legacy.linear.BlockRealMatrix","commons-math4-legacy-4.0-beta1.jar"}, + {"COMMONS","org.apache.commons.math4.legacy.linear.Array2DRowRealMatrix","commons-math4-legacy-4.0-beta1.jar"}, {"PARALLEL_COLT","cern.colt.matrix.tdouble.impl.DenseDoubleMatrix2D","parallelcolt-0.11.4.jar"}, {"EJML","org.ejml.data.DMatrixRMaj","ejml-core-0.46.1.jar"}, {"OJALGO","org.ojalgo.matrix.store.R064Store","ojalgo-57.5.0.jar"}, diff --git a/benchmark/versions.json b/benchmark/versions.json index 39da776..71d04f7 100644 --- a/benchmark/versions.json +++ b/benchmark/versions.json @@ -1,6 +1,6 @@ { "NMDEV": "NM Dev 1.2.6", - "COMMONS": "Commons Math 4.0-SNAPSHOT (20261018.085925-1575) \u2014 Array2DRowRealMatrix", + "COMMONS": "Commons Math 4.0-beta1 - Array2DRowRealMatrix", "PARALLEL_COLT": "Parallel Colt 0.11.4 (upstream tag build)", "EJML": "EJML 0.46.1", "OJALGO": "ojAlgo 57.5.0", @@ -10,5 +10,5 @@ "MTJ": "MTJ 1.0.4 (F2J)", "UJMP": "UJMP 0.3.0 (core)", "F2J_LAPACK": "F2J LAPACK/BLAS 0.1", - "COMMONS_BLOCK": "Commons Math 4.0-SNAPSHOT (20261018.085925-1575) \u2014 BlockRealMatrix" + "COMMONS_BLOCK": "Commons Math 4.0-beta1 - BlockRealMatrix" } From 20d9e27850cfebc9faf717539329f06866a91230 Mon Sep 17 00:00:00 2001 From: haksunli Date: Tue, 3 Nov 2026 22:05:53 -0500 Subject: [PATCH 2/2] Make benchmark runner reusable with any selected NMDEV JAR --- .github/workflows/benchmark-application.yml | 38 ++++++++++++- benchmark/LOCAL-RUN.md | 33 ++++++++++- .../nm/benchmark/launcher/BenchmarkMain.java | 15 +++-- .../nm/benchmark/launcher/Dependencies.java | 21 +++++-- .../dev/nm/benchmark/launcher/NmdevInput.java | 52 +++++++++++++++++ .../nm/benchmark/launcher/NmdevInputTest.java | 51 +++++++++++++++++ benchmark/pom.xml | 2 +- benchmark/run-benchmark.ps1 | 54 ++++++++++++++++++ benchmark/scripts/build-direct.sh | 5 +- benchmark/scripts/repair-commons.ps1 | 57 ------------------- benchmark/scripts/run.sh | 8 ++- .../nm/benchmark/OriginValidationMain.java | 2 +- benchmark/versions.json | 2 +- 13 files changed, 262 insertions(+), 78 deletions(-) create mode 100644 benchmark/launcher/src/main/java/dev/nm/benchmark/launcher/NmdevInput.java create mode 100644 benchmark/launcher/src/test/java/dev/nm/benchmark/launcher/NmdevInputTest.java create mode 100644 benchmark/run-benchmark.ps1 mode change 100755 => 100644 benchmark/scripts/build-direct.sh delete mode 100644 benchmark/scripts/repair-commons.ps1 diff --git a/.github/workflows/benchmark-application.yml b/.github/workflows/benchmark-application.yml index 6982bc1..66c690c 100644 --- a/.github/workflows/benchmark-application.yml +++ b/.github/workflows/benchmark-application.yml @@ -33,12 +33,24 @@ jobs: distribution: temurin java-version: '17' cache: maven + - name: Check PowerShell entrypoint syntax + shell: pwsh + run: '[scriptblock]::Create([IO.File]::ReadAllText("benchmark/run-benchmark.ps1")) | Out-Null' - name: Build application and test checkpoint/ZIP safeguards run: mvn -B -f benchmark/pom.xml package - name: Verify automatic preparation and all library/profile adapters - run: java -Xmx2g -jar benchmark/target/nmdev-benchmark-1.2.0.jar --smoke --output smoke-results + run: java -Xmx2g -jar benchmark/target/nmdev-benchmark-1.3.0.jar --smoke --output smoke-results + - name: Verify arbitrary local NMDEV filename and recorded binary origin + shell: pwsh + run: | + Copy-Item smoke-results/.runtime/lib/nmdev-selected.jar 'selected NMDEV.jar' + java -Xmx2g -jar benchmark/target/nmdev-benchmark-1.3.0.jar --nmdev-jar 'selected NMDEV.jar' --smoke --libraries 'NMDEV,COMMONS,COMMONS_BLOCK' --max-cases 1 --output local-jar-results + if ($LASTEXITCODE -ne 0) { throw 'Local-JAR smoke failed' } + $expected = (Get-FileHash 'selected NMDEV.jar' -Algorithm SHA256).Hash.ToLowerInvariant() + $recorded = Get-Content local-jar-results/binary-provenance.json -Raw | ConvertFrom-Json + if ($recorded.nmdev_sha256 -ne $expected -or $recorded.nmdev_original_filename -ne 'selected NMDEV.jar') { throw 'Wrong NMDEV binary provenance' } - name: Verify saved forks are reused - run: java -Xmx2g -jar benchmark/target/nmdev-benchmark-1.2.0.jar --smoke --output smoke-results + run: java -Xmx2g -jar benchmark/target/nmdev-benchmark-1.3.0.jar --smoke --output smoke-results - uses: actions/upload-artifact@v4 if: always() with: @@ -49,4 +61,24 @@ jobs: if: matrix.os == 'ubuntu-24.04' && success() with: name: nmdev-benchmark-application - path: benchmark/target/nmdev-benchmark-1.2.0.jar + path: benchmark/target/nmdev-benchmark-1.3.0.jar + + release: + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + needs: portable + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + - uses: actions/download-artifact@v4 + with: + name: nmdev-benchmark-application + path: release + - name: Publish verified reusable application + env: + GH_TOKEN: ${{ github.token }} + run: | + cd release + sha256sum nmdev-benchmark-1.3.0.jar > SHA256SUMS + gh release create benchmark-v1.3.0 nmdev-benchmark-1.3.0.jar SHA256SUMS ../benchmark/run-benchmark.ps1 --repo nmltd/nmdev-examples --target "$GITHUB_SHA" --title 'Reusable benchmark application 1.3.0' --notes 'Select any NMDEV binary with --nmdev-jar. Full 1,260-case suite across eleven libraries including both Commons matrix implementations. Released checksum-pinned Commons Math 4.0-beta1 dependencies. Windows and Linux application smoke, local-JAR selection and resume checks passed for this exact application build. Full benchmark timings are run locally.' diff --git a/benchmark/LOCAL-RUN.md b/benchmark/LOCAL-RUN.md index e530311..72134a1 100644 --- a/benchmark/LOCAL-RUN.md +++ b/benchmark/LOCAL-RUN.md @@ -1,3 +1,34 @@ +# Reusable benchmark application 1.3.0 + +From PowerShell, run `benchmark/run-benchmark.ps1`. It downloads the checksum-verified prebuilt runner and NMDEV 1.2.10, then starts the complete suite. A full JDK 17+ is required; Maven and source edits are unnecessary. + +```powershell +powershell -ExecutionPolicy Bypass -File benchmark/run-benchmark.ps1 -NmdevVersion 1.2.10 +# Future releases: change only -NmdevVersion. For a custom build, select its file: +powershell -ExecutionPolicy Bypass -File benchmark/run-benchmark.ps1 -NmdevJar 'D:\path\nmdev.jar' -OutputDirectory custom-results +``` + +The same Java application also accepts `--nmdev-jar` directly: + +```text +java -jar nmdev-benchmark-1.3.0.jar --nmdev-jar path/to/nmdev.jar --output new-results +``` + +All 1,260 cases and eleven libraries (twelve implementation variants) remain enabled, including Commons array and block matrices. The selected file is validated as an NMDEV JAR, copied under one private runtime filename, and its actual SHA-256, original filename and embedded version (if supplied by the JAR) are recorded. No version is inferred solely from its filename. A new NMDEV binary requires a new result directory; changing the binary in a stopped run is rejected before cached JARs or result metadata are replaced. Repeat the same command to resume. + +Commons now uses the released **4.0-beta1** JARs from Maven Central, with explicit hashes and matching origin checks. Expiring timestamped Apache snapshot URLs are no longer needed. These Commons results use a different comparator binary from historical 4.0-SNAPSHOT runs and must be labelled accordingly. Other comparison-library pins and numerical benchmark sources are unchanged. + +To build the runner yourself: + +```text +mvn -s benchmark/settings.xml -gs benchmark/settings.xml -f benchmark/pom.xml package +java -jar benchmark/target/nmdev-benchmark-1.3.0.jar --nmdev-jar path/to/nmdev.jar --output new-results +``` + +Older application instructions and experiment history follow. Do not use packaging-only migration to move a 1.2.0 experiment to 1.3.0; keep the original runner and results for that experiment. + +--- + # Run the complete benchmark unattended Requires a **full JDK 17 or newer**, Maven to build, and Internet access on the first run. Windows, Linux and macOS use the same Java entry point; no WSL, Python, shell scripts, GitHub token, manual dependency installation or profile selection is required. @@ -13,7 +44,7 @@ The public application entry point is `dev.nm.benchmark.launcher.BenchmarkMain`. With no arguments, the application automatically: -1. Downloads checksum-verified numerical dependencies and the repository's public trial license. It uses the validated NM Dev 1.2.6 public release and the timestamp-pinned Commons Math 4 snapshot from the lockfile, keeping version labels explicit. The public NM Dev binary hash differs from the older archived benchmark binary; local measurements must be treated as a separate experiment. +1. Downloads checksum-verified numerical dependencies and the repository's public trial license. Application 1.3.0 defaults to the validated NM Dev 1.2.10 release (or your --nmdev-jar selection) and released Commons Math 4.0-beta1 modules from the lockfile, keeping version labels explicit. The public NM Dev binary hash differs from the older archived benchmark binary; local measurements must be treated as a separate experiment. 2. Builds Parallel Colt 0.11.4 from a checksum-verified archive of its exact upstream commit, then compiles the bundled JMH harness. The locally built binary's actual hash and compiler version are recorded; compiler-dependent binary hashes can differ between machines. 3. Collects machine information and runs correctness, input-preservation, pivot and backend preflight checks. 4. Runs all **1,260 cases** serially: 312 baseline, 360 large-square, 48 rectangular, plus 540 all-core cases. All eleven libraries (twelve implementation variants) are attempted. One-thread, four-thread and all-core profiles are scheduled automatically; they never run concurrently. diff --git a/benchmark/launcher/src/main/java/dev/nm/benchmark/launcher/BenchmarkMain.java b/benchmark/launcher/src/main/java/dev/nm/benchmark/launcher/BenchmarkMain.java index a713062..bcc72fb 100644 --- a/benchmark/launcher/src/main/java/dev/nm/benchmark/launcher/BenchmarkMain.java +++ b/benchmark/launcher/src/main/java/dev/nm/benchmark/launcher/BenchmarkMain.java @@ -47,16 +47,18 @@ static List plan(boolean smoke, List libraries, int availableProce } public static void main(String[] args) throws Exception { boolean smoke = false; Path output = Path.of("nmdev-benchmark-output"); int maxCases = Integer.MAX_VALUE; - List libraries = LIBRARIES; + List libraries = LIBRARIES; Path nmdevJar=null; for (int i=0;i libraries, int maxCases) throws Exception { + static void run(Path output, boolean smoke, List libraries, int maxCases, Path nmdevJar) throws Exception { + Path previousRequest=output.resolve("request.json"); + if(Files.exists(previousRequest) && !Storage.read(previousRequest).getAsJsonObject().get("application_sha256").getAsString().equals(Storage.sha(Dependencies.application()))) + throw new IOException("Benchmark application changed. Use a new --output directory; saved results were preserved."); List cases=plan(smoke,libraries); Map machine=MachineInfo.collect(); if(!Files.exists(output.resolve("machine.json"))) Storage.json(output.resolve("machine.json"),machine); Storage.json(output.resolve("latest-machine.json"),machine); System.out.println("NM Dev unattended benchmark: "+cases.size()+" cases, two independent JVM forks per case."); System.out.println("Output: "+output+"; repeat this command to resume. Long operations can take several minutes."); - Map artifacts=Dependencies.prepare(output); Dependencies.harness(output); + Map artifacts=Dependencies.prepare(output,nmdevJar); Dependencies.harness(output); Map request=new LinkedHashMap<>(); request.put("format",2); request.put("all_cores_available_processors",Runtime.getRuntime().availableProcessors()); request.put("suite",smoke?"SMOKE-NOT-FOR-PUBLICATION":"FULL"); request.put("cases",cases); request.put("artifacts",artifacts); request.put("machine",MachineInfo.identity(machine)); request.put("application_sha256",Storage.sha(Dependencies.application())); diff --git a/benchmark/launcher/src/main/java/dev/nm/benchmark/launcher/Dependencies.java b/benchmark/launcher/src/main/java/dev/nm/benchmark/launcher/Dependencies.java index 7d12298..2166e4f 100644 --- a/benchmark/launcher/src/main/java/dev/nm/benchmark/launcher/Dependencies.java +++ b/benchmark/launcher/src/main/java/dev/nm/benchmark/launcher/Dependencies.java @@ -13,8 +13,8 @@ /** Prepares immutable public inputs without Maven credentials, Python or Git. */ final class Dependencies { - static final String NM_URL = "https://github.com/nmltd/maven-packages/releases/download/nmdev-1.2.6-validated/nmdev-1.2.6.jar"; - static final String NM_SHA = "0b2d807d17927b482fadcdc313768a61d2fbdc80c7da4226005a198e0a6796ba"; + static final String NM_URL = "https://github.com/nmltd/maven-packages/releases/download/nmdev-1.2.10-validated/nmdev-1.2.10.jar"; + static final String NM_SHA = "a4284d16dcb83851c5486892a4425e7b5c6b9341895b484609449aee30d4f846"; static final String LICENSE_URL = "https://raw.githubusercontent.com/nmltd/nmdev-examples/ad1fbacaeea9c92ead37beb3002566c33b5a6006/nm.lic"; static final String LICENSE_SHA = "2fbc9e56f7d8d933bfd7c59c39cf08bee151305b285f35a19882cc2c844bb1c1"; static final String COLT_URL = "https://codeload.github.com/rwl/ParallelColt/zip/7c34364026680c1113f1a9586b9fb8c55080330c"; @@ -61,9 +61,18 @@ protected PasswordAuthentication getPasswordAuthentication() { } throw new IOException("Unable to prepare verified dependency " + path.getFileName(), last); } - static Map prepare(Path output) throws Exception { + static Map prepare(Path output, Path selectedJar) throws Exception { Path runtime = output.resolve(".runtime"), lib = runtime.resolve("lib"); Files.createDirectories(lib); + NmdevInput selected=selectedJar==null?null:NmdevInput.open(selectedJar); + NmdevInput.requireCompatibleRun(output,selected==null?NM_SHA:selected.sha256()); + Path runtimeJar=lib.resolve(NmdevInput.RUNTIME_NAME); + if(selected==null) { + download(NM_URL,NM_SHA,runtimeJar); + selected=NmdevInput.open(runtimeJar); + } + selected.install(runtimeJar); + System.out.println("NMDEV binary: "+selected.label()+"; SHA-256 "+selected.sha256()); resource("config/dependencies.lock.tsv", output.resolve("dependencies.lock.tsv.txt")); resource("config/versions.json", output.resolve("versions.json")); String lock = Files.readString(output.resolve("dependencies.lock.tsv.txt")); @@ -74,7 +83,9 @@ static Map prepare(Path output) throws Exception { if (values.length != 3) throw new IOException("Malformed dependency lock entry"); if (!values[2].startsWith("source:")) download(values[2], values[1], lib.resolve(values[0])); } - download(NM_URL, NM_SHA, lib.resolve("nmdev-1.2.6.jar")); + var versions=Storage.read(output.resolve("versions.json")).getAsJsonObject(); + versions.addProperty("NMDEV",selected.label()); + Storage.json(output.resolve("versions.json"),versions); Path customLicense = System.getProperty("nmdev.license") == null ? null : Path.of(System.getProperty("nmdev.license")).toAbsolutePath(); if (customLicense != null) Storage.atomic(runtime.resolve("nm.lic"), Files.readAllBytes(customLicense)); else download(LICENSE_URL, LICENSE_SHA, runtime.resolve("nm.lic")); @@ -99,7 +110,7 @@ static Map prepare(Path output) throws Exception { try (var files = Files.list(lib)) { for (Path file : files.filter(p -> p.toString().endsWith(".jar")).sorted().toList()) hashes.put(file.getFileName().toString(), Storage.sha(file)); } Storage.json(output.resolve("artifacts.json"), hashes); Storage.json(output.resolve("parallelcolt-build.json"), Storage.read(stamp)); - Storage.json(output.resolve("binary-provenance.json"), Map.of("nmdev_url", NM_URL, "nmdev_sha256", NM_SHA, "nmdev_checksum_source", "https://github.com/nmltd/maven-packages/releases/download/nmdev-1.2.6-validated/SHA256SUMS", "public_trial_url", LICENSE_URL, + Storage.json(output.resolve("binary-provenance.json"), Map.of("nmdev_url", selectedJar==null?NM_URL:"local-file", "nmdev_sha256", selected.sha256(), "nmdev_checksum_source", selectedJar==null?"https://github.com/nmltd/maven-packages/releases/download/nmdev-1.2.10-validated/SHA256SUMS":"computed from selected JAR", "nmdev_original_filename",selectedJar==null?"nmdev-1.2.10.jar":selected.path().getFileName().toString(), "nmdev_runtime_filename",NmdevInput.RUNTIME_NAME, "nmdev_version",selected.version(), "public_trial_url", LICENSE_URL, "parallelcolt_source_url", COLT_URL, "parallelcolt_source_sha256", COLT_SHA, "parallelcolt_binary_is_locally_built", true)); return hashes; } diff --git a/benchmark/launcher/src/main/java/dev/nm/benchmark/launcher/NmdevInput.java b/benchmark/launcher/src/main/java/dev/nm/benchmark/launcher/NmdevInput.java new file mode 100644 index 0000000..2c1dd3f --- /dev/null +++ b/benchmark/launcher/src/main/java/dev/nm/benchmark/launcher/NmdevInput.java @@ -0,0 +1,52 @@ +package dev.nm.benchmark.launcher; + +import java.io.IOException; +import java.nio.file.*; +import java.util.Properties; +import java.util.jar.JarFile; + +/** A selected binary is identified by its bytes, independently of its filename. */ +record NmdevInput(Path path, String sha256, String version) { + static final String RUNTIME_NAME = "nmdev-selected.jar"; + static NmdevInput open(Path source) throws IOException { + Path path=source.toAbsolutePath().normalize(); + if(!Files.isRegularFile(path)) throw new IOException("NMDEV JAR does not exist: "+path); + String version=""; + try(JarFile jar=new JarFile(path.toFile())) { + if(jar.getJarEntry("dev/nm/algebra/linear/matrix/doubles/matrixtype/dense/DenseMatrix.class")==null) + throw new IOException("Selected JAR does not contain NMDEV DenseMatrix: "+path); + var entry=jar.getJarEntry("META-INF/maven/dev.nm/nmdev/pom.properties"); + if(entry!=null) { + Properties properties=new Properties(); + try(var input=jar.getInputStream(entry)) {properties.load(input);} + version=properties.getProperty("version",""); + } + if(version.isBlank() && jar.getManifest()!=null) + version=jar.getManifest().getMainAttributes().getValue("Implementation-Version"); + } + return new NmdevInput(path,Storage.sha(path),version==null?"":version); + } + String label() {return version.isBlank()?"NM Dev (selected JAR; SHA-256 "+sha256+")":"NM Dev "+version;} + static void requireCompatibleRun(Path output,String sha256) throws IOException { + Path request=output.resolve("request.json"); + if(Files.exists(request)) { + var artifacts=Storage.read(request).getAsJsonObject().getAsJsonObject("artifacts"); + if(artifacts==null || !artifacts.has(RUNTIME_NAME) || !sha256.equals(artifacts.get(RUNTIME_NAME).getAsString())) + throw new IOException("NMDEV JAR differs from this run. Use a new --output directory; saved results were preserved."); + } + } + void install(Path destination) throws IOException { + Files.createDirectories(destination.getParent()); + // One private, fixed alias prevents an old version sorting ahead on the classpath. + try(var files=Files.list(destination.getParent())) { + if(files.anyMatch(p->p.getFileName().toString().startsWith("nmdev-") && p.toString().endsWith(".jar") && !p.equals(destination))) + throw new IOException("Old NMDEV JARs exist in the runtime cache. Use a new --output directory."); + } + if(!Files.exists(destination) || !Files.isSameFile(path,destination)) { + Path temporary=destination.resolveSibling(destination.getFileName()+".copy"); + Files.copy(path,temporary,StandardCopyOption.REPLACE_EXISTING); + if(!sha256.equals(Storage.sha(temporary))) {Files.deleteIfExists(temporary);throw new IOException("Selected NMDEV JAR changed while copying");} + Storage.move(temporary,destination); + } else if(!sha256.equals(Storage.sha(destination))) throw new IOException("Selected NMDEV JAR changed while preparing the run"); + } +} diff --git a/benchmark/launcher/src/test/java/dev/nm/benchmark/launcher/NmdevInputTest.java b/benchmark/launcher/src/test/java/dev/nm/benchmark/launcher/NmdevInputTest.java new file mode 100644 index 0000000..5db2e2b --- /dev/null +++ b/benchmark/launcher/src/test/java/dev/nm/benchmark/launcher/NmdevInputTest.java @@ -0,0 +1,51 @@ +package dev.nm.benchmark.launcher; + +import java.nio.file.*; +import java.util.Map; +import java.util.jar.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; +import static org.junit.jupiter.api.Assertions.*; + +class NmdevInputTest { + @TempDir Path temporary; + Path jar(String name,String version,String bytes) throws Exception { + Path path=temporary.resolve(name); + try(var jar=new JarOutputStream(Files.newOutputStream(path))) { + jar.putNextEntry(new JarEntry("dev/nm/algebra/linear/matrix/doubles/matrixtype/dense/DenseMatrix.class")); + jar.write(bytes.getBytes(java.nio.charset.StandardCharsets.UTF_8));jar.closeEntry(); + jar.putNextEntry(new JarEntry("META-INF/maven/dev.nm/nmdev/pom.properties")); + jar.write(("version="+version+"\n").getBytes(java.nio.charset.StandardCharsets.UTF_8));jar.closeEntry(); + } + return path; + } + @Test void acceptsArbitraryFilenameAndCopiesTheExactSelectedBytes() throws Exception { + var selected=NmdevInput.open(jar("my latest binary.jar","1.2.10","test bytes")); + Path runtime=temporary.resolve("output/.runtime/lib/nmdev-selected.jar"); + selected.install(runtime); + assertEquals(Storage.sha(selected.path()),Storage.sha(runtime)); + assertEquals("NM Dev 1.2.10",selected.label()); + selected.install(runtime); // Resume with the same bytes is idempotent. + NmdevInput.open(runtime).install(runtime); // The caller may select the cached file itself. + } + @Test void rejectsAChangedBinaryBeforeTouchingAnExistingRun() throws Exception { + var first=NmdevInput.open(jar("old.jar","1.2.9","original")); + var next=NmdevInput.open(jar("new.jar","1.2.10","changed")); + Path output=temporary.resolve("saved");Files.createDirectories(output); + Storage.json(output.resolve("request.json"),Map.of("artifacts",Map.of(NmdevInput.RUNTIME_NAME,first.sha256()))); + byte[] saved=Files.readAllBytes(output.resolve("request.json")); + NmdevInput.requireCompatibleRun(output,first.sha256()); + assertThrows(java.io.IOException.class,()->NmdevInput.requireCompatibleRun(output,next.sha256())); + assertArrayEquals(saved,Files.readAllBytes(output.resolve("request.json"))); + } + @Test void refusesInvalidOrMissingInputAndOldShadowingJars() throws Exception { + Path wrong=temporary.resolve("not-a-jar.jar");Files.writeString(wrong,"invalid"); + assertThrows(java.io.IOException.class,()->NmdevInput.open(wrong)); + assertThrows(java.io.IOException.class,()->NmdevInput.open(temporary.resolve("missing.jar"))); + var selected=NmdevInput.open(jar("selected.jar","1.2.10","valid selection")); + Path lib=temporary.resolve("lib");Files.createDirectories(lib); + Files.copy(selected.path(),lib.resolve("nmdev-1.2.9.jar")); + assertThrows(java.io.IOException.class,()->selected.install(lib.resolve(NmdevInput.RUNTIME_NAME))); + assertFalse(Files.exists(lib.resolve(NmdevInput.RUNTIME_NAME))); + } +} diff --git a/benchmark/pom.xml b/benchmark/pom.xml index 63217dd..f16abff 100644 --- a/benchmark/pom.xml +++ b/benchmark/pom.xml @@ -1,6 +1,6 @@ 4.0.0 - dev.nmnmdev-benchmark1.2.0 + dev.nmnmdev-benchmark1.3.0 NM Dev unattended benchmark application 17UTF-8