Skip to content

Commit dd6db0e

Browse files
Rename to AGENTS.md and address review feedback
Co-authored-by: saulshanabrook <1186124+saulshanabrook@users.noreply.github.com>
1 parent bff5813 commit dd6db0e

File tree

1 file changed

+48
-45
lines changed

1 file changed

+48
-45
lines changed
Lines changed: 48 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# GitHub Copilot Instructions for egglog-python
1+
# Agent Instructions for egglog-python
2+
3+
This file provides instructions for AI coding agents (including GitHub Copilot) working on this repository.
24

35
## Project Overview
46

@@ -22,17 +24,14 @@ This repository provides Python bindings for the Rust library `egglog`, enabling
2224

2325
### Prerequisites
2426
- **uv** - Package manager (https://github.com/astral-sh/uv)
25-
- **Rust toolchain** - Version 1.89.0 (specified in rust-toolchain.toml)
26-
- **Python** - 3.10+ (see .python-version)
27+
- **Rust toolchain** - See rust-toolchain.toml for version
28+
- **Python** - See .python-version for version
2729

2830
### Common Commands
2931

3032
```bash
31-
# Install dependencies (for development)
32-
uv sync --extra dev --locked
33-
34-
# Install dependencies (for testing)
35-
uv sync --extra test --locked
33+
# Install dependencies
34+
uv sync --all-extras
3635

3736
# Run tests
3837
uv run pytest --benchmark-disable -vvv --durations=10
@@ -91,7 +90,7 @@ See `pyproject.toml` for complete Ruff configuration.
9190
- **FFI**: Uses PyO3 for Python bindings
9291
- **Main library**: Uses egglog from git (saulshanabrook/egg-smol, clone-cost branch)
9392

94-
### File Organization
93+
### Rust File Organization
9594
- `src/lib.rs` - Main library entry point
9695
- `src/egraph.rs` - E-graph implementation
9796
- `src/conversions.rs` - Type conversions between Python and Rust
@@ -102,6 +101,31 @@ See `pyproject.toml` for complete Ruff configuration.
102101
- `src/termdag.rs` - Term DAG operations
103102
- `src/utils.rs` - Utility functions
104103

104+
### Python File Organization
105+
106+
#### Public Interface
107+
All public Python APIs are exported from the top-level `egglog` module. Anything that is public should be exported in `python/egglog/__init__.py` at the top level.
108+
109+
#### Lower-Level Bindings
110+
The `egglog.bindings` module provides lower-level access to the Rust implementation for advanced use cases.
111+
112+
#### Core Python Files
113+
- `python/egglog/__init__.py` - Top-level module exports, defines the public API
114+
- `python/egglog/egraph.py` - Main EGraph class and e-graph management
115+
- `python/egglog/egraph_state.py` - E-graph state and execution management
116+
- `python/egglog/runtime.py` - Runtime system for expression evaluation and method definitions
117+
- `python/egglog/builtins.py` - Built-in types (i64, f64, String, Vec, etc.) and operations
118+
- `python/egglog/declarations.py` - Class, function, and method declaration decorators
119+
- `python/egglog/conversion.py` - Type conversion between Python and egglog types
120+
- `python/egglog/pretty.py` - Pretty printing for expressions and e-graph visualization
121+
- `python/egglog/deconstruct.py` - Deconstruction of Python values into egglog expressions
122+
- `python/egglog/thunk.py` - Lazy evaluation support
123+
- `python/egglog/type_constraint_solver.py` - Type inference and constraint solving
124+
- `python/egglog/config.py` - Configuration settings
125+
- `python/egglog/ipython_magic.py` - IPython/Jupyter integration
126+
- `python/egglog/visualizer_widget.py` - Interactive visualization widget
127+
- `python/egglog/version_compat.py` - Python version compatibility utilities
128+
105129
## Code Style Preferences
106130

107131
1. **Imports**: Follow Ruff's import sorting
@@ -111,30 +135,6 @@ See `pyproject.toml` for complete Ruff configuration.
111135
3. **Comments**: Use clear, explanatory comments for complex logic
112136
4. **Documentation**: Keep docs synchronized with code changes
113137

114-
## Pre-commit Hooks
115-
116-
The repository uses pre-commit with:
117-
- `ruff-check` with auto-fix
118-
- `ruff-format` for formatting
119-
- `uv-lock` to keep lockfile updated
120-
121-
Run `pre-commit install` to enable automatic checking.
122-
123-
## Dependencies
124-
125-
### Python Dependencies
126-
- **Core**: typing-extensions, black, graphviz, anywidget
127-
- **Array support**: scikit-learn, array_api_compat, numba, numpy>2
128-
- **Dev tools**: ruff, pre-commit, mypy, jupyterlab
129-
- **Testing**: pytest, pytest-benchmark, pytest-codspeed, pytest-xdist, syrupy (snapshot testing)
130-
- **Docs**: sphinx and related packages
131-
132-
### Rust Dependencies
133-
- **PyO3**: Python bindings framework
134-
- **egglog**: Core e-graph library
135-
- **egraph-serialize**: Serialization support
136-
- **serde_json**: JSON handling
137-
138138
## Contributing Guidelines
139139

140140
When making changes:
@@ -144,15 +144,27 @@ When making changes:
144144
4. Build documentation if changing public APIs
145145
5. Follow existing code patterns and style
146146
6. Keep changes minimal and focused
147+
7. Add a changelog entry in `docs/changelog.md` under the UNRELEASED section
147148

148149
## Common Patterns
149150

150151
### Python API Design
151-
- Use `@egraph.class_` decorator for e-graph classes
152-
- Use `@egraph.function` for functions
153-
- Use `@egraph.method` for methods
152+
- Define e-graph classes by inheriting from `egglog.Expr`
153+
- Use `@egraph.function` decorator for functions
154+
- Use `@egraph.method` decorator for methods
154155
- Leverage type annotations for better IDE support
155156

157+
### Working with Values
158+
- Use `get_literal_value(expr)` or the `.value` property to get Python values from primitives
159+
- Use pattern matching with `match`/`case` for destructuring egglog primitives
160+
- Use `get_callable_fn(expr)` to get the underlying Python function from a callable expression
161+
- Use `get_callable_args(expr)` to get arguments to a callable
162+
163+
### Parallelism
164+
- The underlying Rust library uses Rayon for parallelism
165+
- Control worker thread count via `RAYON_NUM_THREADS` environment variable
166+
- Defaults to single thread if not set
167+
156168
### Rust-Python Integration
157169
- Use PyO3's `#[pyclass]` and `#[pymethods]` macros
158170
- Handle errors with appropriate Python exceptions
@@ -180,12 +192,3 @@ Documentation is built with Sphinx:
180192
- The library uses Rust for performance-critical operations
181193
- Benchmarking is done via CodSpeed for continuous performance monitoring
182194
- Profile with release builds (`cargo build --release`) when needed
183-
184-
## Continuous Integration
185-
186-
GitHub Actions workflows in `.github/workflows/`:
187-
- `CI.yml` - Main testing, type checking, benchmarks, and docs
188-
- `version.yml` - Version management
189-
- `update-changelog.yml` - Changelog automation
190-
191-
Tests run on Python 3.10, 3.11, 3.12, and 3.13.

0 commit comments

Comments
 (0)