Skip to content
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

Removed defaultNodes #2276

Merged
merged 2 commits into from
Oct 18, 2023
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
3 changes: 0 additions & 3 deletions backend/src/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ class NodeData:

side_effects: bool
deprecated: bool
default_nodes: List[DefaultNode] | None # For iterators only
features: List[FeatureId]

run: RunFn
Expand Down Expand Up @@ -126,7 +125,6 @@ def register(
node_type: NodeType = "regularNode",
side_effects: bool = False,
deprecated: bool = False,
default_nodes: List[DefaultNode] | None = None,
decorators: List[Callable] | None = None,
see_also: List[str] | str | None = None,
features: List[FeatureId] | FeatureId | None = None,
Expand Down Expand Up @@ -197,7 +195,6 @@ def inner_wrapper(wrapped_func: T) -> T:
outputs=p_outputs,
side_effects=side_effects,
deprecated=deprecated,
default_nodes=default_nodes,
features=features,
run=wrapped_func,
)
Expand Down
30 changes: 5 additions & 25 deletions backend/src/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
import gc
import time
import uuid
from collections.abc import Awaitable
from concurrent.futures import ThreadPoolExecutor
from typing import Callable, Dict, Iterable, List, Optional, Set, Tuple, TypeVar
from typing import Dict, Iterable, List, Optional, Set

from sanic.log import logger

Expand All @@ -19,6 +18,7 @@
from events import Event, EventQueue, InputsDict
from nodes.base_output import BaseOutput
from progress_controller import Aborted, ProgressController
from util import timed_supplier

Output = List[object]

Expand Down Expand Up @@ -144,9 +144,6 @@ def compute_broadcast(output: Output, node_outputs: Iterable[BaseOutput]):
return data, types


T = TypeVar("T")


class NodeExecutionError(Exception):
def __init__(
self,
Expand All @@ -161,23 +158,6 @@ def __init__(
self.inputs: InputsDict = inputs


def timed_supplier(supplier: Callable[[], T]) -> Callable[[], Tuple[T, float]]:
def wrapper():
start = time.time()
result = supplier()
duration = time.time() - start
return result, duration

return wrapper


async def timed_supplier_async(supplier: Callable[[], Awaitable[T]]) -> Tuple[T, float]:
start = time.time()
result = await supplier()
duration = time.time() - start
return result, duration


class Executor:
"""
Class for executing chaiNNer's processing logic
Expand Down Expand Up @@ -412,7 +392,7 @@ def __get_upstream_nodes(self, node: NodeId) -> Set[NodeId]:
upstream_nodes.extend(self.__get_upstream_nodes(upstream_node))
return set(upstream_nodes)

async def __process_nodes(self, nodes: List[NodeId]):
async def __process_nodes(self):
await self.progress.suspend()

iterator_node_set = set()
Expand Down Expand Up @@ -448,7 +428,7 @@ async def __process_nodes(self, nodes: List[NodeId]):
before_iteration_time = time.time()

# Now run each of the iterators
for iterator_node in nodes:
for iterator_node in self.__get_iterator_nodes():
# Get all downstream nodes of the iterator
# This excludes any nodes that are downstream of a collector, as well as collectors themselves
downstream_nodes = [
Expand Down Expand Up @@ -576,7 +556,7 @@ async def __process_nodes(self, nodes: List[NodeId]):
async def run(self):
logger.debug(f"Running executor {self.execution_id}")
try:
await self.__process_nodes(self.__get_iterator_nodes())
await self.__process_nodes()
finally:
gc.collect()

Expand Down
11 changes: 2 additions & 9 deletions backend/src/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,7 @@
JsonExecutionOptions,
set_execution_options,
)
from process import (
Executor,
NodeExecutionError,
Output,
compute_broadcast,
run_node,
timed_supplier,
)
from process import Executor, NodeExecutionError, Output, compute_broadcast, run_node
from progress_controller import Aborted
from response import (
alreadyRunningResponse,
Expand All @@ -50,6 +43,7 @@
)
from server_config import ServerConfig
from system import is_arm_mac
from util import timed_supplier


class AppContext:
Expand Down Expand Up @@ -132,7 +126,6 @@ async def nodes(_request: Request):
"nodeType": node.type,
"hasSideEffects": node.side_effects,
"deprecated": node.deprecated,
"defaultNodes": node.default_nodes,
"features": node.features,
}
node_list.append(node_dict)
Expand Down
14 changes: 14 additions & 0 deletions backend/src/util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import time
from typing import Callable, Tuple, TypeVar

T = TypeVar("T")


def timed_supplier(supplier: Callable[[], T]) -> Callable[[], Tuple[T, float]]:
def wrapper():
start = time.time()
result = supplier()
duration = time.time() - start
return result, duration

return wrapper
1 change: 0 additions & 1 deletion src/common/common-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ export interface NodeSchema {
readonly inputs: readonly Input[];
readonly outputs: readonly Output[];
readonly groupLayout: readonly (InputId | Group)[];
readonly defaultNodes?: readonly DefaultNode[] | null;
readonly schemaId: SchemaId;
readonly hasSideEffects: boolean;
readonly deprecated: boolean;
Expand Down
68 changes: 29 additions & 39 deletions src/renderer/components/NodeDocumentation/NodeDocs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -376,16 +376,13 @@ interface NodeDocsProps {
schema: NodeSchema;
}
export const NodeDocs = memo(({ schema }: NodeDocsProps) => {
const { schemata, functionDefinitions, categories } = useContext(BackendContext);
const { functionDefinitions, categories } = useContext(BackendContext);

const selectedAccentColor = getCategoryAccentColor(categories, schema.category);

const [isLargerThan1200] = useMediaQuery('(min-width: 1200px)');

const nodeDocsToShow = [
schema,
...(schema.defaultNodes?.map((n) => schemata.get(n.schemaId)) ?? []),
];
const nodeFunctionDefinition = functionDefinitions.get(schema.schemaId);

return (
<Box
Expand All @@ -412,43 +409,36 @@ export const NodeDocs = memo(({ schema }: NodeDocsProps) => {
textAlign="left"
w="full"
>
{nodeDocsToShow.map((nodeSchema) => {
const nodeFunctionDefinition = functionDefinitions.get(
nodeSchema.schemaId
);
return (
<Flex
direction={isLargerThan1200 ? 'row' : 'column'}
gap={4}
key={nodeSchema.schemaId}
<Flex
direction={isLargerThan1200 ? 'row' : 'column'}
gap={4}
key={schema.schemaId}
>
<SingleNodeInfo
accentColor={selectedAccentColor}
functionDefinition={nodeFunctionDefinition}
key={schema.schemaId}
schema={schema}
/>
<Center
h="full"
position="relative"
verticalAlign="top"
>
<Box
maxW="fit-content"
mr={6}
position="relative"
w="auto"
>
<SingleNodeInfo
<NodeExample
accentColor={selectedAccentColor}
functionDefinition={nodeFunctionDefinition}
key={nodeSchema.schemaId}
schema={nodeSchema}
key={schema.schemaId}
selectedSchema={schema}
/>
<Center
h="full"
position="relative"
verticalAlign="top"
>
<Box
maxW="fit-content"
mr={6}
position="relative"
w="auto"
>
<NodeExample
accentColor={selectedAccentColor}
key={nodeSchema.schemaId}
selectedSchema={nodeSchema}
/>
</Box>
</Center>
</Flex>
);
})}
</Box>
</Center>
</Flex>
</VStack>
</Box>
</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,6 @@ const NodeDocumentationModal = memo(() => {
const selectedSchema = schemata.get(selectedSchemaId);

// search
const helperNodeMapping = useMemo(() => {
const mapping = new Map<SchemaId, SchemaId>();
for (const schema of schemata.schemata) {
for (const helper of schema.defaultNodes ?? []) {
mapping.set(helper.schemaId, schema.schemaId);
}
}
return mapping;
}, [schemata]);

const searchIndex = useMemo(() => createSearchIndex(schemata.schemata), [schemata.schemata]);
const [searchQuery, setSearchQuery] = useState('');
const { searchScores, searchTerms } = useMemo(() => {
Expand Down Expand Up @@ -100,16 +90,14 @@ const NodeDocumentationModal = memo(() => {
useEffect(() => {
if (searchScores && searchScores.size > 0) {
const highestScore = Math.max(...searchScores.values());
let highestScoreSchemaId = [...searchScores.entries()].find(
const highestScoreSchemaId = [...searchScores.entries()].find(
([, score]) => score === highestScore
)?.[0];
if (highestScoreSchemaId) {
highestScoreSchemaId =
helperNodeMapping.get(highestScoreSchemaId) ?? highestScoreSchemaId;
openNodeDocumentation(highestScoreSchemaId);
}
}
}, [searchScores, helperNodeMapping, openNodeDocumentation]);
}, [searchScores, openNodeDocumentation]);

return (
<Modal
Expand Down