Skip to content

Refactor n memory

Refactor n memory #318

Workflow file for this run

name: Python test / linting
env:
TRIGGER_ON_PR_PUSH: true # Set to true to enable triggers on PR pushes
RUSTFLAGS: -C debuginfo=0
RUST_BACKTRACE: 1
PYTHONUTF8: 1
on:
push:
branches: [ "master", "development", "dev" ]
# # Comment out paths to force run on all pushes
# paths:
# - 'python/**'
# - '.github/workflows/python-test.yml'
# - '.typos.toml'
# - 'ruff.toml'
# - '.pre-commit-config.yaml'
pull_request:
branches: [ "master", "development", "dev" ]
# # Comment out paths to force run on all PRs
# paths:
# - 'python/**'
# - '.github/workflows/python-test.yml'
# - '.typos.toml'
# - 'ruff.toml'
# - '.pre-commit-config.yaml'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
defaults:
run:
shell: bash
jobs:
python-test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
python-version: ["3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install the latest version of uv
uses: astral-sh/setup-uv@v4
with:
enable-cache: true
- name: Set up Rust
run: rustup show
- name: Cache Rust
uses: Swatinem/rust-cache@v2
with:
workspaces: python/pecos-rslib
- name: Install LLVM
uses: KyleMayes/install-llvm-action@v2
with:
version: "14.0"
env: True
- name: Configure LLVM
shell: bash
run: |
echo "LLVM_SYS_140_PREFIX=$LLVM_PATH" >> "$GITHUB_ENV"
# Test LLVM installation
if [[ "${{ runner.os }}" == "Windows" ]]; then
# On Windows with bash, we need to convert Windows paths to Unix paths
LLVM_CONFIG="$(cygpath -u "$LLVM_PATH")/bin/llvm-config.exe"
if [[ -f "$LLVM_CONFIG" ]]; then
"$LLVM_CONFIG" --version
else
echo "Warning: llvm-config.exe not found at $LLVM_CONFIG"
ls -la "$(cygpath -u "$LLVM_PATH")/bin/" || true
fi
else
"$LLVM_PATH/bin/llvm-config" --version
fi
- name: Set UV_PYTHON environment variable
run: |
# Get the exact Python path from setup-python
if [[ "${{ runner.os }}" == "Windows" ]]; then
# On Windows, we need to use the Windows-style path
PYTHON_PATH=$(python -c "import sys; print(sys.executable)")
else
PYTHON_PATH=$(which python)
fi
echo "Python from setup-python: $PYTHON_PATH"
python --version
# Export UV_PYTHON for all subsequent steps
echo "UV_PYTHON=$PYTHON_PATH" >> "$GITHUB_ENV"
- name: Create virtual environment
run: |
# Create venv using the correct Python version from setup-python
uv venv --python "$UV_PYTHON"
# Verify the venv is using the correct Python version
echo "Python in venv:"
source .venv/bin/activate
python --version
# Verify version matches what we expect
VENV_PYTHON_VERSION=$(python -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')")
if [[ "$VENV_PYTHON_VERSION" != "${{ matrix.python-version }}" ]]; then
echo "ERROR: Python version mismatch!"
echo "Expected: ${{ matrix.python-version }}"
echo "Got: $VENV_PYTHON_VERSION"
exit 1
fi
- name: Fix SQLite for macOS Python 3.13
if: ${{ matrix.os == 'macOS-latest' && matrix.python-version == '3.13' }}
run: |
# For Python 3.13 on macOS, we need to handle SQLite differently
# Install the latest SQLite via Homebrew
brew install sqlite3
# Save current compiler settings and use system compiler
OLD_CC="$CC"
OLD_CXX="$CXX"
# Use the system clang (not the LLVM one)
export CC=/usr/bin/clang
export CXX=/usr/bin/clang++
# Set environment variables to use Homebrew's SQLite
export LDFLAGS="-L$(brew --prefix sqlite3)/lib"
export CPPFLAGS="-I$(brew --prefix sqlite3)/include"
# Build pysqlite3 from source linking against Homebrew's SQLite
uv pip install --force-reinstall --no-binary :all: pysqlite3
# Restore compiler settings
export CC="$OLD_CC"
export CXX="$OLD_CXX"
# Create a sitecustomize.py to patch sqlite3 imports
SITE_PACKAGES=$(uv run python -c "import site; print(site.getsitepackages()[0])")
echo "import sys" > "$SITE_PACKAGES/sitecustomize.py"
echo "try:" >> "$SITE_PACKAGES/sitecustomize.py"
echo " import pysqlite3" >> "$SITE_PACKAGES/sitecustomize.py"
echo " sys.modules['sqlite3'] = pysqlite3" >> "$SITE_PACKAGES/sitecustomize.py"
echo " sys.modules['sqlite3.dbapi2'] = pysqlite3.dbapi2" >> "$SITE_PACKAGES/sitecustomize.py"
echo "except ImportError:" >> "$SITE_PACKAGES/sitecustomize.py"
echo " pass" >> "$SITE_PACKAGES/sitecustomize.py"
- name: Build PECOS
run: |
# Use the Makefile to build everything, respecting existing venv
UV_PYTHON="$UV_PYTHON" make build
- name: Run pre-commit checks
run: uv run pre-commit run --all-files --show-diff-on-failure
- name: Debug environment
run: |
echo "=== Environment Debug ==="
echo "Current directory: $(pwd)"
echo "Python executable: $(which python)"
echo "UV Python: $(uv run which python)"
echo "=== Installed packages ==="
uv pip list | grep -E "(numpy|scipy|networkx|matplotlib|phir|pecos|quantum)" || echo "No matching packages found"
echo "=== PYTHONPATH ==="
export PYTHONPATH="$(pwd)/python/quantum-pecos/src:$(pwd)/python/pecos-rslib/src:${PYTHONPATH}"
echo "PYTHONPATH=$PYTHONPATH"
echo "=== Test import ==="
uv run python -c "import sys; print('Python paths:'); print('\n'.join(sys.path))"
uv run python -c "import numpy; print('numpy imported successfully')" || echo "Failed to import numpy"
uv run python -c "import networkx; print('networkx imported successfully')" || echo "Failed to import networkx"
uv run python -c "import pecos; print('pecos imported successfully')" || echo "Failed to import pecos"
- name: Run standard tests
run: |
# Use the Makefile to run standard Python tests (now includes PYTHONPATH)
make pytest
- name: Run optional dependency tests
run: |
# Use the Makefile to run optional dependency tests (now includes PYTHONPATH)
make pytest-dep