Skip to content

Commit

Permalink
Make CLI print errors
Browse files Browse the repository at this point in the history
  • Loading branch information
drhagen committed Nov 26, 2023
1 parent b5f3e20 commit 45726bd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/tensora/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import typer
from parsita import Failure, Success

from .desugar.exceptions import DiagonalAccessError, NoKernelFoundError
from .expression import parse_assignment
from .format import Format, Mode, parse_format
from .kernel_type import KernelType
Expand Down Expand Up @@ -97,7 +98,11 @@ def tensora(
formats[variable_name] = Format((Mode.dense,) * order, tuple(range(order)))

# Generate code
code = generate_c_code_from_parsed(sugar, formats, kernel_types)
try:
code = generate_c_code_from_parsed(sugar, formats, kernel_types)
except (DiagonalAccessError, NoKernelFoundError) as error:
typer.echo(error, err=True)
raise typer.Exit(1)

if output_path is None:
typer.echo(code)
Expand Down
6 changes: 3 additions & 3 deletions src/tensora/desugar/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ class DiagonalAccessError(Exception):
def __str__(self) -> str:
return (
f"Diagonal access to a tensor (i.e. repeating the same index within a tensor) is not "
f"currently supported: {self.tensor.name}({', '.join(self.tensor.indexes)}"
f"currently supported: {self.tensor.name}({', '.join(self.tensor.indexes)})"
)


@dataclass(frozen=True, slots=True)
class NoKernelFoundError(Exception):
def __str__(self) -> str:
return (
"Was unable to find a kernel to solve the given tensor expression. This is likely "
"due to sparse tensors needing to be iterated in opposite orders."
"Tensora's tensor algebra compiler was unable to find a kernel for the given problem. "
"This is likely due to sparse tensors needing to be iterated in opposite orders."
)

0 comments on commit 45726bd

Please sign in to comment.