Skip to content

Commit ef4f5cd

Browse files
committed
Merge branch 'main' into pdl-299
Signed-off-by: Louis Mandel <[email protected]>
2 parents 516c6a8 + 6200a71 commit ef4f5cd

File tree

6 files changed

+42
-24
lines changed

6 files changed

+42
-24
lines changed

pdl-live-react/src/pdl_ast.d.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2354,6 +2354,11 @@ export type PdlContext17 =
23542354
export type PdlId17 = string | null
23552355
export type PdlIsLeaf17 = true
23562356
export type Kind17 = "model"
2357+
/**
2358+
* Model name used by the backend.
2359+
*
2360+
*/
2361+
export type Model = LocalizedExpression | string
23572362
/**
23582363
* Messages to send to the model.
23592364
*
@@ -2411,11 +2416,6 @@ export type Backend =
24112416
| {
24122417
[k: string]: unknown
24132418
}
2414-
/**
2415-
* IO Processor name.
2416-
*
2417-
*/
2418-
export type Processor = LocalizedExpression | string | null
24192419
/**
24202420
* Parameters sent to the model.
24212421
*
@@ -3210,7 +3210,7 @@ export interface GraniteioModelBlock {
32103210
pdl__timing?: PdlTiming | null
32113211
pdl__is_leaf?: PdlIsLeaf17
32123212
kind?: Kind17
3213-
model: unknown
3213+
model: Model
32143214
input?: Input
32153215
modelResponse?: Modelresponse
32163216
/**
@@ -3221,7 +3221,7 @@ export interface GraniteioModelBlock {
32213221
pdl__model_input?: PdlModelInput
32223222
platform?: Platform
32233223
backend: Backend
3224-
processor?: Processor
3224+
processor?: unknown
32253225
parameters?: Parameters
32263226
}
32273227
/**

pdl-live-react/src/pdl_ast_utils.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { match, P } from "ts-pattern"
22

3-
import { Backend, PdlBlock, Processor } from "./pdl_ast"
3+
import { Backend, PdlBlock } from "./pdl_ast"
44
import { ExpressionT, isArgs } from "./helpers"
55

66
export function map_block_children(
@@ -74,10 +74,7 @@ export function map_block_children(
7474
: undefined
7575
// @ts-expect-error: f_expr does not preserve the type of the expression
7676
const backend: Backend = f_expr(block.backend)
77-
// @ts-expect-error: f_expr does not preserve the type of the expression
78-
const processor: Processor = block.processor
79-
? f_expr(block.processor)
80-
: undefined
77+
const processor = block.processor ? f_expr(block.processor) : undefined
8178
return {
8279
...block,
8380
model,

src/pdl/pdl-schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4461,7 +4461,6 @@
44614461
{
44624462
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
44634463
},
4464-
{},
44654464
{
44664465
"type": "string"
44674466
}
@@ -4626,6 +4625,7 @@
46264625
{
46274626
"type": "string"
46284627
},
4628+
{},
46294629
{
46304630
"type": "null"
46314631
}

src/pdl/pdl_ast.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ class GraniteioModelBlock(ModelBlock):
548548
platform: Literal[ModelPlatform.GRANITEIO] = ModelPlatform.GRANITEIO
549549
"""Optional field to ensure that the block is using granite-io.
550550
"""
551-
model: ExpressionType[object]
551+
model: ExpressionType[str]
552552
"""Model name used by the backend.
553553
"""
554554
backend: ExpressionType[str | dict[str, Any] | object]

src/pdl/pdl_granite_io.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def processor_of_block(block: GraniteioModelBlock):
2626
processor = value_of_expr(block.processor)
2727
if isinstance(processor, InputOutputProcessor):
2828
return processor
29-
model = value_of_expr(block.model)
29+
model: str = value_of_expr(block.model)
3030
backend = value_of_expr(block.backend)
3131
assert isinstance(model, str), f"The model should be a string: {model}"
3232
match backend:

src/pdl/pdl_interpreter.py

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
)
9797
from .pdl_context import ( # noqa: E402
9898
DependentContext,
99+
IndependentContext,
99100
PDLContext,
100101
SerializeMode,
101102
SingletonContext,
@@ -359,7 +360,11 @@ def set_error_to_scope_for_retry(
359360
"content": error,
360361
"defsite": block_id,
361362
}
362-
scope = scope | {"pdl_context": pdl_context * SingletonContext(PdlDict(err_msg))}
363+
scope = scope | {
364+
"pdl_context": DependentContext(
365+
[pdl_context, SingletonContext(PdlDict(err_msg))]
366+
)
367+
}
363368
return scope
364369

365370

@@ -605,9 +610,13 @@ def process_block_body(
605610
append(obj_loc, k),
606611
)
607612
if block.context == IndependentEnum.DEPENDENT:
608-
background = background * value_background
613+
background = DependentContext(
614+
[background, value_background]
615+
)
609616
else:
610-
background = background + value_background
617+
background = IndependentContext(
618+
[background, value_background]
619+
)
611620
if (
612621
block.context is IndependentEnum.INDEPENDENT
613622
): # reset pdl_context
@@ -829,7 +838,9 @@ def process_block_body(
829838
}
830839
]
831840
)
832-
scope = scope | {"pdl_context": pdl_context_init * background}
841+
scope = scope | {
842+
"pdl_context": DependentContext([pdl_context_init, background])
843+
}
833844
if items is not None:
834845
for k in items.keys():
835846
scope = scope | {k: items[k][iidx]}
@@ -845,9 +856,13 @@ def process_block_body(
845856
repeat_loc,
846857
)
847858
if block.context is IndependentEnum.DEPENDENT:
848-
saved_background = saved_background * iteration_background
859+
saved_background = DependentContext(
860+
[saved_background, iteration_background]
861+
)
849862
else:
850-
saved_background = saved_background + iteration_background
863+
saved_background = IndependentContext(
864+
[saved_background, iteration_background]
865+
)
851866

852867
if block.context is IndependentEnum.DEPENDENT:
853868
background = saved_background
@@ -1088,7 +1103,9 @@ def process_blocks( # pylint: disable=too-many-arguments,too-many-positional-ar
10881103
try:
10891104
for i, block in enumerate(blocks):
10901105
iteration_state = iteration_state.with_iter(i)
1091-
scope = scope | {"pdl_context": pdl_context_init * background}
1106+
scope = scope | {
1107+
"pdl_context": DependentContext([pdl_context_init, background])
1108+
}
10921109
new_loc = append(loc, "[" + str(i) + "]")
10931110
if iteration_type == IterationType.LASTOF and state.yield_result:
10941111
iteration_state = state.with_yield_result(i + 1 == len(blocks))
@@ -1100,9 +1117,13 @@ def process_blocks( # pylint: disable=too-many-arguments,too-many-positional-ar
11001117
) = process_block(iteration_state, scope, block, new_loc)
11011118
results.append(iteration_result)
11021119
if context == IndependentEnum.DEPENDENT:
1103-
saved_background = saved_background * iteration_background
1120+
saved_background = DependentContext(
1121+
[saved_background, iteration_background]
1122+
)
11041123
else:
1105-
saved_background = saved_background + iteration_background
1124+
saved_background = IndependentContext(
1125+
[saved_background, iteration_background]
1126+
)
11061127

11071128
if context == IndependentEnum.DEPENDENT:
11081129
background = saved_background

0 commit comments

Comments
 (0)