Skip to content

Commit cee79cd

Browse files
committed
Add fallback for unsupported reward function
1 parent 9a40b3e commit cee79cd

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/mqt/predictor/rl/predictorenv.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,12 +302,20 @@ def calculate_reward(self, qc: QuantumCircuit | None = None, mode: str = "auto")
302302
if qc is None:
303303
qc = self.state
304304

305-
# Only these two reward functions support both exact and approximate paths.
305+
# Reward functions that are always computed exactly, regardless of `mode`.
306306
if self.reward_function not in {"expected_fidelity", "estimated_success_probability"}:
307307
if self.reward_function == "critical_depth":
308308
return crit_depth(qc), "exact"
309-
msg = f"Unsupported reward function: {self.reward_function}"
310-
raise RuntimeError(msg)
309+
# Fallback for other unknown / not-yet-implemented reward functions:
310+
logger.warning(
311+
"Reward function '%s' is not supported in PredictorEnv. Returning 0.0 as a fallback reward.",
312+
self.reward_function,
313+
)
314+
return 0.0, "exact"
315+
316+
# ------------------------------------------------------------------
317+
# From here on: dual-path rewards (exact vs approx) for EF / ESP.
318+
# ------------------------------------------------------------------
311319

312320
# Decide which path to use (exact vs approx)
313321
if mode == "exact":

0 commit comments

Comments
 (0)