Skip to content

compile_active_word_log

from tensorsig.offset_coded_signatures.active_word_log import compile_active_word_log

Compile certified bridge support and its factor closure for independent windows.

Source code in src/tensorsig/offset_coded_signatures/active_word_log.py
def compile_active_word_log(plan: LieQuotientPlan) -> ActiveWordLogPlan:
    """Compile certified bridge support and its factor closure for independent windows."""
    if not isinstance(plan, LieQuotientPlan):
        raise TypeError("plan must be a LieQuotientPlan.")
    cached = plan._active_word_cache
    if cached is not None:
        return cached
    bridge = plan._word_bridge
    columns = bridge.active_columns
    requested = tuple(
        tuple(letter - 1 for letter in bridge.ambient_words[i]) for i in columns
    )
    code_dim = (
        plan.alphabet.code_dim if isinstance(plan.alphabet, ProjectedAlphabet) else 1
    )
    program = _compile_word_program(requested, code_dim, factors=True)
    readout = _compile_word_log_readout(program, requested)
    matrix = bridge.quotient_matrix.detach().cpu()
    if matrix.layout != torch.strided:
        matrix = matrix.to_dense()
    matrix = matrix.index_select(1, torch.tensor(columns, dtype=torch.long))
    result = ActiveWordLogPlan(program, readout, matrix.to(torch.float64), requested)
    result = result.to(plan.generator_map.device, plan.generator_map.dtype)
    object.__setattr__(plan, "_active_word_cache", result)
    return result