Camel.verifiers.physics verifier
UnitParser
Class for handling unit parsing and manipulation operations.
init
_load_sympy_units
Returns:
Dict[str, Any]: Dictionary mapping unit names to their corresponding sympy Quantity objects.
_add_si_prefixes
Add SI prefixed units (like km, MHz, etc.) to the allowed units.
parse_unit
Parse a unit string into a SymPy expression using the appropriate method.
Parameters:
- unit_str (str): The unit string to parse.
Returns:
Optional[Any]: SymPy expression representing the unit, or None if parsing fails or the unit is dimensionless.
parse_unit_with_latex
Parse a unit string using SymPy’s LaTeX parser.
Parameters:
- unit_str (str): The unit string in LaTeX format.
Returns:
Any: SymPy expression representing the unit, or the original string if parsing fails.
detect_scaling_factor
Detect a scaling factor in the unit expression.
Parameters:
- unit_expr (Any): The unit expression.
Returns:
Tuple[Union[int, float, Any], Any]: Tuple of scale factor and base unit.
preprocess_unit_string
Preprocess a unit string to replace ’^’ with ’**’ for exponentiation.
Parameters:
- unit_str (str): The unit string to preprocess.
Returns:
str: Preprocessed unit string.
unit_is_none
Check if a unit string represents ‘no unit’ or is empty.
Parameters:
- unit_str (Optional[str]): The unit string to check.
Returns:
bool: True if the unit is None or represents ‘no unit’.
extract_value_and_unit
Extract numerical value and unit components from a SymPy expression.
Parameters:
- expr (Any): SymPy expression with units.
Returns:
Tuple[Union[int, float, Any], Any]: Numerical value and unit expression.
detect_unit_args
Extract the base units from a composite SymPy unit expression.
Parameters:
- unit_expr (Any): SymPy expression representing a composite unit.
Returns:
List[Any]: List of SymPy base unit components.
PhysicsSolutionComparator
Class for compare solutions and reference answers that contains value and units.
Parameters:
- solution (str): The output from running the solution code.
- reference_answer (str): The reference answer to compare against.
- float_tolerance (Optional[float], optional): The tolerance for floating point comparisons. (default: :obj:
None
)
init
_split_value_unit
Split a string into value and unit components. Handles LaTeX-style units enclosed in dollar signs.
Parameters:
- s (str): The input string.
Returns:
Tuple[str, str]: Tuple of (value, unit) as strings.
_clean_answer
Clean a raw answer string by removing LaTeX formatting.
Parameters:
- raw_answer (str): The raw answer string potentially containing LaTeX formatting.
Returns:
str: The cleaned answer string without LaTeX formatting.
_parse_expression
Parse an expression into a SymPy expression.
Parameters:
- expr (Any): Expression to parse, can be a string, number, or other type.
Returns:
Any: Parsed SymPy expression.
_is_number
Check if a value can be converted to a number.
Parameters:
- s (Any): Value to check.
Returns:
bool: True if the value can be converted to a number.
_detect_tolerance
_convert_units
Convert the solution units to match gt units
verify_unit
compare_solution_to_reference
Returns:
VerificationResult with comparison status.
_get_value_unit_pairs
_compare_numeric_values
Compare numerical values, with unit conversion if needed.
_compare_symbolic_values
Compare symbolic expressions for equivalence.
PhysicsVerifier
The PhysicsVerifier inherits PythonVerifier and makes it able to compare and convert units.
Parameters:
- extractor (Optional[BaseExtractor]): The extractor to use for extracting code from messages. (default: :obj:
None
) - timeout (Optional[float]): The timeout for code execution in seconds. (default: :obj:
30.0
) - required_packages (Optional[List[str]]): The required packages for code execution. (default: :obj:
None
) - float_tolerance (Optional[float]): The relative tolerance used to compare numerical values. (default: :obj:
None
) **kwargs: Additional keyword arguments to pass to the parent class.