phyelds.calculus¶
phyelds.calculus
¶
Core syntax for phyelds. It exposes a set of functions that are used to create and manipulate fields, as well as to manage the state of the system. @aggregate is a decorator that marks a function as an aggregate function, Example: @aggregate def my_function(): # do something return result
Then, there is the core syntax of phyelds: - remember: used to remember a value across iterations. - neighbors: used to get the neighbors of a node. - neighbors_distances: used to get the distances to the neighbors.
aggregate(func)
¶
A decorator for aggregate functions, namely each function that is called in the context of a field. You can use it in the following way: @aggregate def my_function(): # do something return result
remember(init)
¶
remember_and_evolve(init, evolve_fn)
¶
Remember a value across iterations and evolve it using the provided function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
init
|
T
|
Initial value to remember. |
required |
evolve_fn
|
Callable[[State[T]], T]
|
Function to evolve the remembered value. It receives the current State object and should return the new value. |
required |
Returns:
| Type | Description |
|---|---|
State[T]
|
The updated State object. |
neighbors(value)
¶
Get the value of the neighbors from the current node.
Example:
neighbors(context.data["temperature"]) // returns the temperature of the neighbors
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
T
|
used to query the neighbors. |
required |
Returns:
| Type | Description |
|---|---|
NeighborhoodField[T]
|
the neighborhood representing this value containing data of type T |
align_right()
¶
Typically used in if statements to align the code Example: if condition: with align_left(): # do something else: with align_right(): # do something else
Returns:
| Type | Description |
|---|---|
|
|
align_left()
¶
Typically used in if statements to align the code See align_right
___transform_code(func)
¶
Transforms the code of the given function to include alignment contexts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
The function to transform. |
required |
Returns:
| Type | Description |
|---|---|
|
The transformed function. |
str_transformed_code(func)
¶
Utility to print the transformed AST source for a given function.
Useful for debugging how the AggregateTransformer rewrites if statements.