qpanda3_runtime.toolbox.tracker.tracking_rule#

Classes#

TrackingRule

Abstract base class for tracking analysis rules.

TrackingRules

Manager for tracking analysis rules.

Module Contents#

class qpanda3_runtime.toolbox.tracker.tracking_rule.TrackingRule#

Bases: abc.ABC

Abstract base class for tracking analysis rules.

This class defines the interface for tracking analysis rules that can process tracker traces and produce analysis results. Each rule must implement a unique identifier and an analysis method.

Subclasses should implement specific analysis logic for different types of tracking data or analysis requirements.

Examples

>>> class MyTrackingRule(TrackingRule):
...     @property
...     def rule_id(self) -> str:
...         return "my_rule"
...
...     def analyze(self, data: TrackerTrace) -> Any:
...         # Custom analysis logic
...         return {"result": "analysis_complete"}
property rule_id: str#
Abstractmethod:

Get the unique identifier for this rule.

Returns:

Unique rule identifier string.

Return type:

str

Notes

Rule IDs should be descriptive and unique within the system. They are used to register and retrieve rules from the rule manager.

abstractmethod analyze(data: qpanda3_runtime.toolbox.tracker.tracker_trace.TrackerTrace) → Any#

Analyze tracking data using this rule.

Parameters:

data (TrackerTrace) – Tracking trace data to analyze. Must be a valid TrackerTrace instance containing tracking session information.

Returns:

Analysis result. The type and structure of the result depends on the specific rule implementation.

Return type:

Any

Raises:
  • ValueError – If the input data is not a valid TrackerTrace instance.

  • RuntimeError – If analysis cannot be performed due to invalid data state.

class qpanda3_runtime.toolbox.tracker.tracking_rule.TrackingRules(default_rule: TrackingRule)#

Manager for tracking analysis rules.

This class manages a collection of tracking rules, providing registration, retrieval, and rule selection functionality.

Variables:
  • available_rules (List[str]) – List of registered rule IDs.

  • default_rule (TrackingRule) – The default rule used when no specific rule is requested.

Examples

>>> default_rule = DefaultTrackingRule()
>>> rule_manager = TrackingRules(default_rule)
>>> rule_manager.register_rule(MyTrackingRule())
>>> rule = rule_manager.get_rule("my_rule")
>>> result = rule.analyze(trace_data)
register_rule(rule: TrackingRule) → None#

Register a new tracking rule.

Parameters:

rule (TrackingRule) – Rule instance to register.

Raises:

ValueError – If a rule with the same rule_id is already registered.

Notes

Registered rules can be retrieved later using their rule_id. If a rule with the same ID already exists, it will be replaced.

get_rule(rule_id: str) → TrackingRule#

Get a rule by its identifier.

Parameters:

rule_id (str) – Identifier of the rule to retrieve.

Returns:

The requested rule instance, or the default rule if the requested rule is not found.

Return type:

TrackingRule

Notes

This method provides a safe way to retrieve rules, falling back to the default rule when the requested rule is not available.

get_default_rule() → TrackingRule#

Get the default rule.

Returns:

The default rule instance.

Return type:

TrackingRule

get_available_rules() → List[str]#

Get list of available rule identifiers.

Returns:

List of registered rule IDs.

Return type:

List[str]

Notes

The list includes the default rule ID and all registered custom rule IDs.

decide_rule(data: Any) → TrackingRule#

Determine which rule to use for analyzing given data.

Parameters:

data (Any) – Data to be analyzed. The type and structure may influence rule selection.

Returns:

Rule instance selected for analyzing the data.

Return type:

TrackingRule

Notes

The default implementation always returns the default rule. Subclasses can override this method to implement custom rule selection logic based on data characteristics.