Skip to content
Open
Changes from 6 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
242 changes: 242 additions & 0 deletions other/materials_designer/specific_examples/run_bandgap_workflow.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
{
"cells": [
{
"metadata": {},
"cell_type": "markdown",
"source": [
"# Bandgap Workflow Example\n",
" This notebook demonstrates how to build and run a bandgap workflow for a material.\n",
"\n",
"## Process Overview\n",
"### 1. Set up the environment and parameters.\n",
"### 2. Log in to get the API token\n",
"### 3. Load the target material.\n",
"### 4. Import workflow builder and related analyzers.\n",
"### 5. Analyze material to get parameters for the workflow configuration.\n",
"### 6. Create the workflow configuration.\n",
"### 7. Create a job with material and workflow configuration.\n",
"### 8. Submit the job to the server.\n",
"### 9. Monitor the job status and retrieve results.\n",
"### 10. Display the results."
],
"id": "ed24b225263ae3c3"
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## 1. Set up the environment and parameters",
"id": "598da5f8c4f507ec"
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## 2. Log in to get the API token",
"id": "51105b005c535ca"
},
{
"metadata": {},
"cell_type": "code",
"source": [
"from mat3ra.api import ApiClient\n",
"# Log in to get the API token\n",
"auth_config = await ApiClient().login()"
],
"id": "23626cb27f6e7206",
"outputs": [],
"execution_count": null
},
Comment on lines 41 to 53
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

jq '.metadata.language_info.version' other/materials_designer/specific_examples/run_bandgap_workflow.ipynb

Repository: Exabyte-io/api-examples

Length of output: 74


Update Python version and use sync API call or enable async support.

Top-level await is used in the code, but the notebook metadata specifies Python 2.7.6, which does not support async/await syntax (introduced in Python 3.5+). Either update the notebook metadata to Python 3.5+, or replace the async call with a synchronous alternative.

🤖 Prompt for AI Agents
In other/materials_designer/specific_examples/run_bandgap_workflow.ipynb around
lines 36 to 47, the notebook uses top-level "await ApiClient().login()" but the
notebook metadata is set to Python 2.7.6 which lacks async/await support; either
update the notebook kernel metadata to a Python 3.5+ kernel (preferably
3.8/3.9+) so async/await are supported, or change the call to a synchronous
login variant (e.g., use ApiClient().login_sync() or call the login coroutine
via an event loop wrapper) and remove the top-level await; update metadata or
code accordingly and rerun the cell to confirm no syntax errors.

{
"metadata": {},
"cell_type": "markdown",
"source": "## 3. Load the target material",
"id": "ba816c64f28f6a3d"
},
{
"metadata": {
"collapsed": true
},
"cell_type": "code",
"source": [
"from utils.visualize import visualize_materials as visualize\n",
"from utils.jupyterlite import load_material_from_folder\n",
"\n",
"material = load_material_from_folder(\"/uploads\", \"MoS2_twisted_interface_60_degrees.json\")\n",
"visualize(material)"
],
"id": "initial_id",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## 4. Import workflow builder and related analyzers",
"id": "f8d7e25a7c9cc2e"
},
{
"metadata": {},
"cell_type": "code",
"source": [
"from mat3ra.wode.context_providers import (\n",
" PointsGridFormDataProvider, # exists - for k-points\n",
" PlanewaveCutoffsContextProvider, # exists - for cutoffs\n",
" SmearingContextProvider, # no JS implementation yet\n",
" BandsContextProvider # no JS implementation yet\n",
")\n",
"\n",
"\n",
"kgrid_provider = PointsGridFormDataProvider(material=material)\n",
"cutoffs_provider = PlanewaveCutoffsContextProvider(material=material)\n",
"smearing_provider = SmearingContextProvider(material=material)\n",
"bands_provider = BandsContextProvider(material=material)\n",
"\n",
"kpoints = kgrid_provider.get_dimensions() # or calculate_dimensions()\n",
"cutoff = cutoffs_provider.get_cutoff() # defaultECUTWFC, defaultECUTRHO\n",
"smearing = smearing_provider.get_smearing()\n",
"number_of_bands = bands_provider.get_number_of_bands()"
],
"id": "5ead702c417eff62",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## 5. Create workflow and set its parameters",
"id": "9bdd00f870caaeeb"
},
{
"metadata": {},
"cell_type": "code",
"source": [
"from mat3ra.standata.workflows import Workflows\n",
"from mat3ra.wode.workflows import Workflow\n",
"from mat3ra.wode.pseudopotentials import PseudopotentialEnum\n",
"\n",
"workflow_config = Workflows.get_by_name_first_match(\"band_structure\")\n",
"workflow = Workflow.create(workflow_config)\n",
"workflow.set_kpoints(kpoints)\n",
"workflow.set_pseudopotential(PseudopotentialEnum.PAW_HSE) # elements will be set automatically based on the material"
],
"id": "68d43f6c797f2fc4",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## 6. Create the compute configuration",
"id": "1f15e054ddb9a08c"
},
{
"metadata": {},
"cell_type": "code",
"source": [
"from mat3ra.ide.compute import ComputeConfiguration, QueueEnum\n",
"compute_config = ComputeConfiguration(\n",
" queue = QueueEnum.OR8,\n",
" nodes = 1,\n",
" cores = 8,\n",
")"
],
"id": "60e880dc581dafe1",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## 7. Create the job with material and workflow configuration",
"id": "cbc16438ad5b0ce0"
},
{
"metadata": {},
"cell_type": "code",
"outputs": [],
"execution_count": null,
"source": [
"from mat3ra.jode.job import create_job\n",
"job = create_job(workflow=workflow, material=material, compute = compute_config, auth_config=auth_config)"
],
"id": "20b3bf702b6e084c"
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## 8. Submit the job and monitor the status",
"id": "8d5740e099512107"
},
{
"metadata": {},
"cell_type": "code",
"outputs": [],
"execution_count": null,
"source": [
"from mat3ra.prode import PropertyEnum\n",
"job.run()\n",
"job.wait_for_complete()\n",
"# job.check_status()\n",
"# job.get_current_output()"
],
"id": "df29a9065e8b5eae"
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## 9. Retrieve results",
"id": "349d46228a98bcd9"
},
{
"metadata": {},
"cell_type": "code",
"outputs": [],
"execution_count": null,
"source": [
"# AFTER Finished\n",
"# A class from Prode to handle results\n",
"results = job.get_results(PropertyEnum.BAND_GAP, PropertyEnum.BAND_STRUCTURE)"
],
"id": "ce79fc805900503a"
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## 10. Display results",
"id": "6f864b5134b53eac"
},
{
"metadata": {},
"cell_type": "code",
"outputs": [],
"execution_count": null,
"source": [
"# Visual library that can visualize any property defined in Prode\n",
"from mat3ra.prove import visualize_property\n",
"visualize_property(results.band_structure)\n",
"print(results.band_gap)"
],
"id": "978bb38b10c15976"
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading