Skip to content

Commit

Permalink
Some PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
swernli committed Dec 7, 2024
1 parent 4625c6e commit ca59f2c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
8 changes: 4 additions & 4 deletions pip/src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,9 +621,9 @@ fn convert_obj_with_ty(py: Python, obj: &PyObject, ty: &Ty) -> PyResult<Value> {
Pauli::Y => fir::Pauli::Y,
Pauli::Z => fir::Pauli::Z,
})),
Prim::Qubit | Prim::Range | Prim::RangeTo | Prim::RangeFrom | Prim::RangeFull => Err(
PyException::new_err(format!("unhandled primitive input type: {prim_ty:?}")),
),
Prim::Qubit | Prim::Range | Prim::RangeTo | Prim::RangeFrom | Prim::RangeFull => {
unimplemented!("primitive input type: {prim_ty:?}")
}
},
Ty::Tuple(tup) => {
if tup.len() == 1 {
Expand Down Expand Up @@ -653,7 +653,7 @@ fn convert_obj_with_ty(py: Python, obj: &PyObject, ty: &Ty) -> PyResult<Value> {
}
Ok(Value::Array(values.into()))
}
_ => Err(PyException::new_err(format!("unhandled input type: {ty}"))),
_ => unimplemented!("input type: {ty}"),
}
}

Expand Down
20 changes: 17 additions & 3 deletions pip/tests/test_qsharp.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,13 @@ def test_callables_exposed_into_env() -> None:
qsharp.eval("function Add(a : Int, b : Int) : Int { a + b }")
assert qsharp.env.Four() == 4
assert qsharp.env.Add(2, 3) == 5
# After init, the callables should be cleared and no longer available
qsharp.init()
with pytest.raises(AttributeError):
qsharp.env.Four()


def test_callable_exposed_into_env_complex_types() -> None:
qsharp.eval(
"function Complicated(a : Int, b : (Double, BigInt)) : ((Double, BigInt), Int) { (b, a) }"
)
Expand All @@ -393,18 +400,25 @@ def test_callables_exposed_into_env() -> None:
)
qsharp.eval("function Smallest(a : Int[]) : Int { Std.Math.Min(a)}")
assert qsharp.env.Smallest([1, 2, 3, 0, 4, 5]) == 0


def test_callable_exposed_into_env_fails_incorrect_types() -> None:
qsharp.init()
# After init, the callables should be cleared and no longer available
with pytest.raises(AttributeError):
qsharp.env.Four()
qsharp.eval("function Identity(a : Int) : Int { a }")
assert qsharp.env.Identity(4) == 4
with pytest.raises(TypeError):
qsharp.env.Identity("4")
with pytest.raises(TypeError):
qsharp.env.Identity(4.0)


def test_callables_in_namespaces_exposed_into_env_submodules_and_removed_on_reinit() -> (
None
):
qsharp.init()
# callables should be created with their namespaces
qsharp.eval("namespace Test { function Four() : Int { 4 } }")
qsharp.eval("function Identity(a : Int) : Int { a }")
assert qsharp.env.Test.Four() == 4
# should be able to import callables
from qsharp.env import Identity
Expand Down

0 comments on commit ca59f2c

Please sign in to comment.