The Workflow API is a FastAPI-based service that manages computational workflows with machine learning models. It provides endpoints for creating, monitoring, and managing workflow executions.
http://127.0.0.1:8001
Currently, the API does not require authentication but requires an LM API key in the workflow request.
GET /ping
Verifies if the API is running.
Response:
{
"status": "ok",
"message": "API is running"
}POST /workflow/
Creates and starts a new workflow execution.
Request Body:
{
"calculation_prompt": string,
"workflow_index": integer | null,
"gen_model_hierarchy": [
string,
string,
string
],
"model_config": {
"parameter_evaluation": string,
"condition_finder": string
},
"interface_agent_kwargs": {
"model": string,
"extras": {
"max_tokens": integer
}
},
"lm_api": string,
"project_config": object | null
}Response:
{
"status": "started",
"workflow_id": string,
"message": "Workflow started successfully"
}GET /workflow-status/{workflow_id}
Returns the current status of a workflow.
Response:
{
"status": "running" | "stopped" | "not_found",
"current_state": string
}POST /stop-workflow/{workflow_id}
Stops a running workflow.
Response:
{
"status": "success",
"message": "Workflow stopped successfully"
}GET /results/{workflow_id}
Retrieves the results of a completed workflow.
GET /timeline/{workflow_id}
Returns a PNG visualization of the workflow timeline.
GET /logs
Provides real-time log streaming using Server-Sent Events (SSE).
The API returns standard HTTP status codes:
- 200: Success
- 400: Bad Request
- 404: Not Found
- 500: Internal Server Error
Error responses include detailed messages and, when applicable, stack traces.
/wf_api_results: Contains workflow results and visualizations/static: Static files/templates: HTML templates
- databricks/dbrx-instruct
- meta-llama/llama-3.1-405b-instruct
- anthropic/claude-3.5-sonnet
- parameter_evaluation: mistralai/mixtral-8x22b-instruct
- condition_finder: mistralai/mixtral-8x22b-instruct
The API implements a custom logging system that:
- Captures both stdout and stderr
- Strips ANSI color codes
- Provides real-time log streaming
- Filters out unnecessary system messages
The following template shows the structure of a project configuration object that can be included in workflow requests:
{
"project_config": {
"name": string,
"participants": string[],
"metadata": {
"project_type": string,
"material": string,
"purpose": string,
[key: string]: any
},
"main_dir": string (path),
"output_dir": string (path),
"pseudopotentials": string (path),
"project_signature": string,
"num_retries_permodel": integer,
"async_batch_size": integer,
"MAXDocToken": integer,
"gen_model_hierarchy": string[],
"model_config": {
"parameter_evaluation": string,
"condition_finder": string
},
"qe_settings": {
"use_slurm": boolean,
"qe_env": string,
"n_cores": integer,
"conda_path": string (path),
"qe_prefix": string,
"module_name": string
}
}
}Example:
{
"project_config": {
"name": "CeO2_optimization",
"participants": ["researcher1", "researcher2"],
"metadata": {
"project_type": "material_optimization",
"material": "CeO2",
"purpose": "band_structure_calculation"
},
"main_dir": "/path/to/your/project",
"output_dir": "/path/to/your/project/output",
"pseudopotentials": "/path/to/your/project/pseudo",
"project_signature": "CeO2_opt_v1",
"num_retries_permodel": 5,
"async_batch_size": 10,
"MAXDocToken": 19000,
"gen_model_hierarchy": [
"databricks/dbrx-instruct",
"meta-llama/llama-3.1-405b-instruct",
"anthropic/claude-3.5-sonnet"
],
"model_config": {
"parameter_evaluation": "mistralai/mixtral-8x22b-instruct",
"condition_finder": "mistralai/mixtral-8x22b-instruct"
},
"qe_settings": {
"use_slurm": false,
"qe_env": "qe",
"n_cores": 8,
"conda_path": "/path/to/conda/etc/profile.d/conda.sh",
"qe_prefix": "mpirun -n 8",
"module_name": "qe"
}
}
}Field Descriptions:
name: Project identifierparticipants: List of project team membersmetadata: Custom metadata for project documentationmain_dir: Main project directory pathoutput_dir: Directory for output filespseudopotentials: Directory containing pseudopotential filesproject_signature: Unique project identifiernum_retries_permodel: Maximum retry attempts per modelasync_batch_size: Batch size for async operationsMAXDocToken: Maximum tokens for documentationgen_model_hierarchy: Ordered list of ML models to trymodel_config: Configuration for specific model tasksqe_settings: Quantum Espresso execution settings
Notes:
- All paths should be absolute paths or relative to the project root
- The
qe_settingsshould match your computational environment - Model names should be valid and accessible in your environment
- Ensure the API server is running (default: http://127.0.0.1:8001)
- Verify connectivity using the health check endpoint
- Prepare your workflow configuration
- Submit your workflow request
Here's a step-by-step guide to create and monitor a workflow:
- Check API Health
curl http://127.0.0.1:8001/ping- Create a New Workflow Basic workflow request:
curl -X POST http://127.0.0.1:8001/workflow/ \
-H "Content-Type: application/json" \
-d '{
"calculation_prompt": "Calculate band structure for CeO2",
"workflow_index": 0,
"lm_api": "your_api_key_here",
"gen_model_hierarchy": [
"databricks/dbrx-instruct",
"meta-llama/llama-3.1-405b-instruct",
"anthropic/claude-3.5-sonnet"
],
"model_config": {
"parameter_evaluation": "mistralai/mixtral-8x22b-instruct",
"condition_finder": "mistralai/mixtral-8x22b-instruct"
}
}'- Monitor Workflow Status
curl http://127.0.0.1:8001/workflow-status/{workflow_id}- Get Results When Complete
curl http://127.0.0.1:8001/results/{workflow_id}- View Timeline Visualization
curl -O http://127.0.0.1:8001/timeline/{workflow_id}curl -X POST http://127.0.0.1:8001/workflow/ \
-H "Content-Type: application/json" \
-d '{
"calculation_prompt": "Calculate band structure for CeO2",
"workflow_index": 0,
"lm_api": "your_api_key_here",
"gen_model_hierarchy": [
"databricks/dbrx-instruct",
"meta-llama/llama-3.1-405b-instruct",
"anthropic/claude-3.5-sonnet"
],
"model_config": {
"parameter_evaluation": "mistralai/mixtral-8x22b-instruct",
"condition_finder": "mistralai/mixtral-8x22b-instruct"
},
"interface_agent_kwargs": {
"model": "mistral",
"extras": {
"max_tokens": 8000
}
},
"project_config": {
"name": "CeO2_optimization",
"participants": ["researcher1", "researcher2"],
"metadata": {
"project_type": "material_optimization",
"material": "CeO2",
"purpose": "band_structure_calculation"
},
"main_dir": "/path/to/your/project",
"output_dir": "/path/to/your/project/output",
"pseudopotentials": "/path/to/your/project/pseudo",
"project_signature": "CeO2_opt_v1",
"num_retries_permodel": 5,
"async_batch_size": 10,
"MAXDocToken": 19000,
"qe_settings": {
"use_slurm": false,
"qe_env": "qe",
"n_cores": 8,
"conda_path": "/path/to/conda/etc/profile.d/conda.sh",
"qe_prefix": "mpirun -n 8",
"module_name": "qe"
}
}
}'To monitor logs in real-time using curl:
curl -N http://127.0.0.1:8001/logsOr using JavaScript in a web browser:
const eventSource = new EventSource('http://127.0.0.1:8001/logs');
eventSource.onmessage = function(event) {
const log = JSON.parse(event.data);
console.log(`${log.timestamp} [${log.level}]: ${log.message}`);
};-
Basic Material Calculation
- Use default configuration
- Provide calculation prompt
- Monitor results
-
Advanced Material Optimization
- Custom project configuration
- Multiple model hierarchy
- Custom computational resources
-
Batch Processing
- Configure async_batch_size
- Monitor multiple workflows
- Collect results
-
Project Information
name: Unique identifier for your projectproject_signature: Version or signatureparticipants: Team members involved
-
Directory Structure
main_dir: Root directory for projectoutput_dir: Results storagepseudopotentials: QE pseudopotential files
-
Computational Settings
n_cores: Number of CPU coresuse_slurm: Cluster submissionqe_prefix: MPI configuration
-
Model Settings
gen_model_hierarchy: Fallback model sequencemodel_config: Task-specific modelsMAXDocToken: Token limit for documentation
-
Directory Structure
project_root/ ├── output/ ├── pseudo/ └── results/ -
Error Handling
- Set appropriate
num_retries_permodel - Monitor logs for failures
- Check status regularly
- Set appropriate
-
Resource Management
- Match
n_coresto available resources - Configure
async_batch_sizeappropriately - Monitor system resources
- Match
-
Model Selection
- Order models by preference in hierarchy
- Match models to task requirements
- Consider token limits