axtreme.simulator.utils

Helper functions for creating vaid simulators.

Functions

is_valid_simulator(instance, *[, verbose])

Checks that instance conforms to Simulator protocol AND signature definition.

simulator_from_func(func)

Adds n_simulations_per_point functionality to a a function that takes x inputs, and return simulation values.

axtreme.simulator.utils.is_valid_simulator(instance: object, *, verbose: bool = False) bool

Checks that instance conforms to Simulator protocol AND signature definition.

This test only works if the instance has type definitions.

Note

By default, isinstance with @runtime_checkable “will check only the presence of the required methods not their type signatures!”. See @runtime_checkable docs for details.

Parameters:
  • instance – will check if this is a valid Simulator.

  • verbose – If true will provide information regarding why it does not conform.

Returns:

True if methods and signatures match

Return type:

bool

Note

  • Briefly looked at override the __instancecheck__ so isinstance would acheive this result

  • Apprears __instancecheck__ doesn’t get called, would need to investigate why to proceed

  • Adding this behaviour to protocol would cause it to depart from standard protocol behaviour

axtreme.simulator.utils.simulator_from_func(func: Callable[[ndarray[tuple[int, int], dtype[float64]]], ndarray[tuple[int, int], dtype[float64]]]) Simulator

Adds n_simulations_per_point functionality to a a function that takes x inputs, and return simulation values.

Parameters:

func – function which accepts (n,d) x input, and returns (n, m) y output (one response per x point).

Returns:

Function conforming to Simultator interface. Output will always be 3 dimensional (n_points, n_simulations_per_point, n_targets).