Skip to content

Kernel validation

KernelValidation dataclass

KernelValidation(
    validation_analysis_cls: type[ValidationAnalysis],
)

Validate a kernel according to a ValidationAnalysis.

This is a simple wrapper around the analysis that runs the analysis, checks the ValidationFrame for errors and throws them if there are any.

validation_analysis_cls instance-attribute

validation_analysis_cls: type[ValidationAnalysis]

The analysis that you want to run in order to validate the kernel.

run

run(mt: Method, no_raise: bool = True) -> None

Run the kernel validation analysis and raise any errors found.

Parameters:

Name Type Description Default
mt Method

The method to validate

required
no_raise bool

Whether or not to raise errors when running the analysis. This is only to make sure the analysis works. Errors found during the analysis will be raised regardless of this setting. Defaults to True.

True
Source code in .venv/lib/python3.12/site-packages/bloqade/validation/kernel_validation.py
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
def run(self, mt: ir.Method, no_raise: bool = True) -> None:
    """Run the kernel validation analysis and raise any errors found.

    Args:
        mt (ir.Method): The method to validate
        no_raise (bool): Whether or not to raise errors when running the analysis.
            This is only to make sure the analysis works. Errors found during
            the analysis will be raised regardless of this setting. Defaults to `True`.

    """

    validation_analysis = self.validation_analysis_cls(mt.dialects)

    if no_raise:
        validation_frame, _ = validation_analysis.run_no_raise(mt)
    else:
        validation_frame, _ = validation_analysis.run(mt)

    errors = validation_frame.errors

    if len(errors) == 0:
        # Valid program
        return
    elif len(errors) == 1:
        raise errors[0]
    else:
        raise ValidationErrorGroup(errors=errors)