Skip to content
Draft
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
8 changes: 3 additions & 5 deletions source/qdk_package/src/interpreter/data_interop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,12 +396,10 @@ fn check_callable_types(
fn callable_type_accepts(expected: &Ty, actual: &Ty) -> bool {
match (expected, actual) {
(Ty::Arrow(expected), Ty::Arrow(actual)) => {
// ISSUE #4222: Python callable inputs skip functor validation
// Uncomment these two lines and the third below once the corresponding qdk-chemistry fix has shipped
// let required = expected.functors.borrow().expect_value("resolved functors");
// let available = actual.functors.borrow().expect_value("resolved functors");
let required = expected.functors.borrow().expect_value("resolved functors");
let available = actual.functors.borrow().expect_value("resolved functors");
expected.kind == actual.kind
// && available.intersect(&required) == required
&& available.intersect(&required) == required
&& callable_type_accepts(&actual.input.borrow(), &expected.input.borrow())
&& callable_type_accepts(&expected.output.borrow(), &actual.output.borrow())
}
Expand Down
12 changes: 4 additions & 8 deletions source/qdk_package/tests/test_callable_passing.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
def test_adaptive_fallback_callable_warning() -> None:
ctx = qdk.Context(target_profile=qsharp.TargetProfile.Adaptive)
ctx.eval(ADAPTIVE_FALLBACK_SOURCE)
with pytest.warns(
UserWarning, match="Qdk.Qsc.Codegen.AdaptiveProfileFallback"
) as caught:
with pytest.warns(UserWarning, match="Qdk.Qsc.Codegen.AdaptiveProfileFallback") as caught:
program = str(ctx.compile(ctx.code.Main))
assert len(caught) == 1
assert run_qir(program, shots=1, type="cpu") == [(13, [qsharp.Result.Zero] * 3)]
Expand Down Expand Up @@ -388,17 +386,15 @@ def _write_entry_project(root: Path, source: str) -> None:
("(Int, Int -> Int)", (7, "WrongOutput"), False),
("Config", {"Callback": "WrongOutput"}, False),
("Qubit => Unit is Adj", "Strong", True),
# ISSUE #4222: Python callable inputs skip functor validation
# Uncomment the three test cases below once the validation is re-enabled.
# ("Qubit => Unit is Adj", "Plain", False),
("Qubit => Unit is Adj", "Plain", False),
("Qubit => Unit is Adj", "Adjoint Strong", True),
("(Qubit[], Qubit) => Unit is Adj", "Controlled Strong", True),
("Qubit => Unit", "Controlled Strong", False),
("(Qubit[], (Qubit[], Qubit)) => Unit", "Controlled Controlled Strong", True),
("(Qubit => Unit is Adj + Ctl) => Unit", "ReadAdjoint", True),
# ("(Qubit => Unit) => Unit", "ReadAdjoint", False),
("(Qubit => Unit) => Unit", "ReadAdjoint", False),
("Unit -> (Qubit => Unit is Adj)", "Factory", True),
# ("Unit -> (Qubit => Unit is Adj + Ctl)", "WeakFactory", False),
("Unit -> (Qubit => Unit is Adj + Ctl)", "WeakFactory", False),
],
)
def test_callable_argument_signature_compatibility(
Expand Down