From b5722c04844e4a3ceacf866954024b75c7020ef9 Mon Sep 17 00:00:00 2001 From: Doug Strain Date: Mon, 9 Sep 2024 11:05:01 -0700 Subject: [PATCH] Add warning for build_call_graph returning a set (#1396) * Add warning for build_call_graph returning a set - We changed build_call_graph to return a dictionary as a part #845. - This now emits a deprecation warning now that all the built-in bloqs are converted. * Add DeprecationWarning --------- Co-authored-by: Matthew Harrigan --- qualtran/resource_counting/_call_graph.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/qualtran/resource_counting/_call_graph.py b/qualtran/resource_counting/_call_graph.py index cf3e1923a..8c1a6debd 100644 --- a/qualtran/resource_counting/_call_graph.py +++ b/qualtran/resource_counting/_call_graph.py @@ -15,6 +15,7 @@ """Functionality for the `Bloq.call_graph()` protocol.""" import collections.abc +import warnings from collections import defaultdict from typing import ( Callable, @@ -94,6 +95,11 @@ def _generalize_callees( callee_counts: Dict[Bloq, Union[int, sympy.Expr]] = defaultdict(lambda: 0) if isinstance(raw_callee_counts, set): raw_callee_iterator: Iterable[BloqCountT] = raw_callee_counts + warnings.warn( + "build_call_graph returning sets is deprecated (got {raw_callee_counts})." + "Please change build_call_graph for this bloq to use a dictionary.", + DeprecationWarning, + ) else: raw_callee_iterator = raw_callee_counts.items() for callee, n in raw_callee_iterator: