Skip to content

Commit

Permalink
add ability to select gate type and toggle stall detection (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
eriktaubeneck authored May 15, 2024
1 parent c397689 commit 3d3b5f7
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 8 deletions.
38 changes: 33 additions & 5 deletions server/app/query/create/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";
import { useState, useRef, FormEvent, useEffect, Fragment } from "react";
import clsx from "clsx";
import { Listbox, Transition, Combobox } from "@headlessui/react";
import { Listbox, Transition, Combobox, Switch } from "@headlessui/react";
import {
CheckIcon,
ChevronUpDownIcon,
Expand Down Expand Up @@ -126,6 +126,7 @@ function IPAForm({
const [commitSpecifier, setCommitSpecifier] = useState<CommitSpecifier>(
CommitSpecifier.BRANCH,
);
const [stallDetectionEnabled, setStallDetectionEnabled] = useState(true);
const disableBranch = commitSpecifier != CommitSpecifier.BRANCH;
const disableCommitHash = commitSpecifier != CommitSpecifier.COMMIT_HASH;
const filteredCommitHashes =
Expand Down Expand Up @@ -242,7 +243,7 @@ function IPAForm({
<label
htmlFor="commit_hash"
className={clsx(
"block text-md font-medium leading-6 text-gray-900 pt-4 pl-[-30px]",
"block text-sm font-medium leading-6 text-gray-900 pt-4 pl-[-30px]",
disableCommitHash && "opacity-25",
)}
>
Expand Down Expand Up @@ -294,7 +295,6 @@ function IPAForm({
Not a valid commit hash.
</p>
)}

<SelectMenu
id="size"
label="Input Size"
Expand All @@ -319,6 +319,34 @@ function IPAForm({
options={["16", "32", "64", "128", "256"]}
defaultValue="64"
/>
<SelectMenu
id="gate_type"
label="Gate Type"
options={["compact", "descriptive"]}
defaultValue="compact"
/>
<div className="items-center pt-4">
<div className="block text-sm font-medium leading-6 text-gray-900">
Stall detection
</div>
<div className="block pt-1 text-sm font-medium leading-6 text-gray-900">
<Switch
checked={stallDetectionEnabled}
onChange={setStallDetectionEnabled}
name="stall_detection"
className={`${
stallDetectionEnabled ? "bg-blue-600" : "bg-gray-200"
} relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2`}
>
<span
className={`${
stallDetectionEnabled ? "translate-x-6" : "translate-x-1"
} inline-block h-4 w-4 transform rounded-full bg-white transition-transform`}
/>
</Switch>
</div>
</div>

<button
type="submit"
className={clsx(
Expand Down Expand Up @@ -394,7 +422,7 @@ function PassedStateSelectMenu({
<>
<Listbox.Label
className={clsx(
"block text-sm font-medium leading-6 text-gray-900",
"block pt-4 text-sm font-medium leading-6 text-gray-900",
labelClassName,
disabled && "opacity-25",
)}
Expand All @@ -403,7 +431,7 @@ function PassedStateSelectMenu({
</Listbox.Label>
<div
className={clsx(
"relative mt-2",
"relative",
selectClassName,
disabled && "opacity-25",
)}
Expand Down
19 changes: 17 additions & 2 deletions sidecar/app/query/ipa.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import time
from dataclasses import dataclass, field
from enum import StrEnum
from pathlib import Path
from typing import ClassVar
from urllib.parse import urlunparse
Expand All @@ -17,6 +18,11 @@
from .step import CommandStep, LoggerOutputCommandStep, Status, Step


class GateType(StrEnum):
COMPACT = "compact-gate"
DESCRIPTIVE = "descriptive-gate"


@dataclass(kw_only=True)
class IPAQuery(Query):
paths: Paths
Expand Down Expand Up @@ -155,23 +161,30 @@ def build_command(self) -> LoggerOutputCommand:
class IPAHelperCompileStep(LoggerOutputCommandStep):
manifest_path: Path
target_path: Path
gate_type: GateType
stall_detection: bool
logger: loguru.Logger = field(repr=False)
status: ClassVar[Status] = Status.COMPILING

@classmethod
def build_from_query(cls, query: IPAQuery):
def build_from_query(cls, query: IPAHelperQuery):
manifest_path = query.paths.repo_path / Path("Cargo.toml")
target_path = query.paths.repo_path / Path(f"target-{query.paths.commit_hash}")
gate_type = query.gate_type
stall_detection = query.stall_detection
return cls(
manifest_path=manifest_path,
target_path=target_path,
gate_type=gate_type,
stall_detection=stall_detection,
logger=query.logger,
)

def build_command(self) -> LoggerOutputCommand:
return LoggerOutputCommand(
cmd=f"cargo build --bin helper --manifest-path={self.manifest_path} "
f'--features="web-app real-world-infra compact-gate stall-detection" '
f'--features="web-app real-world-infra {self.gate_type} '
f"{'stall-detection' if self.stall_detection else ''}\" "
f"--no-default-features --target-dir={self.target_path} "
f"--release",
logger=self.logger,
Expand Down Expand Up @@ -383,6 +396,8 @@ def build_command(self) -> LoggerOutputCommand:
@dataclass(kw_only=True)
class IPAHelperQuery(IPAQuery):
port: int
gate_type: GateType
stall_detection: bool

step_classes: ClassVar[list[type[Step]]] = [
IPACloneStep,
Expand Down
6 changes: 5 additions & 1 deletion sidecar/app/routes/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from ..local_paths import Paths
from ..query.base import Query
from ..query.demo_logger import DemoLoggerQuery
from ..query.ipa import IPACoordinatorQuery, IPAHelperQuery
from ..query.ipa import GateType, IPACoordinatorQuery, IPAHelperQuery
from ..query.step import Status
from ..settings import settings

Expand Down Expand Up @@ -39,6 +39,8 @@ def demo_logger(
def start_ipa_helper(
query_id: str,
commit_hash: Annotated[str, Form()],
gate_type: Annotated[str, Form()],
stall_detection: Annotated[bool, Form()],
background_tasks: BackgroundTasks,
):
role = settings.role
Expand All @@ -53,6 +55,8 @@ def start_ipa_helper(
query = IPAHelperQuery(
paths=paths,
query_id=query_id,
gate_type=GateType[gate_type.upper()],
stall_detection=stall_detection,
port=settings.helper_port,
)
background_tasks.add_task(query.start)
Expand Down

0 comments on commit 3d3b5f7

Please sign in to comment.