Generalize _block_diagonalize to more general algorithms.
We are now working towards changing and varying the algorithm. #23 (!101), #45 (closed), #138, #119 all require varying the algorithm. We have #135 (closed), for making algorithms public API, but before that we should make the internal API more general. I would like to change _block_diagonalize
to become
def _define_computation(
input_series: dict[str, BlockSeries],
scope: dict[str, Any],
algorithm: callable = main,
operator: Optional[Callable] = None,
return_all: bool = False,
linear_operator_mask: Optional[np.ndarray[bool]] = None,
) -> tuple[BlockSeries, ...] | tuple[dict[str, BlockSeries], dict[str, BlockSeries]]:
For a reference, this is the current _block_diagonalize
:
def _block_diagonalize(
H: BlockSeries,
solve_sylvester: Optional[Callable] = None,
*,
operator: Optional[Callable] = None,
return_all: bool = False,
) -> tuple[BlockSeries, ...] | tuple[dict[str, BlockSeries], dict[str, BlockSeries]]:
By comparing these two this means that we loses the following functionality:
- Ability to prepare default
solve_sylvester
- Ability to use the same algorithm for figuring out what should be a linear operator. This is taken over by
linear_operator_mask
Other than that the changes in the implementation are minimal.
As a separate remark, notice that I propose to pass the algorithm as a Callable
directly. This should be accompanied by wrapping algorithm_parsing.algorithm
with functools.cache
.
The following discussion from !101 should be addressed:
-
@Hugo started a discussion: Let's make a separate MR that allows to specify a different algorithm and pass a different scope to
_block_diagonalize
.