From 4d64299b11f2976edf59946f685ea165c74aca34 Mon Sep 17 00:00:00 2001 From: Miles Date: Tue, 16 Apr 2024 07:35:52 -0400 Subject: [PATCH] [ITensors] `Observers.jl` package extension (#1381) --- .../comment_trigger_test_itensortdvp.yml | 77 ------------------- .github/workflows/test_itensortdvp_ubuntu.yml | 53 +++++++++++++ Project.toml | 3 + .../ITensorsObserversExt.jl | 11 +++ src/ITensorMPS/alternating_update.jl | 2 +- 5 files changed, 68 insertions(+), 78 deletions(-) delete mode 100644 .github/workflows/comment_trigger_test_itensortdvp.yml create mode 100644 .github/workflows/test_itensortdvp_ubuntu.yml create mode 100644 ext/ITensorsObserversExt/ITensorsObserversExt.jl diff --git a/.github/workflows/comment_trigger_test_itensortdvp.yml b/.github/workflows/comment_trigger_test_itensortdvp.yml deleted file mode 100644 index eb557bb55b..0000000000 --- a/.github/workflows/comment_trigger_test_itensortdvp.yml +++ /dev/null @@ -1,77 +0,0 @@ -name: Run ITensorTDVP tests from comment trigger - -# https://dev.to/zirkelc/trigger-github-workflow-for-comment-on-pull-request-45l2 - -on: - issue_comment: - types: [created] - -jobs: - deploy: - name: Deploy - if: github.event.issue.pull_request && contains(github.event.comment.body, '[test ITensorTDVP]') - runs-on: ${{ matrix.os }} - env: - JULIA_NUM_THREADS: ${{ matrix.threads }} - strategy: - matrix: - version: - - '1' - os: - - ubuntu-latest - threads: - - '2' - arch: - - x64 - steps: - - name: Get PR branch - uses: xt0rted/pull-request-comment-branch@v1 - id: comment-branch - - name: Set latest commit status as pending - uses: myrotvorets/set-commit-status-action@master - with: - sha: ${{ steps.comment-branch.outputs.head_sha }} - token: ${{ secrets.GITHUB_TOKEN }} - status: pending - - name: Checkout PR branch - uses: actions/checkout@v3 - with: - # https://github.com/actions/checkout/issues/331#issuecomment-1438220926 - ref: refs/pull/${{ github.event.issue.number }}/head - - name: Setup Node.js 16 - uses: actions/setup-node@v3 - with: - node-version: 16 - - uses: julia-actions/setup-julia@latest - with: - version: ${{ matrix.version }} - arch: ${{ matrix.arch }} - - name: Install Julia dependencies - shell: julia --project=monorepo {0} - run: | - using Pkg; - Pkg.add("ITensorTDVP"); - Pkg.test("ITensorTDVP"); - - name: Set latest commit status as ${{ job.status }} - uses: myrotvorets/set-commit-status-action@master - if: always() - with: - sha: ${{ steps.comment-branch.outputs.head_sha }} - token: ${{ secrets.GITHUB_TOKEN }} - status: ${{ job.status }} - - name: Add comment to PR - uses: actions/github-script@v6 - if: always() - with: - script: | - const name = '${{ github.workflow }}'; - const url = '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}'; - const success = '${{ job.status }}' === 'success'; - const body = `${name}: ${success ? 'succeeded ✅' : 'failed ❌'}\n${url}`; - - await github.rest.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: body - }) diff --git a/.github/workflows/test_itensortdvp_ubuntu.yml b/.github/workflows/test_itensortdvp_ubuntu.yml new file mode 100644 index 0000000000..0e8611ff44 --- /dev/null +++ b/.github/workflows/test_itensortdvp_ubuntu.yml @@ -0,0 +1,53 @@ +name: Run ITensorTDVP tests (Unbuntu) + +on: + push: + branches: + - main + tags: '*' + pull_request: + +jobs: + test: + name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ matrix.threads }} thread(s) + runs-on: ${{ matrix.os }} + env: + JULIA_NUM_THREADS: ${{ matrix.threads }} + strategy: + matrix: + version: + - '1.6' + - '1' + os: + - ubuntu-latest + threads: + - '2' + arch: + - x64 + exclude: + # MacOS not available on x86 + - {os: 'macOS-latest', arch: 'x86'} + steps: + - uses: actions/checkout@v2 + - uses: julia-actions/setup-julia@latest + with: + version: ${{ matrix.version }} + arch: ${{ matrix.arch }} + - name: Install Julia dependencies and run tests + shell: julia {0} + run: | + using Pkg; + try + Pkg.activate(temp=true); + Pkg.develop(path="./NDTensors"); + Pkg.develop(path="."); + Pkg.add("ITensorTDVP"); + Pkg.test("ITensorTDVP"); + catch err + err isa Pkg.Resolve.ResolverError || rethrow() + # If we can't resolve that means this is incompatible by SemVer and this is fine + # It means we marked this as a breaking change, so we don't need to worry about + # Mistakenly introducing a breaking change, as we have intentionally made one + @info "ITensorTDVP not compatible with this release. Skipping this test." exception=err + exit(0) # Exit immediately, as a success + end diff --git a/Project.toml b/Project.toml index 6acb6a706c..74cbcc273f 100644 --- a/Project.toml +++ b/Project.toml @@ -34,9 +34,11 @@ Zeros = "bd1ec220-6eb4-527a-9b49-e79c3db6233b" ZygoteRules = "700de1a5-db45-46bc-99cf-38207098b444" [weakdeps] +Observers = "338f10d5-c7f1-4033-a7d1-f9dec39bcaa0" VectorInterface = "409d34a3-91d5-4945-b6ec-7529ddf182d8" [extensions] +ITensorsObserversExt = "Observers" ITensorsVectorInterfaceExt = "VectorInterface" [compat] @@ -72,4 +74,5 @@ ZygoteRules = "0.2.2" julia = "1.6" [extras] +Observers = "338f10d5-c7f1-4033-a7d1-f9dec39bcaa0" VectorInterface = "409d34a3-91d5-4945-b6ec-7529ddf182d8" diff --git a/ext/ITensorsObserversExt/ITensorsObserversExt.jl b/ext/ITensorsObserversExt/ITensorsObserversExt.jl new file mode 100644 index 0000000000..f5829b99be --- /dev/null +++ b/ext/ITensorsObserversExt/ITensorsObserversExt.jl @@ -0,0 +1,11 @@ +module ITensorsObserversExt + +using Observers: Observers +using Observers.DataFrames: AbstractDataFrame +using ITensors.ITensorMPS: ITensorMPS + +function ITensorMPS.update_observer!(observer::AbstractDataFrame; kwargs...) + return Observers.update!(observer; kwargs...) +end + +end diff --git a/src/ITensorMPS/alternating_update.jl b/src/ITensorMPS/alternating_update.jl index 3770f8b86e..63c62154c6 100644 --- a/src/ITensorMPS/alternating_update.jl +++ b/src/ITensorMPS/alternating_update.jl @@ -98,7 +98,7 @@ function alternating_update( ) end current_time += time_step - update!(step_observer!; psi, sweep, outputlevel, current_time) + update_observer!(step_observer!; psi, sweep, outputlevel, current_time) if outputlevel >= 1 print("After sweep ", sweep, ":") print(" maxlinkdim=", maxlinkdim(psi))