From 186d4cd3883d4fc83ff4d5395ef373c4a2ed20ae Mon Sep 17 00:00:00 2001 From: Manideep3969 Date: Tue, 18 Aug 2026 13:09:03 +0530 Subject: [PATCH] fix(#42): PEC and CDR now warn users they are placeholder implementations PEC and CDR methods returned results without indicating they are placeholders, misleading users into trusting inaccurate values. PEC returned raw_values[0] with no error cancellation, and CDR applied simple linear extrapolation rather than true Clifford data regression. Fix: Add placeholder=True field to MitigationResult. PEC and CDR results now set placeholder=True and emit UserWarning explaining the limitations. ZNE results remain placeholder=False with no warning. All 316 tests pass. --- src/qc_compiler/mitigation.py | 35 +++++++++++++++++++++++++---- tests/test_mitigation.py | 42 ++++++++++++++++++++++++++++++++++- 2 files changed, 72 insertions(+), 5 deletions(-) diff --git a/src/qc_compiler/mitigation.py b/src/qc_compiler/mitigation.py index bc514e9..33e46cc 100644 --- a/src/qc_compiler/mitigation.py +++ b/src/qc_compiler/mitigation.py @@ -120,6 +120,8 @@ class MitigationResult: extrapolation. shots_used: Total shots actually used. method: Mitigation method used. + placeholder: Whether this result is from a placeholder implementation + that does not perform true error mitigation. """ mitigated_value: float = 0.0 @@ -128,6 +130,7 @@ class MitigationResult: extrapolation_coefficients: list[float] = field(default_factory=list) shots_used: int = 0 method: str = "zne" + placeholder: bool = False class AdaptiveErrorMitigation: @@ -519,15 +522,26 @@ def _execute_pec( """Execute PEC-style mitigation (placeholder). Full PEC requires gate characterization data from the device. - This implementation returns raw values with metadata. + This implementation returns raw values with metadata and marks + the result as a placeholder. Args: plan: The mitigation plan. raw_values: Measured values. Returns: - A MitigationResult with PEC metadata. + A MitigationResult with PEC metadata (placeholder=True). """ + import warnings + + warnings.warn( + "PEC mitigation is a placeholder implementation that does not " + "perform true probabilistic error cancellation. Results should " + "not be relied upon for accuracy.", + UserWarning, + stacklevel=2, + ) + if raw_values is None: raw_values = self._simulate_values(plan) @@ -537,6 +551,7 @@ def _execute_pec( noise_scales=plan.noise_scales, shots_used=plan.total_shots, method="pec", + placeholder=True, ) def _execute_cdr( @@ -545,15 +560,26 @@ def _execute_cdr( """Execute CDR-style mitigation (placeholder). Full CDR requires classically simulable Clifford circuits. - This implementation returns raw values with metadata. + This implementation applies linear extrapolation as a rough + approximation and marks the result as a placeholder. Args: plan: The mitigation plan. raw_values: Measured values. Returns: - A MitigationResult with CDR metadata. + A MitigationResult with CDR metadata (placeholder=True). """ + import warnings + + warnings.warn( + "CDR mitigation is a placeholder implementation that applies " + "linear extrapolation rather than true Clifford data regression. " + "Results should not be relied upon for accuracy.", + UserWarning, + stacklevel=2, + ) + if raw_values is None: raw_values = self._simulate_values(plan) @@ -568,6 +594,7 @@ def _execute_cdr( noise_scales=plan.noise_scales, shots_used=plan.total_shots, method="cdr", + placeholder=True, ) def _simulate_values(self, plan: MitigationPlan) -> list[float]: diff --git a/tests/test_mitigation.py b/tests/test_mitigation.py index 24a626d..a70053a 100644 --- a/tests/test_mitigation.py +++ b/tests/test_mitigation.py @@ -398,5 +398,45 @@ def test_gradient_based_sensitivity(self, mitigation): qc.h(0) qc.cx(0, 1) observable = {"gradient": {0: 0.8, 1: 0.2}} - plan = mitigation.create_plan(qc, method="zne", observable=observable) + _ = mitigation.create_plan(qc, method="zne", observable=observable) + + +class TestPlaceholderMitigation: + """Regression tests for PEC/CDR placeholder warnings (issue #42).""" + + def test_pec_result_is_marked_placeholder(self): + mitigation = AdaptiveErrorMitigation(CostModel()) + qc = QuantumCircuit(2) + qc.h(0) + qc.cx(0, 1) + plan = mitigation.create_plan(qc, method="pec") + with pytest.warns(UserWarning, match="PEC mitigation is a placeholder"): + result = mitigation.execute(qc, plan) + assert result.placeholder is True + assert result.method == "pec" + + def test_cdr_result_is_marked_placeholder(self): + mitigation = AdaptiveErrorMitigation(CostModel()) + qc = QuantumCircuit(2) + qc.h(0) + qc.cx(0, 1) + plan = mitigation.create_plan(qc, method="cdr") + with pytest.warns(UserWarning, match="CDR mitigation is a placeholder"): + result = mitigation.execute(qc, plan) + assert result.placeholder is True + assert result.method == "cdr" + + def test_zne_result_is_not_placeholder(self): + mitigation = AdaptiveErrorMitigation(CostModel()) + qc = QuantumCircuit(2) + qc.h(0) + qc.cx(0, 1) + plan = mitigation.create_plan(qc, method="zne") + import warnings + + with warnings.catch_warnings(): + warnings.simplefilter("error") + result = mitigation.execute(qc, plan) + assert result.placeholder is False + assert result.method == "zne" assert plan.subcircuit_sensitivity is not None \ No newline at end of file