qpanda3_runtime.toolbox.tracker.tracking_rule#
Classes#
Abstract base class for tracking analysis rules. |
|
Manager for tracking analysis rules. |
Module Contents#
- class qpanda3_runtime.toolbox.tracker.tracking_rule.TrackingRule#
Bases:
abc.ABCAbstract 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.
示例
>>> 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.
- 返回:
Unique rule identifier string.
- 返回类型:
str
备注
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.
- 参数:
data (
TrackerTrace) -- Tracking trace data to analyze. Must be a valid TrackerTrace instance containing tracking session information.- 返回:
Analysis result. The type and structure of the result depends on the specific rule implementation.
- 返回类型:
Any- 抛出:
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.
- 变量:
available_rules (
List[str]) -- List of registered rule IDs.default_rule (
TrackingRule) -- The default rule used when no specific rule is requested.
示例
>>> 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.
- 参数:
rule (
TrackingRule) -- Rule instance to register.- 抛出:
ValueError -- If a rule with the same rule_id is already registered.
备注
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.
- 参数:
rule_id (
str) -- Identifier of the rule to retrieve.- 返回:
The requested rule instance, or the default rule if the requested rule is not found.
- 返回类型:
备注
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.
- 返回:
The default rule instance.
- 返回类型:
- get_available_rules() List[str]#
Get list of available rule identifiers.
- 返回:
List of registered rule IDs.
- 返回类型:
List[str]
备注
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.
- 参数:
data (
Any) -- Data to be analyzed. The type and structure may influence rule selection.- 返回:
Rule instance selected for analyzing the data.
- 返回类型:
备注
The default implementation always returns the default rule. Subclasses can override this method to implement custom rule selection logic based on data characteristics.