Skip to content

Commit d18903f

Browse files
Add CI workflows, update README with installation instructions
- Add GitHub Actions tests workflow: pytest on Python 3.10-3.12, nightly runs, coverage reporting (100% threshold), 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 - Fix README typo (responsbile -> responsible)
1 parent 4f4dbde commit d18903f

3 files changed

Lines changed: 270 additions & 2 deletions

File tree

.github/workflows/notebooks.yml

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
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+
python - << 'PYEOF'
64+
import subprocess, sys
65+
from pathlib import Path
66+
67+
notebooks = sorted(Path("notebooks").glob("*.ipynb"))
68+
failed = []
69+
70+
for nb in notebooks:
71+
print(f"{'=' * 40}")
72+
print(f"Executing: {nb}")
73+
print(f"{'=' * 40}")
74+
75+
result = subprocess.run(
76+
[
77+
sys.executable, "-m", "jupyter", "nbconvert",
78+
"--to", "notebook",
79+
"--execute",
80+
"--inplace",
81+
"--ExecutePreprocessor.timeout=600",
82+
"--ExecutePreprocessor.kernel_name=python3",
83+
str(nb),
84+
],
85+
capture_output=False,
86+
)
87+
88+
if result.returncode != 0:
89+
failed.append(str(nb))
90+
print(f"❌ Failed: {nb}")
91+
else:
92+
print(f"✅ Successfully executed: {nb}")
93+
print()
94+
95+
if failed:
96+
print(f"\n{len(failed)} notebook(s) failed:")
97+
for f in failed:
98+
print(f" - {f}")
99+
sys.exit(1)
100+
else:
101+
print(f"\nAll {len(notebooks)} notebook(s) executed successfully.")
102+
PYEOF
103+
104+
- name: Upload executed notebooks as artifacts
105+
uses: actions/upload-artifact@v4
106+
if: always()
107+
with:
108+
name: executed-notebooks
109+
path: notebooks/*.ipynb
110+
retention-days: 7
111+
112+
notebook-lint:
113+
runs-on: ubuntu-latest
114+
steps:
115+
- name: Checkout repository
116+
uses: actions/checkout@v4
117+
118+
- name: Set up Python
119+
uses: actions/setup-python@v5
120+
with:
121+
python-version: '3.10'
122+
123+
- name: Install dependencies
124+
run: |
125+
python -m pip install --upgrade pip
126+
pip install nbformat
127+
128+
- name: Validate notebook format
129+
run: |
130+
python - << 'EOF'
131+
import nbformat
132+
import sys
133+
from pathlib import Path
134+
135+
notebooks = list(Path('notebooks').glob('*.ipynb'))
136+
errors = []
137+
138+
for nb_path in notebooks:
139+
try:
140+
with open(nb_path, 'r', encoding='utf-8') as f:
141+
nb = nbformat.read(f, as_version=4)
142+
print(f"✅ Valid notebook: {nb_path}")
143+
except Exception as e:
144+
errors.append(f"❌ Invalid notebook {nb_path}: {e}")
145+
print(errors[-1])
146+
147+
if errors:
148+
print(f"\n{len(errors)} notebook(s) failed validation.")
149+
sys.exit(1)
150+
else:
151+
print(f"\nAll {len(notebooks)} notebook(s) are valid.")
152+
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.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

0 commit comments

Comments
 (0)