mqt.ionshuttler.linear.dd

Dynamical-decoupling methods for Linear schedules.

Submodules

Package Contents

class CriticalSegment[source]

Describe one interval over which longitudinal phase remains comparable.

ion: int
index: int
start: int
end: int
positions: tuple[int, ...]
toggling_signs: tuple[int, ...]
sensitivities: tuple[float, ...]
phase: float
boundary_gate: str | None = None
property squared_phase: float

This segment’s normalized squared-phase objective.

class CriticalSegmentResult[source]

Contain logic-aware normalized-phase replay over critical segments.

phase_cost is a schedule-ranking surrogate: the sum of squared normalized segment phases. It is not a joint-coherence decay exponent or a complete circuit-error model.

segments: tuple[CriticalSegment, ...]
phase_per_ion: Mapping[int, float]
squared_phase_per_ion: Mapping[int, float]
phase_cost: float = 0.0
sensitivity_profile: tuple[float, ...] = ()
dt: float = 1.0
__post_init__() → None[source]

Freeze nested per-ion results.

compute_critical_segments(schedule: Schedule, architecture: LinearArchitecture, *, sensitivity_profile: FieldProfile | None = None, dt: float = 1.0, segmentation: SegmentationMode = 'critical', local_pulse_action_ids: frozenset[int] = frozenset()) → CriticalSegmentResult[source]

Replay ion-local segments and their normalized squared-phase proxy.

Returns:

The reconstructed critical segments and their phase objective.

Raises:

ValueError – If the analysis parameters or architecture metadata are invalid.

gate_z_effect(action: Action, ion: int) → int | None[source]

Return a preserving gate’s Z sign, or None for a mixing gate.

Raises:

TypeError – If action is not a supported algorithmic gate.

normalized_sensitivity_values(architecture: LinearArchitecture, profile: FieldProfile | None = None) → tuple[float, ...][source]

Return a nonnegative dimensionless sensitivity envelope with unit RMS.

Raises:

ValueError – If the profile does not match the architecture or cannot be normalized.

class GlobalDDConfig[source]

Configure a periodic sequence of schedule-wide global X pulses.

Shift optimization minimizes the logic-aware critical-segment phase cost shared with SADD.

spacing: int
shift_range: int = 0
half_first_window: bool = True
pulse: GateSpec
scheme_name: str = 'periodic_x'
__post_init__() → None[source]

Validate periodic placement and optional shift optimization.

Raises:
  • TypeError – If a configuration value has the wrong type.

  • ValueError – If a value or pulse lies outside the supported domain.

class GlobalDDReport[source]

Summarize the selected global pulse sequence and phase cost.

report_type: ClassVar[str] = 'periodic_global_dd'
scheme_name: str
pulse_timesteps: tuple[int, ...]
spacing: int
phase_cost: float
__post_init__() → None[source]

Freeze pulse positions and validate their ordering.

Raises:
  • TypeError – If a report value has the wrong type.

  • ValueError – If a report value is outside its supported range.

to_dict() → dict[str, object][source]

Return this report using JSON-compatible values.

classmethod from_dict(data: object) → GlobalDDReport[source]

Restore a global-DD report from JSON-compatible values.

Returns:

The restored global-DD report.

Raises:

ValueError – If the serialized report is malformed.

apply_periodic_global_dd(schedule: Schedule, architecture: LinearArchitecture, config: GlobalDDConfig) → DDPassResult[GlobalDDReport][source]

Insert periodic global X pulses, optionally shifting them by phase cost.

Each pulse is a GlobalGate whose targets are all ions of the schedule. Global pulses are placed before all existing actions at the same schedule boundary and may overlap local gates or transport under the global-frame abstraction.

Returns:

The transformed schedule and selected pulse/phase summary.

Raises:

ValueError – If the architecture does not support global pulses, replay metadata is absent, or global pulses already exist.

class IdealizedHahnConfig[source]

Configure the idealized full-control Hahn reference.

The comparator permits local pulses at every ion position and concurrently with transport or other operations. Its output is therefore a reference schedule, not necessarily an executable schedule for the given hardware.

By default the sequence is a single midpoint pulse and the resulting Pauli frame persists past its window, to be discharged virtually by a consumer that corrects the terminal frame. Set include_terminating_pulse to insert the physical closing pulse that returns the frame to the identity instead.

scheme: str | DDScheme = 'hahn'
min_idle_timesteps: int | None = None
label: str = 'IdealizedHahn'
include_terminating_pulse: bool = False
__post_init__() → None[source]

Validate the reference sequence configuration.

Raises:
  • TypeError – If a configuration value has the wrong type.

  • ValueError – If a configuration value is outside its supported range.

class IdealizedHahnReport[source]

Summarize local pulse sequences inserted by the idealized reference.

report_type: ClassVar[str] = 'idealized_hahn'
sequences: tuple[LocalDDSequence, ...] = ()
__post_init__() → None[source]

Freeze and validate insertion records.

Raises:

TypeError – If an item is not a local DD insertion record.

to_dict() → dict[str, object][source]

Return this report using JSON-compatible values.

classmethod from_dict(data: object) → IdealizedHahnReport[source]

Restore an idealized-Hahn report from JSON-compatible values.

Returns:

The restored report.

Raises:

ValueError – If the serialized report is malformed.

apply_idealized_hahn(schedule: Schedule, architecture: LinearArchitecture, config: IdealizedHahnConfig | None = None) → DDPassResult[IdealizedHahnReport][source]

Insert constraint-relaxed Hahn pulses into every eligible idle window.

Pulse positions are rounded to schedule boundaries, clamped to their idle window, and deduplicated by boundary while retaining sequence order. The default single-pulse sequence leaves a persistent Pauli frame; see IdealizedHahnConfig for the closing-pulse alternative.

Returns:

The idealized schedule and its inserted local-pulse records.

decoupling_ratio(schedule: Schedule, sequences: Sequence[LocalDDSequence] = ()) → float[source]

Return the fraction of ion-time volume covered by recorded DD windows.

max_absolute_residual_phase(schedule: Schedule, architecture: LinearArchitecture, local_pulse_action_ids: frozenset[int] = frozenset()) → float[source]

Return the largest absolute schedule-end residual phase.

residual_phase_by_ion(schedule: Schedule, architecture: LinearArchitecture, local_pulse_action_ids: frozenset[int] = frozenset()) → dict[int, float][source]

Return schedule-end residual phase for every ion.

sum_absolute_residual_phase(schedule: Schedule, architecture: LinearArchitecture, local_pulse_action_ids: frozenset[int] = frozenset()) → float[source]

Return the sum of absolute schedule-end residual phases.

sum_squared_residual_phase(schedule: Schedule, architecture: LinearArchitecture, local_pulse_action_ids: frozenset[int] = frozenset()) → float[source]

Return the sum of squared schedule-end residual phases.

class NearestHahnConfig[source]

Configure the schedule-preserving nearest-feasible Hahn comparator.

min_idle_timesteps: int = 2
label: str = 'NearestHahn'
__post_init__() → None[source]

Validate the comparator configuration.

Raises:
  • TypeError – If a configuration value has the wrong type.

  • ValueError – If a configuration value is outside its supported range.

class NearestHahnOpportunityRecord[source]

Describe the placement outcome for one eligible ion-local idle window.

ion: int
window: tuple[int, int]
ideal_midpoint: int
status: NearestHahnStatus
selected_timestep: int | None = None
processing_zone: str | None = None
signed_displacement: int | None = None
absolute_displacement: int | None = None
skip_reason: NearestHahnSkipReason | None = None
__post_init__() → None[source]

Validate one placement audit entry.

Raises:
  • TypeError – If a record value has the wrong type.

  • ValueError – If a record value is outside its supported range.

to_dict() → dict[str, object][source]

Return this record using JSON-compatible values.

classmethod from_dict(data: object) → NearestHahnOpportunityRecord[source]

Restore one placement record from JSON-compatible values.

Returns:

The restored record.

Raises:

ValueError – If the serialized record is malformed.

class NearestHahnReport[source]

Summarize nearest-Hahn placements and the windows it could not use.

report_type: ClassVar[str] = 'nearest_hahn'
sequences: tuple[LocalDDSequence, ...] = ()
opportunities: tuple[NearestHahnOpportunityRecord, ...] = ()
__post_init__() → None[source]

Freeze and validate the report collections.

Raises:

TypeError – If a collection contains an unexpected value.

property placed: int

The number of windows that received a pulse.

to_dict() → dict[str, object][source]

Return this report using JSON-compatible values.

classmethod from_dict(data: object) → NearestHahnReport[source]

Restore a nearest-Hahn report from JSON-compatible values.

Returns:

The restored report.

run_nearest_hahn(schedule: Schedule, architecture: LinearArchitecture, config: NearestHahnConfig | None = None) → DDPassResult[NearestHahnReport][source]

Place one X pulse as near each eligible idle-window midpoint as the schedule allows.

The pass uses only processing-zone access the compiled trajectory already provides. It inserts no transport, never extends the makespan, and adds no physical recovery pulse, so the resulting Pauli frame persists and is discharged virtually by a consumer that corrects the terminal frame. Unlike apply_idealized_hahn(), every returned schedule is executable on the given architecture.

The pass is intended for a base schedule. Applying it to an already augmented schedule is permitted, but the returned report then owns only the pulses this call inserted.

Parameters:
  • schedule – Base schedule to augment.

  • architecture – Hardware model the schedule runs on.

  • config – Optional comparator settings.

Returns:

The augmented schedule and its complete eligible-window audit.

class DDPassResult[source]

Bases: Generic[ReportT]

Contain an augmented schedule and diagnostics from one DD pass.

schedule: Schedule
architecture: LinearArchitecture
report: ReportT
unavailable_reason: str | None = None
__post_init__() → None[source]

Validate the schedule, report, and optional explanation.

Raises:
  • TypeError – If the schedule or report violates the pass-result protocol.

  • ValueError – If an unavailable reason is empty.

to_dict() → dict[str, object][source]

Return the DD-pass result using JSON-compatible values.

classmethod from_dict(data: object, report_class: type[ReportT]) → DDPassResult[ReportT][source]

Restore a DD-pass result with an explicit report class.

Returns:

The restored DD-pass result.

Raises:

ValueError – If the serialized envelope or report type is malformed.

to_json() → str[source]

Serialize this DD-pass result as JSON text.

Returns:

The JSON document.

classmethod from_json(raw: str, report_class: type[ReportT]) → DDPassResult[ReportT][source]

Restore a DD-pass result from JSON text.

Returns:

The restored DD-pass result.

save(filename: str | Path) → Path[source]

Write this DD-pass result to an explicit UTF-8 JSON file.

Returns:

The path written.

class LocalDDSequence[source]

Describe one ion-local pulse sequence in a DD method report.

ion: int
window: tuple[int, int]
scheme_name: str
pulse_timesteps: tuple[int, ...]
action_ids: tuple[int, ...]
remaining_phase: float = 0.0
phase_reduction: float = 0.0
residual_phase_at_window_end_before: float | None = None
residual_phase_at_window_end_after: float | None = None
residual_phase_at_window_end_reduction: float | None = None
__post_init__() → None[source]

Validate pulse positions and their associated idle window.

Raises:
  • TypeError – If a sequence field has the wrong type.

  • ValueError – If the window or pulse positions are inconsistent.

to_dict() → dict[str, object][source]

Return this local sequence using JSON-compatible values.

classmethod from_dict(data: object) → LocalDDSequence[source]

Restore a local sequence from JSON-compatible values.

Returns:

The restored local DD sequence.

Raises:

ValueError – If the serialized sequence is malformed.

class SADDConfig[source]

Configure the shared pulse-only and transport-enabled SADD backend.

SADD denotes shuttling-aware dynamical decoupling.

timeout_s bounds each control window’s solve. The unchanged schedule is always an admissible solution and is supplied to the solver as a hint, so a window that runs out of time yields a weaker improvement or none at all rather than an invalid or missing result. Raise it for long windows or many participating ions, where proving optimality takes longer.

Synthesized shuttles, swaps, and local pulses take the durations defined by the architecture.

min_window_length: int = 2
max_window_length: int = 16
max_participating_ions: int = 5
timeout_s: float = 1.0
ion_preselection: Literal['phase', 'distance'] = 'phase'
opportunity_order: Literal['chronological', 'reverse_chronological'] = 'chronological'
max_accepted_windows: int | None = None
improvement_tolerance: float = 1e-12
allow_pulses: bool = True
scale: int = 1000
num_search_workers: int = 8
__post_init__() → None[source]

Validate optimization and problem parameters.

Raises:
  • TypeError – If a parameter has the wrong type.

  • ValueError – If a parameter is outside its supported range.

class SADDMethod[source]

Bases: enum.StrEnum

Select a shuttling-aware dynamical decoupling (SADD) method.

PULSE_ONLY = 'pulse_only_sadd'
FULL = 'full_sadd'
property allow_transport: bool

Whether this method permits transport synthesis.

class SADDOpportunityRecord[source]

Describe one ordered SADD optimization opportunity and its outcome.

transport_delta records the signed change in scheduled transport actions by concrete action type between the opportunity input and proposed result. Equality ignores runtime_s, so two runs with the same outcome compare equal.

target_pz: str
window: tuple[int, int]
participating_ions: tuple[int, ...]
status: str
validation_status: str
phase_cost_before: float
phase_cost_after: float | None
accepted: bool
pulse_count: int
transport_delta: Mapping[str, int]
runtime_s: float
message: str | None = None
eligible_ions: tuple[int, ...] = ()
busy_ions: tuple[int, ...] = ()
rejected_no_active_segment_ions: tuple[int, ...] = ()
rejected_unreachable_ions: tuple[int, ...] = ()
selection_scores: tuple[tuple[int, float, int], ...] = ()
phase_before_by_ion: IonFloatMapping | None = None
phase_after_by_ion: IonFloatMapping | None = None
pulse_timesteps: IonTimestepsMapping | None = None
pulse_action_ids: IonTimestepsMapping | None = None
transport_actions: tuple[str, ...] = ()
trajectories: IonTimestepsMapping | None = None
model_num_variables: int = 0
model_num_constraints: int = 0
__post_init__() → None[source]

Validate and freeze nested opportunity diagnostics.

Raises:
  • TypeError – If a field has the wrong type.

  • ValueError – If a field contains an invalid value.

class SADDReport[source]

Collect ordered opportunity records produced by one SADD pass.

report_type: ClassVar[str] = 'sadd'
method: SADDMethod
opportunities: tuple[SADDOpportunityRecord, ...] = ()
__post_init__() → None[source]

Normalize opportunity records to an immutable tuple.

Raises:

TypeError – If the method or an opportunity has the wrong type.

property sequences: tuple[LocalDDSequence, ...]

Accepted ion-local pulse sequences in opportunity order.

to_dict() → dict[str, object][source]

Return this report using JSON-compatible values.

classmethod from_dict(data: object) → SADDReport[source]

Restore a SADD report from JSON-compatible values.

Returns:

The restored SADD report.

Raises:

ValueError – If the serialized report is malformed.

class SADDResult[source]

Contain a SADD-augmented compilation result and its pass report.

result: CompilationResult
report: SADDReport
unavailable_reason: str | None = None
__post_init__() → None[source]

Validate the transformed result, report, and optional explanation.

Raises:
  • TypeError – If a field has the wrong type.

  • ValueError – If an unavailable reason is empty.

to_dict() → dict[str, object][source]

Return this SADD result using JSON-compatible values.

classmethod from_dict(data: object) → SADDResult[source]

Restore a serialized SADD result.

Returns:

The restored SADD result.

Raises:

ValueError – If the serialized value is malformed.

to_json() → str[source]

Serialize this SADD result as JSON text.

Returns:

The JSON document.

classmethod from_json(raw: str) → SADDResult[source]

Restore a SADD result from JSON text.

Returns:

The restored SADD result.

save(filename: str | Path) → Path[source]

Write this SADD result to an explicit UTF-8 JSON file.

Returns:

The path written.

run_sadd(result: CompilationResult, method: SADDMethod, config: SADDConfig | None = None, *, architecture: LinearArchitecture | None = None) → SADDResult[source]

Apply shuttling-aware dynamical decoupling to a compiled schedule.

Pulse-only and transport-enabled SADD use the same optimization backend; method controls whether the solver may synthesize transport.

Parameters:
  • result – Compilation result to augment.

  • method – SADD method to apply.

  • config – Optional optimization settings.

  • architecture – Optional compatible architecture with added DD capabilities.

Returns:

The transformed compilation result and an ordered SADD report.

Raises:
  • TypeError – If method is not a SADDMethod.

  • ValueError – If the result and architecture are incompatible or the architecture lacks actions required by the selected method.

class GateSpec[source]

Describe the rotation of one decoupling pulse.

gate_name names the rotation class, such as "Rx". A pulse applied to one ion becomes that gate; a global pulse becomes a GlobalGate with the same rotation.

gate_name: str
theta: float | None = None