-
Notifications
You must be signed in to change notification settings - Fork 5
Feature/SOF-7759 Jode Mock NB #254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 7 commits
9242fe6
74069ac
35aa49b
dfe43aa
975cdbb
c9bd9ee
8ce197f
13f23e8
8716dd8
1f7ff60
21301f5
be40a18
8564836
d3fd230
d5cb17b
c030a11
f244e20
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,327 @@ | ||
| { | ||
| "cells": [ | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "0", | ||
| "metadata": {}, | ||
| "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." | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "1", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "## 1. Set up the environment and parameters" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "2", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "## 2. Log in to get the API token" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "3", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "from mat3ra.api import ApiClient\n", | ||
| "\n", | ||
| "from examples.reproducing_publications.band_gaps_for_interface_bilayer_twisted_molybdenum_disulfide import \\\n", | ||
| " unit_flowchart_id\n", | ||
| "\n", | ||
| "# Log in to get the API token\n", | ||
| "auth_config = await ApiClient().login()" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "4", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "## 3. Load the target material" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "5", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "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)" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "6", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "## 4. Import workflow builder and related analyzers" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "7", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "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()" | ||
|
||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "8", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "## 5. Create workflow and set its parameters" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "9", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "from mat3ra.standata.workflows import Workflows\n", | ||
| "from mat3ra.wode.workflows import Workflow\n", | ||
| "from mat3ra.wode.pseudopotentials import PseudopotentialEnum\n", | ||
| "\n", | ||
| "# Get Applications list (with versions, build)\n", | ||
| "# Search WF by name and and n\n", | ||
| "workflow_config = Workflows.get_by_name_first_match(\"band_structure\")\n", | ||
| "workflow = Workflow.create(workflow_config)\n", | ||
| "\n", | ||
| "# View workflow to understand its structure\n", | ||
| "visualize(workflow)\n", | ||
| "# Get workflow's specific unit that needs to be modified\n", | ||
| "unit_to_modify = workflow.get_unit_by_name(name=\"scf\", subworkflow_name=\"xxx\", order_in_subworkflow=1)\n", | ||
| "new_context = kgrid_context_provider.get_data(dimentions=[6,6,6])\n", | ||
| "unit_to_modify.context.add_context(new_context)\n", | ||
| "workflow.set_unit(unit_flowchart_id=unit_to_modify.flowchart_id, new_unit=unit_to_modify)\n", | ||
| "\n", | ||
| "workflow.set_context_providers(kpoints)\n", | ||
| "workflow.set_pseudopotential(PseudopotentialEnum.Funtional_GGA) # elements will be set automatically based on the material" | ||
VsevolodX marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "10", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "## 6. Create the compute configuration" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "11", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "from mat3ra.ide.compute import ComputeConfiguration, QueueEnum\n", | ||
| "compute_config = ComputeConfiguration(\n", | ||
| " queue = QueueEnum.OR8,\n", | ||
| " nodes = 1,\n", | ||
| " cores = 8,\n", | ||
| ")" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "12", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "## 7. Create the job with material and workflow configuration" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "13", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "from mat3ra.jode.job import create_job\n", | ||
| "job = create_job(workflow=workflow, material=material, compute = compute_config, auth_config=auth_config)\n" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "14", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "## 8. Submit the job and monitor the status" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "15", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "from mat3ra.prode import PropertyEnum\n", | ||
| "job.run()\n", | ||
| "job.wait_for_complete()\n", | ||
| "# job.check_status()\n", | ||
| "# job.get_current_output()" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "16", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "## 9. Retrieve results" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "17", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "# AFTER Finished\n", | ||
| "# A class from Prode to handle results\n", | ||
| "results = job.get_results(PropertyEnum.BAND_GAP, PropertyEnum.BAND_STRUCTURE)" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "18", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "## 10. Display results" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "19", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "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)" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "20", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "import pydot\n", | ||
| "import json\n", | ||
| "\n", | ||
| "# Example JSON data (you would load this from a file)\n", | ||
| "json_data = {\n", | ||
| " \"nodes\": [\n", | ||
| " {\"name\": \"A\", \"shape\": \"box\", \"label\": \"Start\"},\n", | ||
| " {\"name\": \"B\", \"shape\": \"box\", \"label\": \"Process 1\"},\n", | ||
| " {\"name\": \"C\", \"shape\": \"diamond\", \"label\": \"Decision\"},\n", | ||
| " {\"name\": \"D\", \"shape\": \"box\", \"label\": \"End\"}\n", | ||
| " ],\n", | ||
| " \"edges\": [\n", | ||
| " {\"source\": \"A\", \"target\": \"B\", \"label\": \"\"},\n", | ||
| " {\"source\": \"B\", \"target\": \"C\", \"label\": \"\"},\n", | ||
| " {\"source\": \"C\", \"target\": \"D\", \"label\": \"Yes\"},\n", | ||
| " {\"source\": \"C\", \"target\": \"B\", \"label\": \"No\"}\n", | ||
| " ]\n", | ||
| "}\n", | ||
| "\n", | ||
| "# Create a new directed graph\n", | ||
| "dot_graph = pydot.Dot(\"my_flowchart\", graph_type=\"digraph\")\n", | ||
| "\n", | ||
| "# Add nodes\n", | ||
| "for node_data in json_data[\"nodes\"]:\n", | ||
| " node = pydot.Node(node_data[\"name\"], shape=node_data[\"shape\"], label=node_data[\"label\"])\n", | ||
| " dot_graph.add_node(node)\n", | ||
| "\n", | ||
| "# Add edges\n", | ||
| "for edge_data in json_data[\"edges\"]:\n", | ||
| " edge = pydot.Edge(edge_data[\"source\"], edge_data[\"target\"], label=edge_data[\"label\"])\n", | ||
| " dot_graph.add_edge(edge)\n", | ||
| "\n", | ||
| "# Save the flowchart as a PNG\n", | ||
| "dot_graph.write_png(\"flowchart.png\")\n", | ||
| "print(\"Flowchart rendered to flowchart.png\")\n" | ||
| ] | ||
|
Comment on lines
289
to
381
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove unrelated pydot flowchart code. This code cell appears to be test or example code for creating flowcharts with pydot, which is completely unrelated to the bandgap calculation workflow demonstrated in this notebook. It should be removed to maintain focus and clarity. If flowchart visualization of the workflow is intended, it should be integrated with the actual workflow object created in earlier cells, not use hardcoded JSON data. 🤖 Prompt for AI Agents |
||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "21", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [] | ||
| } | ||
| ], | ||
| "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 | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove unused import or clarify its purpose.
The imported
unit_flowchart_idfrom line 49-50 is not used in this cell or anywhere else in the notebook. If it's intended for future use, consider adding a comment explaining its purpose, otherwise remove it.Apply this diff to remove the unused import:
📝 Committable suggestion
🧰 Tools
🪛 Ruff (0.14.6)
50-50: Undefined name
kgrid_context_provider(F821)
🤖 Prompt for AI Agents