This repository has been archived by the owner on Jul 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
Lazy config evaluation #64
Draft
elijahbenizzy
wants to merge
1
commit into
main
Choose a base branch
from
lazy-config-evaluation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,11 +5,12 @@ | |
|
||
Note: one should largely consider the code in this module to be "private". | ||
""" | ||
import collections | ||
import inspect | ||
import logging | ||
import typing | ||
from types import ModuleType | ||
from typing import Type, Dict, Any, Callable, Tuple, Set, Collection, List | ||
from typing import Type, Dict, Any, Callable, Tuple, Set, Collection, List, Mapping | ||
|
||
import hamilton.function_modifiers_base | ||
from hamilton import node | ||
|
@@ -310,10 +311,10 @@ def dfs_traverse(node: node.Node): | |
|
||
@staticmethod | ||
def execute_static(nodes: Collection[node.Node], | ||
inputs: Dict[str, Any], | ||
inputs: Mapping[str, Any], | ||
adapter: base.HamiltonGraphAdapter, | ||
computed: Dict[str, Any] = None, | ||
overrides: Dict[str, Any] = None): | ||
computed: Mapping[str, Any] = None, | ||
overrides: Mapping[str, Any] = None): | ||
"""Executes computation on the given graph, inputs, and memoized computation. | ||
|
||
Effectively this is a "private" function and should be viewed as such. | ||
|
@@ -369,7 +370,7 @@ def dfs_traverse(node: node.Node, dependency_type: DependencyType = DependencyTy | |
return computed | ||
|
||
@staticmethod | ||
def combine_config_and_inputs(config: Dict[str, Any], inputs: Dict[str, Any]) -> Dict[str, Any]: | ||
def combine_config_and_inputs(config: Mapping[str, Any], inputs: Mapping[str, Any]) -> typing.Mapping[str, Any]: | ||
"""Validates and combines config and inputs, ensuring that they're mutually disjoint. | ||
:param config: Config to construct, run the DAG with. | ||
:param inputs: Inputs to run the DAG on at runtime | ||
|
@@ -379,7 +380,7 @@ def combine_config_and_inputs(config: Dict[str, Any], inputs: Dict[str, Any]) -> | |
duplicated_inputs = [key for key in inputs if key in config] | ||
if len(duplicated_inputs) > 0: | ||
raise ValueError(f'The following inputs are present in both config and inputs. They must be mutually disjoint. {duplicated_inputs}') | ||
return {**config, **inputs} | ||
return collections.ChainMap(config, inputs) | ||
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. does the unit test need to change to enforce chain map's way of not evaluating things? 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. Yeah, if the contract is that we don't evaluate the driver then we want to test that its not evaluated. That said, I don't really like that as a contract, and it feels limiting later on, so let's think through. |
||
|
||
def execute(self, | ||
nodes: Collection[node.Node] = None, | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
do these need to change?
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.
No, but I figured it would be nice to stay consistent.