Skip to content
Merged
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
35 changes: 31 additions & 4 deletions src/qc_compiler/mitigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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)

Expand All @@ -537,6 +551,7 @@ def _execute_pec(
noise_scales=plan.noise_scales,
shots_used=plan.total_shots,
method="pec",
placeholder=True,
)

def _execute_cdr(
Expand All @@ -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)

Expand All @@ -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]:
Expand Down
42 changes: 41 additions & 1 deletion tests/test_mitigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading