Skip to content

Commit

Permalink
refactor!: Convert local_variables from list of strings to dictionary (
Browse files Browse the repository at this point in the history
…#106)

* Convert local_variables from list of strings to dictionary

* Update example used in docs

* Add test cases
  • Loading branch information
dexter2206 authored Jul 9, 2024
1 parent 25618f4 commit 62697e0
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
6 changes: 3 additions & 3 deletions docs/examples/alias_sampling.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ program:
- input_params:
- L
local_variables:
- R=ceiling(log_2(L))
R: ceiling(log_2(L))
name: usp
ports:
- direction: input
Expand Down Expand Up @@ -33,7 +33,7 @@ program:
- L
- mu
local_variables:
- R=ceiling(log_2(L))
R: ceiling(log_2(L))
name: qrom
ports:
- direction: input
Expand Down Expand Up @@ -168,7 +168,7 @@ program:
- qrom.mu
- compare.mu
local_variables:
- R=ceiling(log_2(L))
R: ceiling(log_2(L))
name: alias_sampling
ports:
- direction: input
Expand Down
2 changes: 1 addition & 1 deletion src/qref/schema_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class RoutineV1(BaseModel):
resources: Annotated[list[ResourceV1], _name_sorter] = Field(default_factory=list)
connections: Annotated[list[ConnectionV1], _source_sorter] = Field(default_factory=list)
input_params: list[_OptionallyMultiNamespacedName] = Field(default_factory=list)
local_variables: list[str] = Field(default_factory=list)
local_variables: dict[str, str] = Field(default_factory=dict)
linked_params: Annotated[list[ParamLinkV1], _source_sorter] = Field(default_factory=list)
meta: dict[str, Any] = Field(default_factory=dict)

Expand Down
11 changes: 10 additions & 1 deletion tests/qref/data/invalid_yaml_programs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,13 @@
description: "Target of a paramater link is not namespaced"
error_path: "$.program.linked_params[0].targets[0]"
error_message: "'N' does not match '^([A-Za-z_][A-Za-z0-9_]*\\\\.)+[A-Za-z_][A-Za-z0-9_]*$'"

- input:
version: v1
program:
name: "root"
input_params:
- N
local_variables: ["R = N+1"]
description: Routine uses old format for local_variables
error_path: "$.program.local_variables"
error_message: "['R = N+1'] is not of type 'object'"
18 changes: 18 additions & 0 deletions tests/qref/data/valid_programs/example_5.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
description: Program with local variables
input:
program:
input_params:
- N
- M
name: root
ports:
- direction: input
name: in_0
size: N
- direction: output
name: out_0
size: 2
local_variables:
L: ceil(N/2)
R: M+2
version: v1

0 comments on commit 62697e0

Please sign in to comment.