> ## Documentation Index
> Fetch the complete documentation index at: https://docs.camel-ai.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Camel.verifiers.physics verifier

<a id="camel.verifiers.physics_verifier" />

<a id="camel.verifiers.physics_verifier.UnitParser" />

## UnitParser

```python theme={"system"}
class UnitParser:
```

Class for handling unit parsing and manipulation operations.

<a id="camel.verifiers.physics_verifier.UnitParser.__init__" />

### **init**

```python theme={"system"}
def __init__(self):
```

<a id="camel.verifiers.physics_verifier.UnitParser._load_sympy_units" />

### \_load\_sympy\_units

```python theme={"system"}
def _load_sympy_units():
```

**Returns:**

Dict\[str, Any]: Dictionary mapping unit names to their
corresponding sympy Quantity objects.

<a id="camel.verifiers.physics_verifier.UnitParser._add_si_prefixes" />

### \_add\_si\_prefixes

```python theme={"system"}
def _add_si_prefixes(self):
```

Add SI prefixed units (like km, MHz, etc.) to the allowed units.

<a id="camel.verifiers.physics_verifier.UnitParser.parse_unit" />

### parse\_unit

```python theme={"system"}
def parse_unit(self, unit_str: str):
```

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.

<a id="camel.verifiers.physics_verifier.UnitParser.parse_unit_with_latex" />

### parse\_unit\_with\_latex

```python theme={"system"}
def parse_unit_with_latex(self, unit_str: str):
```

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.

<a id="camel.verifiers.physics_verifier.UnitParser.detect_scaling_factor" />

### detect\_scaling\_factor

```python theme={"system"}
def detect_scaling_factor(self, unit_expr: Any):
```

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.

<a id="camel.verifiers.physics_verifier.UnitParser.preprocess_unit_string" />

### preprocess\_unit\_string

```python theme={"system"}
def preprocess_unit_string(unit_str: str):
```

Preprocess a unit string to replace '^' with '\*\*' for
exponentiation.

**Parameters:**

* **unit\_str** (str): The unit string to preprocess.

**Returns:**

str: Preprocessed unit string.

<a id="camel.verifiers.physics_verifier.UnitParser.unit_is_none" />

### unit\_is\_none

```python theme={"system"}
def unit_is_none(unit_str: Optional[str]):
```

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'.

<a id="camel.verifiers.physics_verifier.UnitParser.extract_value_and_unit" />

### extract\_value\_and\_unit

```python theme={"system"}
def extract_value_and_unit(expr: Any):
```

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.

<a id="camel.verifiers.physics_verifier.UnitParser.detect_unit_args" />

### detect\_unit\_args

```python theme={"system"}
def detect_unit_args(unit_expr: Any):
```

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.

<a id="camel.verifiers.physics_verifier.PhysicsSolutionComparator" />

## PhysicsSolutionComparator

```python theme={"system"}
class 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`)

<a id="camel.verifiers.physics_verifier.PhysicsSolutionComparator.__init__" />

### **init**

```python theme={"system"}
def __init__(
    self,
    solution: str,
    reference_answer: str,
    float_tolerance: Optional[float] = None
):
```

<a id="camel.verifiers.physics_verifier.PhysicsSolutionComparator._split_value_unit" />

### \_split\_value\_unit

```python theme={"system"}
def _split_value_unit(s: str):
```

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.

<a id="camel.verifiers.physics_verifier.PhysicsSolutionComparator._clean_answer" />

### \_clean\_answer

```python theme={"system"}
def _clean_answer(raw_answer: str):
```

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.

<a id="camel.verifiers.physics_verifier.PhysicsSolutionComparator._parse_expression" />

### \_parse\_expression

```python theme={"system"}
def _parse_expression(expr: Any):
```

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.

<a id="camel.verifiers.physics_verifier.PhysicsSolutionComparator._is_number" />

### \_is\_number

```python theme={"system"}
def _is_number(s: Any):
```

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.

<a id="camel.verifiers.physics_verifier.PhysicsSolutionComparator._detect_tolerance" />

### \_detect\_tolerance

```python theme={"system"}
def _detect_tolerance(default_tolerance: float, value: str):
```

<a id="camel.verifiers.physics_verifier.PhysicsSolutionComparator._convert_units" />

### \_convert\_units

```python theme={"system"}
def _convert_units(self):
```

Convert the solution units to match gt units

<a id="camel.verifiers.physics_verifier.PhysicsSolutionComparator.verify_unit" />

### verify\_unit

```python theme={"system"}
def verify_unit(sol_unit_expr: Any, gt_unit_expr: Any):
```

<a id="camel.verifiers.physics_verifier.PhysicsSolutionComparator.compare_solution_to_reference" />

### compare\_solution\_to\_reference

```python theme={"system"}
def compare_solution_to_reference(self):
```

**Returns:**

VerificationResult with comparison status.

<a id="camel.verifiers.physics_verifier.PhysicsSolutionComparator._get_value_unit_pairs" />

### \_get\_value\_unit\_pairs

```python theme={"system"}
def _get_value_unit_pairs(self):
```

<a id="camel.verifiers.physics_verifier.PhysicsSolutionComparator._compare_numeric_values" />

### \_compare\_numeric\_values

```python theme={"system"}
def _compare_numeric_values(self):
```

Compare numerical values, with unit conversion if needed.

<a id="camel.verifiers.physics_verifier.PhysicsSolutionComparator._compare_symbolic_values" />

### \_compare\_symbolic\_values

```python theme={"system"}
def _compare_symbolic_values(self):
```

Compare symbolic expressions for equivalence.

<a id="camel.verifiers.physics_verifier.PhysicsVerifier" />

## PhysicsVerifier

```python theme={"system"}
class PhysicsVerifier(PythonVerifier):
```

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.

<a id="camel.verifiers.physics_verifier.PhysicsVerifier.__init__" />

### **init**

```python theme={"system"}
def __init__(
    self,
    extractor: Optional[BaseExtractor] = None,
    timeout: Optional[float] = 30.0,
    required_packages: Optional[List[str]] = None,
    float_tolerance: Optional[float] = None,
    **kwargs
):
```
