Skip to content

Commit bfa2331

Browse files
authored
Don't reject non-const duration in constructors. (#14009)
Originally, I thought it'd make the most sense to reject construction of operations that'd have a duration type but also be non-const expressions. But, a user can currently create a `Var` with a duration type, so this seems like an incomplete restriction.
1 parent 07e61c8 commit bfa2331

2 files changed

Lines changed: 0 additions & 24 deletions

File tree

qiskit/circuit/classical/expr/constructors.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -683,16 +683,8 @@ def mul(left: typing.Any, right: typing.Any) -> Expr:
683683
left = _coerce_lossless(left, type)
684684
right = _coerce_lossless(right, type)
685685
elif left.type.kind is types.Duration and right.type.kind in {types.Uint, types.Float}:
686-
if not right.const:
687-
raise ValueError(
688-
f"multiplying operands '{left}' and '{right}' would result in a non-const '{left.type}'"
689-
)
690686
type = left.type
691687
elif right.type.kind is types.Duration and left.type.kind in {types.Uint, types.Float}:
692-
if not left.const:
693-
raise ValueError(
694-
f"multiplying operands '{left}' and '{right}' would result in a non-const '{right.type}'"
695-
)
696688
type = right.type
697689
else:
698690
raise TypeError(f"invalid types for '{Binary.Op.MUL}': '{left.type}' and '{right.type}'")
@@ -761,10 +753,6 @@ def div(left: typing.Any, right: typing.Any) -> Expr:
761753
left = _coerce_lossless(left, type)
762754
right = _coerce_lossless(right, type)
763755
elif left.type.kind is types.Duration and right.type.kind in {types.Uint, types.Float}:
764-
if not right.const:
765-
raise ValueError(
766-
f"division of '{left}' and '{right}' would result in a non-const '{left.type}'"
767-
)
768756
type = left.type
769757
else:
770758
raise TypeError(f"invalid types for '{Binary.Op.DIV}': '{left.type}' and '{right.type}'")

test/python/circuit/classical/test_expr_constructors.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -808,13 +808,6 @@ def test_mul_forbidden(self):
808808
with self.assertRaisesRegex(TypeError, "cannot multiply two durations"):
809809
expr.mul(Duration.dt(1000), Duration.dt(1000))
810810

811-
# Multiply timing expressions by non-const floats:
812-
non_const_float = expr.Var.new("a", types.Float())
813-
with self.assertRaisesRegex(ValueError, "would result in a non-const"):
814-
expr.mul(Duration.dt(1000), non_const_float)
815-
with self.assertRaisesRegex(ValueError, "would result in a non-const"):
816-
expr.mul(non_const_float, Duration.dt(1000))
817-
818811
def test_div_explicit(self):
819812
cr = ClassicalRegister(8, "c")
820813

@@ -924,8 +917,3 @@ def test_div_forbidden(self):
924917
expr.div(255.0, 1)
925918
with self.assertRaisesRegex(TypeError, "invalid types"):
926919
expr.div(255.0, Duration.dt(1000))
927-
928-
# Divide timing expressions by non-const floats:
929-
non_const_float = expr.Var.new("a", types.Float())
930-
with self.assertRaisesRegex(ValueError, "would result in a non-const"):
931-
expr.div(Duration.dt(1000), non_const_float)

0 commit comments

Comments
 (0)