Skip to content

fix: bootstrap MP imports and document setup sequence - #1

Open
Irratzo wants to merge 1 commit into
fridayowl:mainfrom
Irratzo:agents/skilled-fox
Open

fix: bootstrap MP imports and document setup sequence#1
Irratzo wants to merge 1 commit into
fridayowl:mainfrom
Irratzo:agents/skilled-fox

Conversation

@Irratzo

@Irratzo Irratzo commented Jul 18, 2026

Copy link
Copy Markdown

This PR makes the Materials Project import path reproducible from a fresh checkout.

What changed:

  • update the backend dependency pins to a compatible MP stack
  • add a small pymatgen/emmet compatibility shim for mp-api imports
  • create the SQLite schema before the import scripts query or insert data
  • make the import scripts fail with a helpful error instead of silently returning no data
  • document the required bootstrap sequence in README.md and QUICKSTART.md
  • fix backend/run_demo.py so demo_results.txt is written relative to the script

Notes:

  • No generated .joblib artifacts are committed.
  • The frontend still appears to be a separate issue; this PR focuses on backend bootstrap, import, and docs.

Make the Materials Project import scripts work from a fresh checkout by updating the pinned MP stack, adding pymatgen compatibility shims, and creating the SQLite schema before import. Also document the required bootstrap/retrain steps and fix the demo results path.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 18, 2026 17:21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR makes the backend “Materials Project → SQLite → model training” bootstrap path reproducible from a fresh checkout by pinning a compatible MP dependency stack, adding a small import-compat shim, ensuring DB tables exist before inserts/queries, and documenting the required setup sequence.

Changes:

  • Update backend dependency pins for the MP stack and add a pymatgen/emmet-core compatibility shim used before importing mp_api.
  • Ensure the SQLite schema is created before import scripts insert/query data, and add clearer failure output when MP client init/import fails.
  • Document the bootstrap sequence in README.md and QUICKSTART.md, and write demo output relative to run_demo.py.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
README.md Documents the new required bootstrap sequence and renumbers setup steps.
QUICKSTART.md Adds bootstrap instructions so a fresh checkout can be initialized correctly.
backend/scripts/fetch_mp_data.py Adds DB initialization and more explicit MP client import/init checks before fetching.
backend/scripts/bulk_import_mp.py Adds pymatgen compatibility shim usage and DB initialization before bulk import.
backend/scripts/bulk_fetch_mp.py Moves MP imports behind the compatibility shim and initializes DB before bulk fetch/insert.
backend/run_demo.py Writes demo results relative to the script location (not the current working directory).
backend/requirements.txt Updates MP/pydantic pins and adds emmet-core pin to stabilize imports.
backend/app/utils/pymatgen_compat.py Introduces module aliasing/patches to bridge pymatgen layout differences for emmet-core.
backend/app/database.py Adds init_db() helper to create schema by importing models and calling create_all().
backend/app/core/materials_project.py Calls compatibility shim before mp_api import and records init errors for better diagnostics.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread backend/run_demo.py
Comment on lines 1 to +3
import sys; sys.path.insert(0, "backend")
import asyncio, json, time
from pathlib import Path
Comment on lines +18 to +30
from app.utils.pymatgen_compat import ensure_pymatgen_compat
ensure_pymatgen_compat()
from mp_api.client import MPRester
from app.database import SessionLocal
from app.database import SessionLocal, init_db
from app.models.material import Material, Property
from sqlalchemy import insert

client = MPRester(api_key=api_key)
try:
client = MPRester(api_key=api_key)
except Exception as exc:
print("ERROR: Materials Project client initialization failed.")
print(f"Client error: {exc}")
return
Comment on lines +21 to +32
from app.utils.pymatgen_compat import ensure_pymatgen_compat
ensure_pymatgen_compat()
from mp_api.client import MPRester
from app.database import SessionLocal, init_db
from app.models.material import Material, Property

client = MPRester(api_key=api_key)
try:
client = MPRester(api_key=api_key)
except Exception as exc:
print("ERROR: Materials Project client initialization failed.")
print(f"Client error: {exc}")
return
Comment on lines +37 to +43
try:
ensure_pymatgen_compat()
from mp_api.client import MPRester
except ModuleNotFoundError as exc:
print("ERROR: Materials Project client could not be imported.")
print(f"Import error: {exc}")
print("")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants