Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions compiler/src/main/scala/edg/ExprBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,15 @@ object ExprBuilder {
)
}

def RangeEmpty(): lit.ValueLit = {
lit.ValueLit(`type` =
lit.ValueLit.Type.Range(lit.RangeLit(
minimum = Some(Floating(Float.NaN)),
maximum = Some(Floating(Float.NaN))
))
)
}

def Array(values: Seq[lit.ValueLit]): lit.ValueLit = {
lit.ValueLit(`type` =
lit.ValueLit.Type.Array(lit.ArrayLit(
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/main/scala/edg/compiler/Compiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class AssignNamer() {
}

object Compiler {
final val kExpectedProtoVersion = 8
final val kExpectedProtoVersion = 9
}

/** Compiler for a particular design, with an associated library to elaborate references from.
Expand Down
12 changes: 12 additions & 0 deletions compiler/src/main/scala/edg/compiler/ExprEvaluate.scala
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,16 @@ object ExprEvaluate {
binarySet.op match {
// Note promotion rules: range takes precedence, then float, then int
// TODO: can we deduplicate these cases to delegate them to evalBinary?
case Op.EQ => (lhs, rhs) match {
case (lhss: ArrayValue[ExprValue] @unchecked, rhs: ExprValue) =>
val resultElts = lhss.values.map { arrayElt =>
evalBinary(expr.BinaryExpr(op = expr.BinaryExpr.Op.EQ), arrayElt, rhs)
}
ArrayValue(resultElts)
case _ => throw new ExprEvaluateException(
s"Unknown binary set operand types in $lhs ${binarySet.op} $rhs from $binarySet"
)
}
case Op.ADD => (lhs, rhs) match {
case (ArrayValue.ExtractRange(arrayElts), rhs: RangeType) =>
val resultElts = arrayElts.map { arrayElt =>
Expand Down Expand Up @@ -363,6 +373,8 @@ object ExprEvaluate {
evalUnary(expr.UnaryExpr(op = expr.UnaryExpr.Op.NEGATE), arrayElt)
}
ArrayValue(resultElts)
case ArrayValue.ExtractBoolean(arrayElts) =>
ArrayValue(arrayElts.map { arrayElt => BooleanValue(!arrayElt) })
case _ => throw new ExprEvaluateException(s"Unknown unary set operand in ${unarySet.op} $vals from $unarySet")
}

Expand Down
3 changes: 2 additions & 1 deletion compiler/src/main/scala/edg/compiler/ExprToString.scala
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class ExprToString() extends ValueExprMap[String] {
import expr.BinarySetExpr.Op
object InfixOp {
def unapply(op: Op): Option[String] = op match {
case Op.EQ => Some("==")
case Op.ADD => Some("+")
case Op.MULT => Some("×")
case Op.CONCAT => None
Expand All @@ -91,7 +92,7 @@ class ExprToString() extends ValueExprMap[String] {
object PrefixOp {
def unapply(op: Op): Option[String] = op match {
case Op.CONCAT => Some("concat")
case Op.ADD | Op.MULT => None
case Op.EQ | Op.ADD | Op.MULT => None
case Op.UNDEFINED | Op.Unrecognized(_) => None
}
}
Expand Down
26 changes: 26 additions & 0 deletions compiler/src/test/scala/edg/compiler/ExprEvaluateTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,17 @@ class ExprEvaluateTest extends AnyFlatSpec {
it should "handle array unary set ops" in {
import edg.ExprBuilder.Literal
import edgir.expr.expr.UnarySetExpr.Op
evalTest.map(
ValueExpr.UnarySetOp(
Op.NEGATE,
ValueExpr.Literal(Seq(
Literal.Boolean(false),
Literal.Boolean(true),
Literal.Boolean(false),
))
)
) should equal(ArrayValue(Seq(BooleanValue(true), BooleanValue(false), BooleanValue(true))))

evalTest.map(
ValueExpr.UnarySetOp(
Op.FLATTEN,
Expand Down Expand Up @@ -327,6 +338,21 @@ class ExprEvaluateTest extends AnyFlatSpec {
it should "handle array-value (broadcast) ops" in {
import edg.ExprBuilder.Literal
import edgir.expr.expr.BinarySetExpr.Op
evalTest.map(
ValueExpr.BinSetOp(
Op.EQ,
ValueExpr.Literal(Seq(Literal.Range(0, 10), Literal.Range(1, 11))),
ValueExpr.Literal(0, 10)
)
) should equal(ArrayValue(Seq(BooleanValue(true), BooleanValue(false))))
evalTest.map(
ValueExpr.BinSetOp(
Op.EQ,
ValueExpr.Literal(Seq(Literal.Range(0, 10), Literal.RangeEmpty())),
ValueExpr.LiteralRangeEmpty()
)
) should equal(ArrayValue(Seq(BooleanValue(false), BooleanValue(true))))

evalTest.map(
ValueExpr.BinSetOp(
Op.ADD,
Expand Down
7 changes: 0 additions & 7 deletions edg/abstract_parts/Categories.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,13 +384,6 @@ class PassiveComponent(DiscreteComponent):
pass


@abstract_block
class DummyDevice(InternalBlock):
"""Non-physical "device" used to affect parameters."""

pass


@abstract_block
class IdealModel(InternalBlock):
"""Ideal model device that can be used as a placeholder to get a design compiling
Expand Down
25 changes: 0 additions & 25 deletions edg/abstract_parts/DummyDevices.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,6 @@ def __init__(self) -> None:
self.io = self.Port(Passive(), [InOut])


class DummyGround(DummyDevice):
def __init__(self) -> None:
super().__init__()
self.gnd = self.Port(Ground(), [Common, InOut])


class DummyVoltageSource(DummyDevice):
def __init__(self, voltage_out: RangeLike = RangeExpr.ZERO, current_limits: RangeLike = RangeExpr.ALL) -> None:
super().__init__()

self.pwr = self.Port(VoltageSource(voltage_out=voltage_out, current_limits=current_limits), [Power, InOut])

self.current_drawn = self.Parameter(RangeExpr(self.pwr.link().current_drawn))
self.voltage_limits = self.Parameter(RangeExpr(self.pwr.link().voltage_limits))


class DummyVoltageSink(DummyDevice):
def __init__(self, voltage_limit: RangeLike = RangeExpr.ALL, current_draw: RangeLike = RangeExpr.ZERO) -> None:
super().__init__()

self.pwr = self.Port(VoltageSink(voltage_limits=voltage_limit, current_draw=current_draw), [Power, InOut])
self.voltage = self.Parameter(RangeExpr(self.pwr.link().voltage))
self.current_limits = self.Parameter(RangeExpr(self.pwr.link().current_limits))


class DummyDigitalSource(DummyDevice):
def __init__(self, voltage_out: RangeLike = RangeExpr.ZERO, current_limits: RangeLike = RangeExpr.ALL) -> None:
super().__init__()
Expand Down
1 change: 0 additions & 1 deletion edg/abstract_parts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
PartsTableSelectorFootprint,
)

from .Categories import DummyDevice
from .Categories import DiscreteComponent, DiscreteSemiconductor, PassiveComponent
from .Categories import DiscreteApplication
from .Categories import Analog, OpampApplication
Expand Down
8 changes: 8 additions & 0 deletions edg/core/ArrayExpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ def hull(self) -> ArrayEltType:
class ArrayBoolExpr(ArrayExpr[BoolExpr, List[bool], ArrayBoolLike]):
_elt_type = BoolExpr

def __invert__(self) -> ArrayBoolExpr:
return self._new_bind(UnarySetOpBinding(self, BoolOp.op_not))

def any(self) -> BoolExpr:
return BoolExpr()._new_bind(UnarySetOpBinding(self, BoolOp.op_or))

Expand Down Expand Up @@ -179,6 +182,11 @@ def __rtruediv__(self, other: Union[FloatLike, RangeLike]) -> ArrayRangeExpr:
self._create_unary_set_op(NumericOp.invert), RangeExpr._to_expr_type(other), NumericOp.mul
)

def elts_equals(self, other: RangeLike) -> ArrayBoolExpr:
"""Returns an ArrayBoolExpr of equality between each element of this and single-element other.
TODO: generalize to equality for other array types, needs some generic version of _to_expr_type"""
return ArrayBoolExpr()._new_bind(BinarySetOpBinding(self, RangeExpr._to_expr_type(other), EqOp.all_equal))


ArrayStringLike = Union["ArrayStringExpr", Sequence[StringLike]]

Expand Down
4 changes: 3 additions & 1 deletion edg/core/Binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ def __init__(self, src: ConstraintExpr, op: Union[NumericOp, BoolOp, EqOp, Range
NumericOp.sum: edgir.UnarySetExpr.SUM,
BoolOp.op_and: edgir.UnarySetExpr.ALL_TRUE,
BoolOp.op_or: edgir.UnarySetExpr.ANY_TRUE,
BoolOp.op_not: edgir.UnarySetExpr.NEGATE,
EqOp.all_equal: edgir.UnarySetExpr.ALL_EQ,
EqOp.all_unique: edgir.UnarySetExpr.ALL_UNIQUE,
RangeSetOp.min: edgir.UnarySetExpr.MINIMUM,
Expand Down Expand Up @@ -391,11 +392,12 @@ class BinarySetOpBinding(Binding):
def __repr__(self) -> str:
return f"BinaryOp({self.op}, ...)"

def __init__(self, lhset: ConstraintExpr, rhs: ConstraintExpr, op: NumericOp):
def __init__(self, lhset: ConstraintExpr, rhs: ConstraintExpr, op: Union[NumericOp, EqOp]):
self.op_map = {
# Numeric
NumericOp.add: edgir.BinarySetExpr.ADD,
NumericOp.mul: edgir.BinarySetExpr.MULT,
EqOp.all_equal: edgir.BinarySetExpr.EQ,
}

super().__init__()
Expand Down
Binary file modified edg/core/resources/edg-compiler-precompiled.jar
Binary file not shown.
Loading
Loading