Skip to content

Commit 17eec49

Browse files
Merge branch 'main' into main
2 parents f1aa7e4 + 8dcc222 commit 17eec49

16 files changed

Lines changed: 2282 additions & 1347 deletions

.flake8

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[flake8]
2+
# E203, W503: black and flake8 disagree on whitespace/operator placement
3+
ignore = E203, W503
4+
max-line-length = 88
5+
exclude = build, dist, .eggs

.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

.gitignore

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Python
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
*.so
6+
.Python
7+
build/
8+
develop-eggs/
9+
dist/
10+
downloads/
11+
eggs/
12+
.eggs/
13+
lib/
14+
lib64/
15+
parts/
16+
sdist/
17+
var/
18+
wheels/
19+
*.egg-info/
20+
.installed.cfg
21+
*.egg
22+
23+
# Jupyter Notebooks
24+
.ipynb_checkpoints/
25+
*/.ipynb_checkpoints/
26+
27+
# Testing
28+
.pytest_cache/
29+
.coverage
30+
htmlcov/
31+
.tox/
32+
.nox/
33+
coverage.xml
34+
*.cover
35+
.hypothesis/
36+
37+
# Virtual environments
38+
.env
39+
.venv
40+
env/
41+
venv/
42+
ENV/
43+
44+
# IDE
45+
.idea/
46+
.vscode/
47+
*.swp
48+
*.swo
49+
*~
50+
51+
# OS
52+
.DS_Store
53+
Thumbs.db
54+
55+
# Distribution
56+
*.tar.gz
57+
*.zip
58+
59+
# Planning files
60+
*.plan.md

README.md

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,52 @@
11
# BOxCrete: A Bayesian Optimization open-source AI Model for Concrete Mix Design & Optimization
22

3-
Concrete, the second most widely used material in the world, accounts for **6–8% of global anthropogenic CO₂ emissions**, largely due to Portland cement production (~0.8 tons CO₂ per ton of cement). Partial replacement with Supplementary Cementitious Materials (SCMs) such as fly ash, slag, and natural pozzolan reduces embodied carbon and often improves durability, but high SCM usage makes compressive strength a highly nonlinear function of multiple interacting mix parameters, rendering traditional design empirical and trial-and-error driven. To systematically navigate this complex composition space, data-driven frameworks are needed. Here, we introduce BOxCrete, an open-source Bayesian optimization framework for probabilistic strength curve prediction and sustainable mix design.
3+
Concrete, the second most widely used material in the world, accounts for **6–8% of global anthropogenic CO₂ emissions**, largely due to Portland cement production (~0.8 tons CO₂ per ton of cement). Partial replacement with Supplementary Cementitious Materials (SCMs) such as fly ash, slag, and natural pozzolan reduces embodied carbon and often improves durability, but high SCM usage makes compressive strength a highly nonlinear function of multiple interacting mix parameters, rendering traditional design empirical and trial-and-error driven. To systematically navigate this complex composition space, data-driven frameworks are needed.
4+
Here, we introduce BOxCrete, an open-source Bayesian optimization framework for probabilistic strength curve prediction and sustainable mix design.
5+
We invite researchers and practitioners of both machine learning and civil engineering
6+
to collaborate on discovering more sustainable concrete formulations that are applicable
7+
to a wide array of construction projects, at scale.
8+
For more information,
9+
please see ["Sustainable Concrete via Bayesian Optimization"](https://arxiv.org/abs/2310.18288).
410

511
This repository contains probabilistic models and data for the
612

713
1) Compressive strength of concrete and mortar mixes
814
2) The associated global warming potential (GWP)
915

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

1251
The models can be used for a variety of tasks, including but not limited to
1352
1) Continuous-time strength curve predictions with uncertainty bands for a user-specified concrete mix.

0 commit comments

Comments
 (0)