gpflow.experimental.check_shapes.error_contexts#

Infrastructure for describing the context of an error.

The MessageBuilder is used to format / indent messages nicely.

The ErrorContext is a reusable bit of information about where/why an error occurred that can be written to a MessageBuilder.

ErrorContexts can be composed using the StackContext and ParallelContext.

This allows reusable error messages in a consistent format.

Classes#

gpflow.experimental.check_shapes.error_contexts.ArgumentContext#

class gpflow.experimental.check_shapes.error_contexts.ArgumentContext(name_or_index, value=<object object>)[source]#

Bases: ErrorContext

An error occurred in the context of an argument to a function.

Parameters:
  • name_or_index (Union[str, int]) –

  • value (Any) –

print(builder)[source]#

Print this context to the given MessageBuilder.

Parameters:

builder (MessageBuilder) –

Return type:

None

gpflow.experimental.check_shapes.error_contexts.AttributeContext#

class gpflow.experimental.check_shapes.error_contexts.AttributeContext(name, value=<object object>)[source]#

Bases: ErrorContext

An error occurred in the context of an attribute on an object.

Parameters:
  • name (str) –

  • value (Any) –

print(builder)[source]#

Print this context to the given MessageBuilder.

Parameters:

builder (MessageBuilder) –

Return type:

None

gpflow.experimental.check_shapes.error_contexts.ConditionContext#

class gpflow.experimental.check_shapes.error_contexts.ConditionContext(condition)[source]#

Bases: ErrorContext

An error occurred in a conditional context.

Parameters:

condition (ParsedBoolSpec) –

print(builder)[source]#

Print this context to the given MessageBuilder.

Parameters:

builder (MessageBuilder) –

Return type:

None

gpflow.experimental.check_shapes.error_contexts.FunctionCallContext#

class gpflow.experimental.check_shapes.error_contexts.FunctionCallContext(func, path_and_line=None)[source]#

Bases: ErrorContext

An error occured inside a function that was called.

Normally print should be called from within the called function: func. If that is impossible, first call precompute from within func.

Parameters:
  • func (Callable[..., Any]) –

  • path_and_line (Optional[str]) –

precompute()[source]#

Precompute the values to print.

This is useful to capture the position of the stack of the relevant call, if this object is saved for later use.

Return type:

FunctionCallContext

Returns:

A new instance with precomptued values.

print(builder)[source]#

Print this context to the given MessageBuilder.

Parameters:

builder (MessageBuilder) –

Return type:

None

gpflow.experimental.check_shapes.error_contexts.FunctionDefinitionContext#

class gpflow.experimental.check_shapes.error_contexts.FunctionDefinitionContext(func)[source]#

Bases: ErrorContext

An error occured in the context of a function definition.

Parameters:

func (Callable[..., Any]) –

print(builder)[source]#

Print this context to the given MessageBuilder.

Parameters:

builder (MessageBuilder) –

Return type:

None

gpflow.experimental.check_shapes.error_contexts.IndexContext#

class gpflow.experimental.check_shapes.error_contexts.IndexContext(index, value=<object object>)[source]#

Bases: ErrorContext

An error occurred in the context of an index in a sequence.

Parameters:
  • index (int) –

  • value (Any) –

print(builder)[source]#

Print this context to the given MessageBuilder.

Parameters:

builder (MessageBuilder) –

Return type:

None

gpflow.experimental.check_shapes.error_contexts.LarkUnexpectedInputContext#

class gpflow.experimental.check_shapes.error_contexts.LarkUnexpectedInputContext(text, error, terminal_descriptions)[source]#

Bases: ParserInputContext

An error was caused by an UnexpectedInput error from Lark.

Parameters:
  • text (str) –

  • error (UnexpectedInput) –

  • terminal_descriptions (Mapping[str, str]) –

print(builder)[source]#

Print this context to the given MessageBuilder.

Parameters:

builder (MessageBuilder) –

Return type:

None

gpflow.experimental.check_shapes.error_contexts.MappingKeyContext#

class gpflow.experimental.check_shapes.error_contexts.MappingKeyContext(key)[source]#

Bases: ErrorContext

An error occurent in the context of a key in a map.

Parameters:

key (Any) –

print(builder)[source]#

Print this context to the given MessageBuilder.

Parameters:

builder (MessageBuilder) –

Return type:

None

gpflow.experimental.check_shapes.error_contexts.MappingValueContext#

class gpflow.experimental.check_shapes.error_contexts.MappingValueContext(key, value=<object object>)[source]#

Bases: ErrorContext

An error occurent in the context of a value in a map.

Parameters:
  • key (Any) –

  • value (Any) –

print(builder)[source]#

Print this context to the given MessageBuilder.

Parameters:

builder (MessageBuilder) –

Return type:

None

gpflow.experimental.check_shapes.error_contexts.MessageBuilder#

class gpflow.experimental.check_shapes.error_contexts.MessageBuilder(indent_str='')[source]#

Bases: object

Utility for formatting nested text.

Parameters:

indent_str (str) –

add_columned_line(*texts)[source]#

Write a line of several values, left-aligned within the current indentation level.

Inputs are converted to str`s using `str(text).

Parameters:

texts (Any) –

Return type:

None

add_line(text)[source]#

Write a line, indented at the current level.

Input is converted to a str using str(text).

Parameters:

text (Any) –

Return type:

None

build()[source]#

Compile all collected text into a single string.

Return type:

str

indent()[source]#

Context manager for indenting text.

Return type:

Iterator[MessageBuilder]

gpflow.experimental.check_shapes.error_contexts.MultipleElementBoolContext#

class gpflow.experimental.check_shapes.error_contexts.MultipleElementBoolContext(text, line, column)[source]#

Bases: ParserInputContext

An error was caused by trying to use a multi-element argument specification as a bool.

Parameters:
  • text (str) –

  • line (int) –

  • column (int) –

print(builder)[source]#

Print this context to the given MessageBuilder.

Parameters:

builder (MessageBuilder) –

Return type:

None

gpflow.experimental.check_shapes.error_contexts.NoteContext#

class gpflow.experimental.check_shapes.error_contexts.NoteContext(note)[source]#

Bases: ErrorContext

An error occurred in a context where a user has added a note.

Parameters:

note (ParsedNoteSpec) –

print(builder)[source]#

Print this context to the given MessageBuilder.

Parameters:

builder (MessageBuilder) –

Return type:

None

gpflow.experimental.check_shapes.error_contexts.ObjectTypeContext#

class gpflow.experimental.check_shapes.error_contexts.ObjectTypeContext(obj)[source]#

Bases: ErrorContext

An error was caused by the type of an object.

Parameters:

obj (Any) –

print(builder)[source]#

Print this context to the given MessageBuilder.

Parameters:

builder (MessageBuilder) –

Return type:

None

gpflow.experimental.check_shapes.error_contexts.ObjectValueContext#

class gpflow.experimental.check_shapes.error_contexts.ObjectValueContext(obj)[source]#

Bases: ErrorContext

An error was caused by the value of an object.

Parameters:

obj (Any) –

print(builder)[source]#

Print this context to the given MessageBuilder.

Parameters:

builder (MessageBuilder) –

Return type:

None

gpflow.experimental.check_shapes.error_contexts.ParallelContext#

class gpflow.experimental.check_shapes.error_contexts.ParallelContext(children)[source]#

Bases: ErrorContext

Error context with many contexts in parallel.

Parameters:

children (Tuple[ErrorContext, ...]) –

print(builder)[source]#

Print this context to the given MessageBuilder.

Parameters:

builder (MessageBuilder) –

Return type:

None

gpflow.experimental.check_shapes.error_contexts.ParserInputContext#

class gpflow.experimental.check_shapes.error_contexts.ParserInputContext(text)[source]#

Bases: ErrorContext, ABC

Abstract base class for contexts that relate to parser input.

Parameters:

text (str) –

gpflow.experimental.check_shapes.error_contexts.ShapeContext#

class gpflow.experimental.check_shapes.error_contexts.ShapeContext(expected, actual)[source]#

Bases: ErrorContext

An error occurred in the context of the shapes of function arguments.

Parameters:
  • expected (ParsedShapeSpec) –

  • actual (Optional[Tuple[Optional[int], ...]]) –

print(builder)[source]#

Print this context to the given MessageBuilder.

Parameters:

builder (MessageBuilder) –

Return type:

None

gpflow.experimental.check_shapes.error_contexts.StackContext#

class gpflow.experimental.check_shapes.error_contexts.StackContext(parent, child)[source]#

Bases: ErrorContext

Error context where one context is “inside” another one.

Parameters:
print(builder)[source]#

Print this context to the given MessageBuilder.

Parameters:

builder (MessageBuilder) –

Return type:

None

gpflow.experimental.check_shapes.error_contexts.TensorSpecContext#

class gpflow.experimental.check_shapes.error_contexts.TensorSpecContext(spec)[source]#

Bases: ErrorContext

An error occurred in the context of a tensor specification.

Parameters:

spec (ParsedTensorSpec) –

print(builder)[source]#

Print this context to the given MessageBuilder.

Parameters:

builder (MessageBuilder) –

Return type:

None

gpflow.experimental.check_shapes.error_contexts.VariableContext#

class gpflow.experimental.check_shapes.error_contexts.VariableContext(variable_name)[source]#

Bases: ErrorContext

An error occurred in the context of a shape specification variable.

Parameters:

variable_name (str) –

print(builder)[source]#

Print this context to the given MessageBuilder.

Parameters:

builder (MessageBuilder) –

Return type:

None