# Automatically run the setup steps when they are changed to allow for easy validation, and
# allow manual testing through the repository's "Actions" tab
on:
workflow_dispatch:
push:
paths:
-.github/workflows/copilot-setup-steps.yml
pull_request:
paths:
-.github/workflows/copilot-setup-steps.yml
jobs:
# The job MUST be called `copilot-setup-steps` or it will not be picked up by Copilot.
copilot-setup-steps:
runs-on:ubuntu-latest
# Set the permissions to the lowest permissions possible needed for your steps.
# Copilot will be given its own token for its operations.
permissions:
# If you want to clone the repository as part of your setup steps, for example to install dependencies, you'll need the `contents: read` permission. If you don't clone the repository in your setup steps, Copilot will do this for you automatically after the steps complete.
contents:read
# You can define any steps you want, and they will run before the agent starts.
# If you do not check out your code, Copilot will do this for you.
- Use custom function mode `get_default_mode().excluding("fusion")` or skip tests in `FAST_COMPILE` if they are not directly relevant to the mode.
Alternative backends (JAX, NUMBA, ...) are optional. Use `pytest.importorskip` to fail gracefully.
### Pre-commit
```bash
micromamba run -n pytensor-test pre-commit
```
Alternative backends (JAX, PyTorch, MLX) are optional. Use `pytest.importorskip` to fail gracefully.
### MyPy
```bash
micromamba run -n pytensor-test python ./scripts/run_mypy.py --verbose
python ./scripts/run_mypy.py --verbose
```
**PyTensor incompatible with strict mypy**. Type-hints are for users/developers not to appease mypy. Liberal `type: ignore[rule]` and file exclusions are acceptable.
### Documentation
```bash
micromamba run -n pytensor-test python -m sphinx -b html ./doc ./html # Build docs (2-3 min)
Use `pytensor.dprint` to inspect graphs. It works on both raw variables (before optimization) and compiled functions (after optimization):
```python
pytensor.dprint(y,print_type=True)# Before optimization
pytensor.dprint(f,print_type=True,print_memory_map=True)# After optimization
```
`print_type=True` shows the type and shape of each variable. `print_memory_map=True` shows memory allocation labels, useful for spotting whether intermediates share memory.
### Rewriting without compiling
Use `rewrite_graph` to apply rewrites to a graph without the full `pytensor.function` compilation:
This prints each rewrite that fires, showing what it replaced and with what.
## CI/CD Pipeline
### Workflows (`.github/workflows/`)
1.**test.yml**: Main suite - Several Python versions, fast-compile (0/1), float32 (0/1), 7 test parts + backend jobs (numba, jax, torch)
1.**test.yml**: Main suite - Several Python versions, 7 test parts + backend jobs (jax, torch)
2.**mypy.yml**: Type checking
3.**copilot-setup-steps.yml**: Environment setup
CI runs tests under three modes: Default (`"NUMBA"`), `"CVM"`, and `"FAST_COMPILE"`. Tests must pass in all three.
## Known Gotchas
## Trust These Instructions
These instructions are comprehensive and tested. Only search for additional information if:
1. Instructions are incomplete for your specific task
2. Instructions are found to be incorrect
3. You need deeper understanding of an implementation detail
For most coding tasks, these instructions provide everything needed to build, test, and validate changes efficiently.
-**Numba scalar outputs**: Numba-compiled scalar functions return Python `float`/`int`, not NumPy scalars. Keep this in mind when writing tests that check output types.