Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
47 changes: 47 additions & 0 deletions api/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
modules:
# ── State Module ───────────────────────────────────────────────────────
- class: modules::state::StateModule
config:
adapter:
class: modules::state::adapters::KvStore
config:
store_method: file_based
file_path: ./data/state_store.db

# ── REST API Module ────────────────────────────────────────────────────
- class: modules::api::RestApiModule
config:
port: 3111
host: 0.0.0.0
default_timeout: 30000
concurrency_request_limit: 1024
cors:
allowed_origins:
- http://localhost:3000
- http://localhost:5173
allowed_methods:
- GET
- POST
- PUT
- DELETE
- OPTIONS

# ── Queue Module ───────────────────────────────────────────────────────
- class: modules::queue::QueueModule
config:
adapter:
class: modules::queue::BuiltinQueueAdapter

# ── PubSub Module ──────────────────────────────────────────────────────
- class: modules::pubsub::PubSubModule
config:
adapter:
class: modules::pubsub::LocalAdapter

# ── Exec Module (Python) ───────────────────────────────────────────────
- class: modules::shell::ExecModule
config:
watch:
- steps/**/*.py
exec:
- motia dev --dir steps
9 changes: 0 additions & 9 deletions api/motia.config.ts

This file was deleted.

29 changes: 0 additions & 29 deletions api/package.json

This file was deleted.

6,913 changes: 0 additions & 6,913 deletions api/pnpm-lock.yaml

This file was deleted.

1 change: 0 additions & 1 deletion api/pnpm-workspace.yaml

This file was deleted.

13 changes: 13 additions & 0 deletions api/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[project]
name = "bbdev"
version = "0.1.0"
description = "Agent-friendly developer toolchain backend powered by Motia"
requires-python = ">=3.10"
dependencies = [
"motia[otel]==1.0.0rc17",
"iii-sdk==0.2.0",
"pydantic>=2.0",
]

[project.optional-dependencies]
dev = ["pytest>=8.0.0"]
17 changes: 9 additions & 8 deletions api/steps/compiler/01_build_api_step.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
import asyncio

from motia import ApiRequest, ApiResponse, FlowContext, http

from utils.event_common import wait_for_result

config = {
"type": "api",
"name": "Build Compiler",
"description": "build bitstream",
"path": "/compiler/build",
"method": "POST",
"emits": ["compiler.build"],
"flows": ["compiler"],
"triggers": [http("POST", "/compiler/build")],
"enqueues": ["compiler.build"],
}


async def handler(req, context):
body = req.get("body") or {}
await context.emit({"topic": "compiler.build", "data": body})
async def handler(request: ApiRequest, ctx: FlowContext) -> ApiResponse:
body = request.body or {}
await ctx.enqueue({"topic": "compiler.build", "data": body})

# ==================================================================================
# Wait for build result
# ==================================================================================
while True:
result = await wait_for_result(context)
result = await wait_for_result(ctx)
if result is not None:
return result
await asyncio.sleep(1)
16 changes: 8 additions & 8 deletions api/steps/compiler/01_build_event_step.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import os
import subprocess
import sys

from motia import FlowContext, queue

# Add the utils directory to the Python path
utils_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
if utils_path not in sys.path:
Expand All @@ -12,16 +13,15 @@
from utils.event_common import check_result

config = {
"type": "event",
"name": "Build Compiler",
"description": "build bitstream",
"subscribes": ["compiler.build"],
"emits": [],
"flows": ["compiler"],
"triggers": [queue("compiler.build")],
"enqueues": [],
}


async def handler(data, context):
async def handler(input_data: dict, ctx: FlowContext) -> None:
bbdir = get_buckyball_path()
script_dir = f"{bbdir}/workflow/steps/compiler/scripts"
yaml_dir = f"{script_dir}/yaml"
Expand All @@ -31,14 +31,14 @@ async def handler(data, context):
command = f"mkdir -p {bbdir}/compiler/build"
result = stream_run_logger(
cmd=command,
logger=context.logger,
logger=ctx.logger,
stdout_prefix="compiler build",
stderr_prefix="compiler build",
)
command = f"cd {bbdir}/compiler/build && ninja -j{os.cpu_count()}"
result = stream_run_logger(
cmd=command,
logger=context.logger,
logger=ctx.logger,
stdout_prefix="compiler build",
stderr_prefix="compiler build",
)
Expand All @@ -47,7 +47,7 @@ async def handler(data, context):
# Return result to API
# ==================================================================================
success_result, failure_result = await check_result(
context, result.returncode, continue_run=False
ctx, result.returncode, continue_run=False
)

# ==================================================================================
Expand Down
17 changes: 9 additions & 8 deletions api/steps/firesim/01_buildbitstream_api_step.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
import asyncio

from motia import ApiRequest, ApiResponse, FlowContext, http

from utils.event_common import wait_for_result

config = {
"type": "api",
"name": "Firesim Buildbitstream",
"description": "build bitstream",
"path": "/firesim/buildbitstream",
"method": "POST",
"emits": ["firesim.buildbitstream"],
"flows": ["firesim"],
"triggers": [http("POST", "/firesim/buildbitstream")],
"enqueues": ["firesim.buildbitstream"],
}


async def handler(req, context):
body = req.get("body") or {}
await context.emit({"topic": "firesim.buildbitstream", "data": body})
async def handler(request: ApiRequest, ctx: FlowContext) -> ApiResponse:
body = request.body or {}
await ctx.enqueue({"topic": "firesim.buildbitstream", "data": body})

# ==================================================================================
# Wait for simulation result
# ==================================================================================
while True:
result = await wait_for_result(context)
result = await wait_for_result(ctx)
if result is not None:
return result
await asyncio.sleep(1)
14 changes: 7 additions & 7 deletions api/steps/firesim/01_buildbitstream_event_step.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import os
import subprocess
import sys

from motia import FlowContext, queue

# Add the utils directory to the Python path
utils_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
if utils_path not in sys.path:
Expand All @@ -12,16 +13,15 @@
from utils.event_common import check_result

config = {
"type": "event",
"name": "Firesim Buildbitstream",
"description": "build bitstream",
"subscribes": ["firesim.buildbitstream"],
"emits": [],
"flows": ["firesim"],
"triggers": [queue("firesim.buildbitstream")],
"enqueues": [],
}


async def handler(data, context):
async def handler(input_data: dict, ctx: FlowContext) -> None:
bbdir = get_buckyball_path()
script_dir = f"{bbdir}/workflow/steps/firesim/scripts"
yaml_dir = f"{script_dir}/yaml"
Expand All @@ -35,7 +35,7 @@ async def handler(data, context):
command += f" -c {yaml_dir}/config_runtime.yaml"
result = stream_run_logger(
cmd=command,
logger=context.logger,
logger=ctx.logger,
stdout_prefix="firesim buildbitstream",
stderr_prefix="firesim buildbitstream",
)
Expand All @@ -44,7 +44,7 @@ async def handler(data, context):
# Return result to API
# ==================================================================================
success_result, failure_result = await check_result(
context, result.returncode, continue_run=False
ctx, result.returncode, continue_run=False
)

# ==================================================================================
Expand Down
17 changes: 9 additions & 8 deletions api/steps/firesim/02_infrasetup_api_step.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
import asyncio

from motia import ApiRequest, ApiResponse, FlowContext, http

from utils.event_common import wait_for_result

config = {
"type": "api",
"name": "Firesim Infrasetup",
"description": "infrasetup",
"path": "/firesim/infrasetup",
"method": "POST",
"emits": ["firesim.infrasetup"],
"flows": ["firesim"],
"triggers": [http("POST", "/firesim/infrasetup")],
"enqueues": ["firesim.infrasetup"],
}


async def handler(req, context):
body = req.get("body") or {}
async def handler(request: ApiRequest, ctx: FlowContext) -> ApiResponse:
body = request.body or {}
data = {"jobs": body.get("jobs", 16)}
await context.emit({"topic": "firesim.infrasetup", "data": data})
await ctx.enqueue({"topic": "firesim.infrasetup", "data": data})

# ==================================================================================
# Wait for simulation result
# ==================================================================================
while True:
result = await wait_for_result(context)
result = await wait_for_result(ctx)
if result is not None:
return result
await asyncio.sleep(1)
16 changes: 7 additions & 9 deletions api/steps/firesim/02_infrasetup_event_step.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import os
import subprocess
import sys

from motia import FlowContext, queue

# Add the utils directory to the Python path
utils_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
if utils_path not in sys.path:
Expand All @@ -12,16 +13,15 @@
from utils.event_common import check_result

config = {
"type": "event",
"name": "Firesim Infrasetup",
"description": "infrasetup",
"subscribes": ["firesim.infrasetup"],
"emits": [],
"flows": ["firesim"],
"triggers": [queue("firesim.infrasetup")],
"enqueues": [],
}


async def handler(data, context):
async def handler(input_data: dict, ctx: FlowContext) -> None:
bbdir = get_buckyball_path()
script_dir = f"{bbdir}/workflow/steps/firesim/scripts"
yaml_dir = f"{script_dir}/yaml"
Expand All @@ -35,7 +35,7 @@ async def handler(data, context):
command += f" -c {yaml_dir}/config_runtime.yaml"
result = stream_run_logger(
cmd=command,
logger=context.logger,
logger=ctx.logger,
stdout_prefix="firesim infrasetup",
stderr_prefix="firesim infrasetup",
)
Expand All @@ -44,13 +44,11 @@ async def handler(data, context):
# Return result to API
# ==================================================================================
success_result, failure_result = await check_result(
context, result.returncode, continue_run=False
ctx, result.returncode, continue_run=False
)

# ==================================================================================
# Continue routing
# Routing to verilog or finish workflow
# For run workflow, continue to verilog; for standalone clean, complete
# ==================================================================================

return
Loading