Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
Rutefig/237 fix python front end (#240)
Browse files Browse the repository at this point in the history
  • Loading branch information
rutefig authored May 8, 2024
1 parent c81ab28 commit 93282e0
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 163 deletions.
3 changes: 0 additions & 3 deletions src/frontend/dsl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,15 +600,12 @@ mod tests {
}

#[test]
#[ignore]
#[should_panic(expected = "Signal not found")]
fn test_expose_non_existing_signal() {
let mut context = setup_circuit_context::<i32, i32>();
let non_existing_signal =
Queriable::Forward(ForwardSignal::new_with_phase(0, "".to_owned()), false); // Create a signal not added to the circuit
context.expose(non_existing_signal, ExposeOffset::First);

todo!("remove the ignore after fixing the check for non existing signals")
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/python/chiquito/cb.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations
from dataclasses import dataclass, field
from enum import Enum, auto
from typing import List, Dict, Optional
from typing import List, Dict, Optional, Union

from chiquito.util import F, uuid
from chiquito.expr import Expr, Const, Neg, to_expr, ToExpr
Expand Down Expand Up @@ -205,7 +205,7 @@ def table() -> LookupTable:
return LookupTable()


ToConstraint = Constraint | Expr | int | F
ToConstraint = Union[Constraint, Expr, int, F]


def to_constraint(v: ToConstraint) -> Constraint:
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/python/chiquito/chiquito_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def __json__(self: ASTCircuit):
"last_step": self.last_step,
"num_steps": self.num_steps,
"q_enable": self.q_enable,
"id": self.id,
"id": self.id.__str__(),
}

def add_forward(self: ASTCircuit, name: str, phase: int) -> ForwardSignal:
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/python/chiquito/dsl.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import annotations
from typing import List, Dict
from typing import List, Dict, Union
from enum import Enum
from typing import Callable, Any

Expand Down Expand Up @@ -295,4 +295,4 @@ def add_lookup(self: StepType, lookup_builder: LookupBuilder):
self.step_type.lookups.append(lookup)


LookupBuilder = LookupTableBuilder | InPlaceLookupBuilder
LookupBuilder = Union[LookupTableBuilder, InPlaceLookupBuilder]
4 changes: 2 additions & 2 deletions src/frontend/python/chiquito/expr.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import annotations
from typing import List
from typing import List, Union
from dataclasses import dataclass

from chiquito.util import F
Expand Down Expand Up @@ -141,7 +141,7 @@ def __json__(self):
return {"Pow": [self.expr.__json__(), self.pow]}


ToExpr = Expr | int | F
ToExpr = Union[Expr, int, F]


def to_expr(v: ToExpr) -> Expr:
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/python/chiquito/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,5 @@ def __str__(self: ASTStepType) -> str:

def __json__(self):
return {
"StepTypeNext": {"id": self.step_type.id, "annotation": self.step_type.name}
"StepTypeNext": {"id": f"{self.step_type.id}", "annotation": self.step_type.name}
}
12 changes: 5 additions & 7 deletions src/frontend/python/chiquito/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ def __json__(self: F):
# Convert the integer to a byte array
montgomery_form = self.n * R % F.field_modulus
byte_array = montgomery_form.to_bytes(32, "little")
# Split into four 64-bit integers
ints = [
int.from_bytes(byte_array[i * 8 : i * 8 + 8], "little") for i in range(4)
]
return ints

# return the hex string
return byte_array.hex()


class CustomEncoder(json.JSONEncoder):
Expand All @@ -29,5 +27,5 @@ def default(self, obj):


# int field is the u128 version of uuid.
def uuid() -> int:
return uuid1(node=int.from_bytes([10, 10, 10, 10, 10, 10], byteorder="little")).int
def uuid() -> str:
return uuid1(node=int.from_bytes([10, 10, 10, 10, 10, 10], byteorder="little")).int.__str__()
2 changes: 1 addition & 1 deletion src/frontend/python/chiquito/wit_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __str__(self: StepInstance):
# For assignments, return "uuid: (Queriable, F)" rather than "Queriable: F", because JSON doesn't accept Dict as key.
def __json__(self: StepInstance):
return {
"step_type_uuid": self.step_type_uuid,
"step_type_uuid": self.step_type_uuid.__str__(),
"assignments": {
lhs.uuid(): [lhs, rhs] for (lhs, rhs) in self.assignments.items()
},
Expand Down
Loading

0 comments on commit 93282e0

Please sign in to comment.