Skip to content

Commit 51d7620

Browse files
Add CI workflows, update README with installation instructions
- Add GitHub Actions tests workflow: pytest on Python 3.9-3.12, nightly runs, coverage reporting, black/flake8 linting - Add GitHub Actions notebooks workflow: notebook execution on Python 3.10, path-filtered triggers, format validation, nightly runs - Add Installation section to README with pip install -e . instructions - Update README import examples to use boxcrete.* namespace - Update README reference to boxcrete/models.py
1 parent 6e50552 commit 51d7620

11 files changed

Lines changed: 869 additions & 916 deletions

.github/workflows/notebooks.yml

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# GitHub Actions workflow for executing Jupyter notebooks
2+
# Runs on pull requests and nightly to ensure notebooks work correctly
3+
4+
name: Notebooks
5+
6+
on:
7+
push:
8+
branches: [main, master]
9+
paths:
10+
- 'notebooks/**'
11+
- 'boxcrete/**'
12+
- 'pyproject.toml'
13+
- '.github/workflows/notebooks.yml'
14+
pull_request:
15+
branches: [main, master]
16+
paths:
17+
- 'notebooks/**'
18+
- 'boxcrete/**'
19+
- 'pyproject.toml'
20+
- '.github/workflows/notebooks.yml'
21+
schedule:
22+
# Run nightly at 3:00 AM UTC
23+
- cron: '0 3 * * *'
24+
workflow_dispatch:
25+
26+
jobs:
27+
execute-notebooks:
28+
runs-on: ubuntu-latest
29+
strategy:
30+
fail-fast: false
31+
matrix:
32+
python-version: ['3.10']
33+
34+
steps:
35+
- name: Checkout repository
36+
uses: actions/checkout@v4
37+
38+
- name: Set up Python ${{ matrix.python-version }}
39+
uses: actions/setup-python@v5
40+
with:
41+
python-version: ${{ matrix.python-version }}
42+
43+
- name: Cache pip dependencies
44+
uses: actions/cache@v4
45+
with:
46+
path: ~/.cache/pip
47+
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }}
48+
restore-keys: |
49+
${{ runner.os }}-pip-${{ matrix.python-version }}-
50+
${{ runner.os }}-pip-
51+
52+
- name: Install dependencies
53+
run: |
54+
python -m pip install --upgrade pip
55+
pip install -e ".[notebooks]"
56+
57+
- name: Install Jupyter kernel
58+
run: |
59+
python -m ipykernel install --user --name python3
60+
61+
- name: Execute notebooks
62+
run: |
63+
# Find and execute all notebooks
64+
for notebook in notebooks/*.ipynb; do
65+
echo "========================================"
66+
echo "Executing: $notebook"
67+
echo "========================================"
68+
69+
# Execute the notebook in place with a timeout
70+
jupyter nbconvert \
71+
--to notebook \
72+
--execute \
73+
--inplace \
74+
--ExecutePreprocessor.timeout=600 \
75+
--ExecutePreprocessor.kernel_name=python3 \
76+
"$notebook"
77+
78+
echo "✅ Successfully executed: $notebook"
79+
echo ""
80+
done
81+
82+
- name: Upload executed notebooks as artifacts
83+
uses: actions/upload-artifact@v4
84+
if: always()
85+
with:
86+
name: executed-notebooks
87+
path: notebooks/*.ipynb
88+
retention-days: 7
89+
90+
notebook-lint:
91+
runs-on: ubuntu-latest
92+
steps:
93+
- name: Checkout repository
94+
uses: actions/checkout@v4
95+
96+
- name: Set up Python
97+
uses: actions/setup-python@v5
98+
with:
99+
python-version: '3.10'
100+
101+
- name: Install dependencies
102+
run: |
103+
python -m pip install --upgrade pip
104+
pip install nbformat
105+
106+
- name: Validate notebook format
107+
run: |
108+
python - << 'EOF'
109+
import nbformat
110+
import sys
111+
from pathlib import Path
112+
113+
notebooks = list(Path('notebooks').glob('*.ipynb'))
114+
errors = []
115+
116+
for nb_path in notebooks:
117+
try:
118+
with open(nb_path, 'r', encoding='utf-8') as f:
119+
nb = nbformat.read(f, as_version=4)
120+
print(f"✅ Valid notebook: {nb_path}")
121+
except Exception as e:
122+
errors.append(f"❌ Invalid notebook {nb_path}: {e}")
123+
print(errors[-1])
124+
125+
if errors:
126+
print(f"\n{len(errors)} notebook(s) failed validation.")
127+
sys.exit(1)
128+
else:
129+
print(f"\nAll {len(notebooks)} notebook(s) are valid.")
130+
EOF

.github/workflows/tests.yml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# GitHub Actions workflow for running unit tests
2+
# Runs on pull requests and nightly
3+
4+
name: Tests
5+
6+
on:
7+
push:
8+
branches: [main, master]
9+
pull_request:
10+
branches: [main, master]
11+
schedule:
12+
# Run nightly at 2:00 AM UTC
13+
- cron: '0 2 * * *'
14+
workflow_dispatch:
15+
16+
jobs:
17+
test:
18+
runs-on: ubuntu-latest
19+
strategy:
20+
fail-fast: false
21+
matrix:
22+
python-version: ['3.9', '3.10', '3.11', '3.12']
23+
24+
steps:
25+
- name: Checkout repository
26+
uses: actions/checkout@v4
27+
28+
- name: Set up Python ${{ matrix.python-version }}
29+
uses: actions/setup-python@v5
30+
with:
31+
python-version: ${{ matrix.python-version }}
32+
33+
- name: Cache pip dependencies
34+
uses: actions/cache@v4
35+
with:
36+
path: ~/.cache/pip
37+
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }}
38+
restore-keys: |
39+
${{ runner.os }}-pip-${{ matrix.python-version }}-
40+
${{ runner.os }}-pip-
41+
42+
- name: Install dependencies
43+
run: |
44+
python -m pip install --upgrade pip
45+
pip install -e ".[dev]"
46+
47+
- name: Run unit tests with pytest
48+
run: |
49+
python -m pytest test/ -v --tb=short --cov=boxcrete --cov-report=xml --cov-report=term-missing --cov-fail-under=100
50+
51+
- name: Upload coverage reports
52+
uses: codecov/codecov-action@v4
53+
if: matrix.python-version == '3.10'
54+
with:
55+
file: ./coverage.xml
56+
flags: unittests
57+
name: codecov-umbrella
58+
fail_ci_if_error: false
59+
60+
lint:
61+
runs-on: ubuntu-latest
62+
steps:
63+
- name: Checkout repository
64+
uses: actions/checkout@v4
65+
66+
- name: Set up Python
67+
uses: actions/setup-python@v5
68+
with:
69+
python-version: '3.10'
70+
71+
- name: Install linting dependencies
72+
run: |
73+
python -m pip install --upgrade pip
74+
pip install flake8 black
75+
76+
- name: Check code formatting with black
77+
run: |
78+
black --check --diff .
79+
80+
- name: Lint with flake8
81+
run: |
82+
# Stop build if there are Python syntax errors or undefined names
83+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
84+
# Exit-zero treats all errors as warnings
85+
flake8 . --count --exit-zero --statistics

README.md

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Sustainable Concrete via Bayesian Optimization
22

3-
Concrete is responsbile for up to **8% of anthropogenic carbon dioxide emissions per year** - compared to less than 3% for all air travel - and urgently needs to be decarbonized in order to achieve a sustainable future.
3+
Concrete is responsible for up to **8% of anthropogenic carbon dioxide emissions per year** - compared to less than 3% for all air travel - and urgently needs to be decarbonized in order to achieve a sustainable future.
44
We invite researchers and practitioners of both machine learning and civil engineering
55
to collaborate on discovering more sustainable concrete formulations that are applicable
66
to a wide array of construction projects, at scale.
@@ -13,7 +13,38 @@ This repository contains probabilistic models and data for the
1313

1414
as a function of their composition, consisting of
1515
cement, slag, water, to name a few basic ingredients.
16-
See the `models.py` file for implementation details.
16+
See `boxcrete/models.py` for implementation details.
17+
18+
## Installation
19+
20+
Install directly from GitHub (no cloning required):
21+
```bash
22+
pip install git+https://github.com/facebookresearch/SustainableConcrete.git
23+
```
24+
25+
Or install from source for development:
26+
```bash
27+
git clone https://github.com/facebookresearch/SustainableConcrete.git
28+
cd SustainableConcrete
29+
pip install -e .
30+
```
31+
32+
For development (includes testing and linting tools):
33+
```bash
34+
pip install -e ".[dev]"
35+
```
36+
37+
For running notebooks:
38+
```bash
39+
pip install -e ".[notebooks]"
40+
```
41+
42+
## Usage
43+
44+
```python
45+
from boxcrete.models import SustainableConcreteModel
46+
from boxcrete.utils import load_concrete_strength, get_mortar_bounds
47+
```
1748

1849
The models can be used for a variety of tasks, including but not limited to
1950
1) continuous-time strength predictions with uncertainty bands for a user-specified concrete mix, and

boxcrete/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
get_strength_gp_input_transform,
1313
)
1414
from boxcrete.utils import (
15+
DEFAULT_DATA_PATH,
1516
DEFAULT_X_COLUMNS,
1617
DEFAULT_Y_COLUMNS,
1718
DEFAULT_YSTD_COLUMNS,
@@ -29,6 +30,7 @@
2930
"fit_gwp_gp",
3031
"fit_strength_gp",
3132
"get_strength_gp_input_transform",
33+
"DEFAULT_DATA_PATH",
3234
"DEFAULT_X_COLUMNS",
3335
"DEFAULT_Y_COLUMNS",
3436
"DEFAULT_YSTD_COLUMNS",

0 commit comments

Comments
 (0)