name: Rust
on:
  push:
    branches: ["main"]
    paths-ignore:
      - "README.md"
      - "cla.md"
  pull_request:
    branches: ["main"]
    paths-ignore:
      - "README.md"
      - "cla.md"

concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: true

env:
  CARGO_TERM_COLOR: always

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: nightly-2023-08-24
          override: true
          components: rustfmt, clippy
      - name: Build
        run: cargo build --verbose

  docs:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: nightly-2023-08-24
          override: true
          components: rustfmt, clippy
      - name: Docs
        run: cargo doc --verbose

  library-tests:
    runs-on: ubuntu-latest-32-cores
    steps:
      - uses: actions/checkout@v4
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: nightly-2023-08-24
          override: true
          components: rustfmt, clippy
      - uses: baptiste0928/cargo-install@v1
        with:
          crate: cargo-nextest
          locked: true
      - name: Doc tests
        # nextest doesn't support --doc tests
        run: cargo test --doc --verbose
      - name: Library tests
        run: cargo nextest run --lib --verbose
      - name: Library tests (original lookup)
        run: cargo nextest run --lib --verbose --no-default-features --features ezkl

  ultra-overflow-tests-gpu:
    runs-on: GPU
    env:
      ENABLE_ICICLE_GPU: true
    steps:
      - uses: actions/checkout@v4
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: nightly-2023-08-24
          override: true
          components: rustfmt, clippy
      - uses: baptiste0928/cargo-install@v1
        with:
          crate: cargo-nextest
          locked: true
      - uses: mwilliamson/setup-wasmtime-action@v2
        with:
          wasmtime-version: "3.0.1"
      - name: Install wasm32-wasi
        run: rustup target add wasm32-wasi
      - name: Install cargo-wasi
        run: cargo install cargo-wasi
      # - name: Matmul overflow (wasi)
      #   run: cargo wasi test matmul_col_ultra_overflow -- --include-ignored --nocapture
      # - name: Conv overflow (wasi)
      #   run: cargo wasi test conv_col_ultra_overflow -- --include-ignored --nocapture
      - name: lookup overflow
        run: cargo nextest run  --release lookup_ultra_overflow --no-capture --features icicle -- --include-ignored
      - name: Matmul overflow
        run: RUST_LOG=debug cargo nextest run matmul_col_ultra_overflow --no-capture --features icicle -- --include-ignored
      - name: Conv overflow
        run: RUST_LOG=debug cargo nextest run conv_col_ultra_overflow --no-capture --features icicle -- --include-ignored
      - name: Conv + relu overflow
        run: cargo nextest run  --release conv_relu_col_ultra_overflow --no-capture --features icicle -- --include-ignored

  ultra-overflow-tests_og-lookup:
    runs-on: non-gpu
    steps:
      - uses: actions/checkout@v4
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: nightly-2023-08-24
          override: true
          components: rustfmt, clippy
      - uses: baptiste0928/cargo-install@v1
        with:
          crate: cargo-nextest
          locked: true
      - uses: mwilliamson/setup-wasmtime-action@v2
        with:
          wasmtime-version: "3.0.1"
      - name: Install wasm32-wasi
        run: rustup target add wasm32-wasi
      - name: Install cargo-wasi
        run: cargo install cargo-wasi
      # - name: Matmul overflow (wasi)
      #   run: cargo wasi test matmul_col_ultra_overflow -- --include-ignored --nocapture
      # - name: Conv overflow (wasi)
      #   run: cargo wasi test conv_col_ultra_overflow -- --include-ignored --nocapture
      - name: lookup overflow
        run: cargo nextest run  --release lookup_ultra_overflow --no-capture --no-default-features --features ezkl -- --include-ignored
      - name: Matmul overflow
        run: RUST_LOG=debug cargo nextest run matmul_col_ultra_overflow --no-capture --no-default-features --features ezkl -- --include-ignored
      - name: Conv overflow
        run: RUST_LOG=debug cargo nextest run conv_col_ultra_overflow --no-capture --no-default-features --features ezkl -- --include-ignored
      - name: Conv + relu overflow
        run: cargo nextest run  --release conv_relu_col_ultra_overflow --no-capture --no-default-features --features ezkl -- --include-ignored

  ultra-overflow-tests:
    runs-on: non-gpu
    steps:
      - uses: actions/checkout@v4
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: nightly-2023-08-24
          override: true
          components: rustfmt, clippy
      - uses: baptiste0928/cargo-install@v1
        with:
          crate: cargo-nextest
          locked: true
      - uses: mwilliamson/setup-wasmtime-action@v2
        with:
          wasmtime-version: "3.0.1"
      - name: Install wasm32-wasi
        run: rustup target add wasm32-wasi
      - name: Install cargo-wasi
        run: cargo install cargo-wasi
      # - name: Matmul overflow (wasi)
      #   run: cargo wasi test matmul_col_ultra_overflow -- --include-ignored --nocapture
      # - name: Conv overflow (wasi)
      #   run: cargo wasi test conv_col_ultra_overflow -- --include-ignored --nocapture
      - name: lookup overflow
        run: cargo nextest run  --release lookup_ultra_overflow --no-capture -- --include-ignored
      - name: Matmul overflow
        run: RUST_LOG=debug cargo nextest run matmul_col_ultra_overflow --no-capture -- --include-ignored
      - name: Conv overflow
        run: RUST_LOG=debug cargo nextest run conv_col_ultra_overflow --no-capture -- --include-ignored
      - name: Conv + relu overflow
        run: cargo nextest run  --release conv_relu_col_ultra_overflow --no-capture -- --include-ignored

  model-serialization:
    runs-on: ubuntu-latest-16-cores
    steps:
      - uses: actions/checkout@v4
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: nightly-2023-08-24
          override: true
          components: rustfmt, clippy
      - uses: baptiste0928/cargo-install@v1
        with:
          crate: cargo-nextest
          locked: true
      - name: Model serialization different binary ID
        run: cargo nextest run native_tests::tests::model_serialization_different_binaries_  --test-threads 1

  wasm32-tests:
    runs-on: ubuntu-latest
    # needs: [build,  library-tests, docs]
    steps:
      - uses: actions/checkout@v4
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: nightly-2023-08-24
          override: true
          components: rustfmt, clippy
      - uses: jetli/wasm-pack-action@v0.4.0
      - uses: nanasess/setup-chromedriver@v2
        # with:
        #   chromedriver-version: "115.0.5790.102"
      - name: Install wasm32-unknown-unknown
        run: rustup target add wasm32-unknown-unknown
      - name: Install wasm runner
        run: cargo install wasm-server-runner
      - name: Add rust-src
        run: rustup component add rust-src --toolchain nightly-2023-08-24-x86_64-unknown-linux-gnu
      - name: Run wasm verifier tests
        # on mac:
        #   AR=/opt/homebrew/opt/llvm/bin/llvm-ar CC=/opt/homebrew/opt/llvm/bin/clang wasm-pack test --firefox --headless -- -Z build-std="panic_abort,std" --features web
        run: wasm-pack test --chrome --headless -- -Z build-std="panic_abort,std" --features web

  tutorial:
    runs-on: ubuntu-latest
    needs: [build, library-tests, docs]
    steps:
      - uses: actions/checkout@v4
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: nightly-2023-08-24
          override: true
          components: rustfmt, clippy
      - uses: baptiste0928/cargo-install@v1
        with:
          crate: cargo-nextest
          locked: true
      - name: Circuit Render
        run: cargo nextest run --release --verbose tests::tutorial_

  mock-proving-tests:
    runs-on: non-gpu
    # needs: [build,  library-tests, docs]
    steps:
      - uses: actions/checkout@v4
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: nightly-2023-08-24
          override: true
          components: rustfmt, clippy
      - uses: baptiste0928/cargo-install@v1
        with:
          crate: cargo-nextest
          locked: true
      - name: public outputs + batch size == 10
        run: cargo nextest run --release --verbose tests::mock_large_batch_public_outputs_ --test-threads 32
      - name: kzg inputs
        run: cargo nextest run --release --verbose tests::mock_kzg_input_::t  --test-threads 32
      - name: kzg params
        run: cargo nextest run --release --verbose tests::mock_kzg_params_::t  --test-threads 32
      - name: kzg outputs
        run: cargo nextest run --release --verbose tests::mock_kzg_output_::t  --test-threads 32
      - name: kzg inputs + params + outputs
        run: cargo nextest run --release --verbose tests::mock_kzg_all_::t  --test-threads 32
      - name: Mock fixed inputs
        run: cargo nextest run --release --verbose tests::mock_fixed_inputs_ --test-threads 32
      - name: Mock fixed outputs
        run: cargo nextest run --release --verbose tests::mock_fixed_outputs --test-threads 32
      - name: Mock accuracy calibration
        run: cargo nextest run --release --verbose tests::mock_accuracy_cal_tests::a
      - name: hashed inputs
        run: cargo nextest run --release --verbose tests::mock_hashed_input_::t  --test-threads 32
      - name: hashed params
        run: cargo nextest run --release --verbose tests::mock_hashed_params_::t  --test-threads 32
      - name: hashed outputs
        run: cargo nextest run --release --verbose tests::mock_hashed_output_::t  --test-threads 32
      - name: hashed inputs + params + outputs
        run: cargo nextest run --release --verbose tests::mock_hashed_all_::t  --test-threads 32
      - name: hashed inputs + fixed params
        run: cargo nextest run --release --verbose tests::mock_hashed_output_fixed_params_::t  --test-threads 32
      - name: MNIST Gan Mock
        run: cargo nextest run --release --verbose tests::large_mock_::large_tests_4_expects -- --include-ignored
      - name: NanoGPT Mock
        run: cargo nextest run --release --verbose tests::large_mock_::large_tests_1_expects -- --include-ignored
      - name: Self Attention Mock
        run: cargo nextest run --release --verbose tests::large_mock_::large_tests_0_expects -- --include-ignored
      - name: Multihead Attention Mock
        run: cargo nextest run --release --verbose tests::large_mock_::large_tests_2_expects -- --include-ignored
      - name: public outputs
        run: cargo nextest run --release --verbose tests::mock_public_outputs_ --test-threads 32
      - name: public inputs
        run: cargo nextest run --release --verbose tests::mock_public_inputs_ --test-threads 32
      - name: fixed params
        run: cargo nextest run --release --verbose tests::mock_fixed_params_ --test-threads 32

  prove-and-verify-evm-tests:
    runs-on: non-gpu
    needs: [build, library-tests]
    steps:
      - uses: actions/checkout@v4
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: nightly-2023-08-24
          override: true
          components: rustfmt, clippy
      - uses: baptiste0928/cargo-install@v1
        with:
          crate: cargo-nextest
          locked: true
      - uses: actions/checkout@v3
      - name: Use pnpm 8
        uses: pnpm/action-setup@v2
        with:
          version: 8
      - name: Use Node.js 18.12.1
        uses: actions/setup-node@v3
        with:
          node-version: "18.12.1"
          cache: "pnpm"
      - name: Install dependencies
        run: |
          pnpm install --no-frozen-lockfile
        env:
          CI: false
          NODE_ENV: development
      - name: Install solc
        run: (hash svm 2>/dev/null || cargo install svm-rs) && svm install 0.8.20 && solc --version
      - name: Install Anvil
        run: cargo install --git https://github.com/foundry-rs/foundry --rev 95a93cd397f25f3f8d49d2851eb52bc2d52dd983 --profile local --locked anvil --force
      - name: KZG prove and verify tests (EVM + kzg all)
        run: cargo nextest run --release --verbose tests_evm::kzg_evm_kzg_all_prove_and_verify --test-threads 1
      - name: KZG prove and verify tests (EVM + kzg inputs)
        run: cargo nextest run --release --verbose tests_evm::kzg_evm_kzg_input_prove_and_verify --test-threads 1
      - name: KZG prove and verify tests (EVM + kzg params)
        run: cargo nextest run --release --verbose tests_evm::kzg_evm_kzg_params_prove_and_verify --test-threads 1
      - name: KZG prove and verify tests (EVM + on chain inputs)
        run: cargo nextest run --release --verbose tests_evm::kzg_evm_on_chain_input_prove_and_verify --test-threads 1
      - name: KZG prove and verify tests (EVM + on chain outputs)
        run: cargo nextest run --release --verbose tests_evm::kzg_evm_on_chain_output_prove_and_verify --test-threads 1
      - name: KZG prove and verify tests (EVM + on chain inputs & outputs)
        run: cargo nextest run --release --verbose tests_evm::kzg_evm_on_chain_input_output_prove_and_verify --test-threads 1
      - name: KZG prove and verify tests (EVM + on chain inputs & outputs hashes)
        run: cargo nextest run --release --verbose tests_evm::kzg_evm_on_chain_input_output_hashed_prove_and_verify --test-threads 1
      - name: KZG prove and verify tests (EVM)
        run: cargo nextest run --release --verbose tests_evm::kzg_evm_prove_and_verify --test-threads 1
      - name: KZG prove and verify tests (EVM + hashed inputs)
        run: cargo nextest run --release --verbose tests_evm::kzg_evm_hashed_input_prove_and_verify --test-threads 1
      - name: KZG prove and verify tests (EVM + hashed params)
        run: cargo nextest run --release --verbose tests_evm::kzg_evm_hashed_params_prove_and_verify --test-threads 1
      - name: KZG prove and verify tests (EVM + hashed outputs)
        run: cargo nextest run --release --verbose tests_evm::kzg_evm_hashed_output_prove_and_verify --test-threads 1

  prove-and-verify-tests:
    runs-on: non-gpu
    needs: [build, library-tests]
    steps:
      - uses: actions/checkout@v4
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: nightly-2023-08-24
          override: true
          components: rustfmt, clippy
      - uses: jetli/wasm-pack-action@v0.4.0
      - name: Add wasm32-unknown-unknown target
        run: rustup target add wasm32-unknown-unknown

      - name: Install wasm-server-runner
        run: cargo install wasm-server-runner

      - name: Add rust-src
        run: rustup component add rust-src --toolchain nightly-2023-08-24-x86_64-unknown-linux-gnu
      - uses: actions/checkout@v3
      - name: Use pnpm 8
        uses: pnpm/action-setup@v2
        with:
          version: 8
      - name: Use Node.js 18.12.1
        uses: actions/setup-node@v3
        with:
          node-version: "18.12.1"
          cache: "pnpm"
      - name: Install dependencies
        run: |
          pnpm install --no-frozen-lockfile
        env:
          CI: false
          NODE_ENV: development
      - uses: baptiste0928/cargo-install@v1
        with:
          crate: cargo-nextest
          locked: true
      - name: Build wasm package for nodejs target.
        run: |
          wasm-pack build --release --target nodejs --out-dir ./tests/wasm/nodejs . -- -Z build-std="panic_abort,std"
      - name: Replace memory definition in nodejs
        run: |
          sed -i "3s|.*|imports['env'] = {memory: new WebAssembly.Memory({initial:20,maximum:65536,shared:true})}|" tests/wasm/nodejs/ezkl.js
      - name: KZG prove and verify tests (public outputs + column overflow)
        run: cargo nextest run --release --verbose tests::kzg_prove_and_verify_with_overflow_::w
      - name: KZG prove and verify tests single inner col
        run: cargo nextest run --release --verbose tests::kzg_prove_and_verify_single_col
      - name: KZG prove and verify tests triple inner col
        run: cargo nextest run --release --verbose tests::kzg_prove_and_verify_triple_col
      - name: KZG prove and verify tests quadruple inner col
        run: cargo nextest run --release --verbose tests::kzg_prove_and_verify_quadruple_col
      - name: KZG prove and verify tests octuple inner col
        run: cargo nextest run --release --verbose tests::kzg_prove_and_verify_octuple_col --test-threads 8
      - name: KZG prove and verify tests (kzg outputs)
        run: cargo nextest run --release --verbose tests::kzg_prove_and_verify_kzg_output
      - name: KZG prove and verify tests (public outputs + fixed params + column overflow)
        run: cargo nextest run --release --verbose tests::kzg_prove_and_verify_with_overflow_fixed_params_
      - name: KZG prove and verify tests (public outputs)
        run: cargo nextest run --release --verbose tests::kzg_prove_and_verify_::t
      - name: KZG prove and verify tests (public outputs + column overflow)
        run: cargo nextest run --release --verbose tests::kzg_prove_and_verify_::t
      - name: KZG prove and verify tests (public inputs)
        run: cargo nextest run --release --verbose tests::kzg_prove_and_verify_public_input
      - name: KZG prove and verify tests (fixed params)
        run: cargo nextest run --release --verbose tests::kzg_prove_and_verify_fixed_params
      - name: KZG prove and verify tests (hashed outputs)
        run: cargo nextest run --release --verbose tests::kzg_prove_and_verify_hashed

  prove-and-verify-tests-gpu:
    runs-on: GPU
    env:
      ENABLE_ICICLE_GPU: true
    steps:
      - uses: actions/checkout@v4
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: nightly-2023-08-24
          override: true
          components: rustfmt, clippy
      - name: Add rust-src
        run: rustup component add rust-src --toolchain nightly-2023-08-24-x86_64-unknown-linux-gnu
      - uses: actions/checkout@v3
      - uses: baptiste0928/cargo-install@v1
        with:
          crate: cargo-nextest
          locked: true
      - name: KZG prove and verify tests (kzg outputs)
        run: cargo nextest run --release --verbose tests::kzg_prove_and_verify_kzg_output --features icicle --test-threads 2
      - name: KZG prove and verify tests (public outputs + column overflow)
        run: cargo nextest run --release --verbose tests::kzg_prove_and_verify_with_overflow_::w --features icicle  --test-threads 2
      - name: KZG prove and verify tests (public outputs + fixed params + column overflow)
        run: cargo nextest run --release --verbose tests::kzg_prove_and_verify_with_overflow_fixed_params_ --features icicle  --test-threads 2
      - name: KZG prove and verify tests (public outputs)
        run: cargo nextest run --release --verbose tests::kzg_prove_and_verify_::t --features icicle  --test-threads 2
      - name: KZG prove and verify tests (public outputs + column overflow)
        run: cargo nextest run --release --verbose tests::kzg_prove_and_verify_::t --features icicle  --test-threads 2
      - name: KZG prove and verify tests (public inputs)
        run: cargo nextest run --release --verbose tests::kzg_prove_and_verify_public_input --features icicle  --test-threads 2
      - name: KZG prove and verify tests (fixed params)
        run: cargo nextest run --release --verbose tests::kzg_prove_and_verify_fixed_params --features icicle  --test-threads 2
      - name: KZG prove and verify tests (hashed outputs)
        run: cargo nextest run --release --verbose tests::kzg_prove_and_verify_hashed --features icicle  --test-threads 2

  fuzz-tests:
    runs-on: ubuntu-latest-32-cores
    needs: [build, library-tests, python-tests]
    steps:
      - uses: actions/checkout@v4
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: nightly-2023-08-24
          override: true
          components: rustfmt, clippy
      - uses: baptiste0928/cargo-install@v1
        with:
          crate: cargo-nextest
          locked: true
      - name: Install solc
        run: (hash svm 2>/dev/null || cargo install svm-rs) && svm install 0.8.20 && solc --version
      - name: Install Anvil
        run: cargo install --git https://github.com/foundry-rs/foundry --rev 95a93cd397f25f3f8d49d2851eb52bc2d52dd983 --profile local --locked anvil --force
      - name: fuzz tests (EVM)
        run: cargo nextest run --release --verbose tests_evm::kzg_evm_fuzz_ --test-threads 2
      # - name: fuzz tests
      #   run: cargo nextest run --release --verbose tests::kzg_fuzz_ --test-threads 6

  prove-and-verify-mock-aggr-tests:
    runs-on: self-hosted
    needs: [build, library-tests]
    steps:
      - uses: actions/checkout@v4
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: nightly-2023-08-24
          override: true
          components: rustfmt, clippy
      - uses: baptiste0928/cargo-install@v1
        with:
          crate: cargo-nextest
          locked: true
      - name: Mock aggr tests
        run: cargo nextest run --release --verbose tests_aggr::kzg_aggr_mock_prove_and_verify_  --test-threads 8

  prove-and-verify-aggr-tests-gpu:
    runs-on: GPU
    env:
      ENABLE_ICICLE_GPU: true
    steps:
      - uses: actions/checkout@v4
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: nightly-2023-08-24
          override: true
          components: rustfmt, clippy
      - uses: baptiste0928/cargo-install@v1
        with:
          crate: cargo-nextest
          locked: true
      - name: KZG )tests
        run: cargo nextest run --release --verbose tests_aggr::kzg_aggr_prove_and_verify_  --features icicle --test-threads 1 -- --include-ignored

  prove-and-verify-aggr-tests:
    runs-on: large-self-hosted
    needs: [build, library-tests, python-tests]
    steps:
      - uses: actions/checkout@v4
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: nightly-2023-08-24
          override: true
          components: rustfmt, clippy
      - uses: baptiste0928/cargo-install@v1
        with:
          crate: cargo-nextest
          locked: true
      - name: KZG )tests
        run: cargo nextest run --release --verbose tests_aggr::kzg_aggr_prove_and_verify_  --test-threads 8 -- --include-ignored

  prove-and-verify-aggr-evm-tests:
    runs-on: large-self-hosted
    needs: [build, library-tests, python-tests]
    steps:
      - uses: actions/checkout@v4
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: nightly-2023-08-24
          override: true
          components: rustfmt, clippy
      - uses: baptiste0928/cargo-install@v1
        with:
          crate: cargo-nextest
          locked: true
      - name: Install solc
        run: (hash svm 2>/dev/null || cargo install svm-rs) && svm install 0.8.20 && solc --version
      - name: Install Anvil
        run: cargo install --git https://github.com/foundry-rs/foundry --rev 95a93cd397f25f3f8d49d2851eb52bc2d52dd983 --profile local --locked anvil --force
      - name: KZG prove and verify aggr tests
        run: cargo nextest run  --release --verbose tests_evm::kzg_evm_aggr_prove_and_verify_::t --test-threads 4 -- --include-ignored

  examples:
    runs-on: ubuntu-latest-32-cores
    needs: [build, library-tests, docs]
    steps:
      - uses: actions/checkout@v4
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: nightly-2023-08-24
          override: true
          components: rustfmt, clippy
      - uses: baptiste0928/cargo-install@v1
        with:
          crate: cargo-nextest
          locked: true
      - name: Download MNIST
        run: sh data.sh
      - name: Examples
        run: cargo nextest run --release tests_examples

  python-tests:
    runs-on: non-gpu
    needs: [build, library-tests, docs]
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v4
        with:
          python-version: "3.7"
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: nightly-2023-08-24
          override: true
          components: rustfmt, clippy
      - name: Install solc
        run: (hash svm 2>/dev/null || cargo install svm-rs) && svm install 0.8.20 && solc --version
      - name: Setup Virtual Env and Install python dependencies
        run: python -m venv .env; source .env/bin/activate; pip install -r requirements.txt;
      - name: Install Anvil
        run: cargo install --git https://github.com/foundry-rs/foundry --rev 95a93cd397f25f3f8d49d2851eb52bc2d52dd983 --profile local --locked anvil --force
      - name: Build python ezkl
        run: source .env/bin/activate; maturin develop --features python-bindings --release
      - name: Run pytest
        run: source .env/bin/activate; pytest -vv

  accuracy-measurement-tests:
    runs-on: ubuntu-latest-32-cores
    # needs: [build, library-tests, docs]
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v4
        with:
          python-version: "3.7"
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: nightly-2023-08-24
          override: true
          components: rustfmt, clippy
      - uses: baptiste0928/cargo-install@v1
        with:
          crate: cargo-nextest
          locked: true
      - name: Setup Virtual Env and Install python dependencies
        run: python -m venv .env; source .env/bin/activate; pip install -r requirements.txt;
      - name: Build python ezkl
        run: source .env/bin/activate; maturin develop --features python-bindings --release
      - name: Public inputs
        run: source .env/bin/activate; cargo nextest run --release --verbose tests::accuracy_measurement_public_inputs_
      - name: fixed params
        run: source .env/bin/activate; cargo nextest run --release --verbose tests::accuracy_measurement_fixed_params_
      - name: Public outputs
        run: source .env/bin/activate; cargo nextest run --release --verbose tests::accuracy_measurement_public_outputs_
      - name: Public outputs + resources
        run: source .env/bin/activate; cargo nextest run --release --verbose tests::resources_accuracy_measurement_public_outputs_

  python-integration-tests:
    runs-on: large-self-hosted
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v4
        with:
          python-version: "3.9"
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: nightly-2023-08-24
          override: true
          components: rustfmt, clippy
      - uses: baptiste0928/cargo-install@v1
        with:
          crate: cargo-nextest
          locked: true
      - name: Install solc
        run: (hash svm 2>/dev/null || cargo install svm-rs) && svm install 0.8.20 && solc --version
      - name: Install Anvil
        run: cargo install --git https://github.com/foundry-rs/foundry --rev 95a93cd397f25f3f8d49d2851eb52bc2d52dd983 --profile local --locked anvil --force
      - name: Setup Virtual Env and Install python dependencies
        run: python -m venv .env; source .env/bin/activate; pip install -r requirements.txt;
      - name: Build python ezkl
        run: source .env/bin/activate; maturin develop --features python-bindings --release
      # - name: authenticate-kaggle-cli
      #   shell: bash
      #   env:
      #     KAGGLE_API_KEY: ${{ secrets.KAGGLE_API_KEY }}
      #   run: |
      #     mkdir /home/ubuntu/.kaggle
      #     # now dump the contents of the file into a file called kaggle.json
      #     echo $KAGGLE_API_KEY > /home/ubuntu/.kaggle/kaggle.json
      #     chmod 600 /home/ubuntu/.kaggle/kaggle.json
      - name: Voice tutorial
        run: source .env/bin/activate; cargo nextest run py_tests::tests::voice_
      - name: NBEATS tutorial
        run: source .env/bin/activate; cargo nextest run py_tests::tests::nbeats_
      - name: All notebooks
        run: source .env/bin/activate; cargo nextest run py_tests::tests::run_notebook_ --test-threads 1
      - name: Tictactoe tutorials
        run: source .env/bin/activate; cargo nextest run py_tests::tests::tictactoe_ --test-threads 1
      # - name: Postgres tutorials
      #   run: source .env/bin/activate; cargo nextest run py_tests::tests::postgres_ --test-threads 1
     
