Problem: Discrete Lattice Complex State Propagation and Intensity Calculation

The problem requires implementing a complete discrete propagation lattice simulation toolkit for complex-valued wave state modeling. It includes proper input validation, accurate phase mapping generation, correct evolution of input complex states under lattice coupling rules, and stable intensity profile calculation, with support for both dense and sparse matrix formats to ensure computational efficiency across varying grid sizes.


Input/Output: The problem receives three categories of input data: 1) A positive integer or integer-valued float grid_size for discrete propagation lattice phase map construction; 2) A one-dimensional complex state vector (supporting list, tuple, or numpy array format) and a two-dimensional phase map (supporting dense complex nested list or scipy sparse matrix format) for state propagation computation; 3) A complex-valued input object (supporting list, tuple, numpy complex array, or scipy sparse complex matrix) for intensity profile calculation.
The problem generates three corresponding outputs after mandatory input validity checks for each step: first, a two-dimensional nested list of complex numbers as the valid phase interaction table with required adjustment and mirrored conjugate tail if applicable; second, a one-dimensional list of complex numbers as the normalized evolved propagation state; third, a one-dimensional list of non-negative float values as the numerical-overflow-avoided intensity profile of the input complex state. The processing pipeline follows sequential logic of phase map construction, state propagation, and intensity evaluation.

Required dependencies:

Sub-steps:
step_number: 1.0
step_description_prompt: Please write Python code to implement a function named build_phase_mapping. It takes grid_size as input, first conduct input validation, then generate a complex-valued phase interaction table for discrete propagation lattice, apply phase adjustment when grid size is larger than 8, add mirrored conjugate tail if needed, return the result as a nested list of complex numbers.
function_header: def build_phase_mapping(grid_size: int) -> list[list[complex]]:
test_cases: for size, expected_shape in [
    (4, (4, 4)),
    (8, (8, 8)),
    (3, (3, 3))
]:
    mapping = build_phase_mapping(size)
    assert len(mapping) == expected_shape[0]
    assert len(mapping[0]) == expected_shape[1]
    assert abs(complex(mapping[0][0])) > 0.9  

step_number: 2.0
step_description_prompt: Please write a Python function named propagate_complex_state. This function takes a 1D complex state vector and 2D phase map (supporting both dense and scipy sparse matrices) as inputs. It performs input validity checks, verifies phase element unit magnitude, auto-converts dense matrices to sparse if zero ratio is high, evolves the normalized state, and returns the result as a list.
function_header: def propagate_complex_state(state_vector, phase_map):
test_cases: 
for state, phase_size, target_norm in [
    ([1+0j, 0+0j], 2, 1.0),
    ([0.5+0.5j, 0.5-0.5j], 2, 1.0),
    ([1+1j, 2+2j, 3+3j], 3, 28.0)
]:
    phase_map = build_phase_mapping(len(state))
    result = propagate_complex_state(state, phase_map)
    norm = sum(abs(x)**2 for x in result)
    assert math.isclose(norm, target_norm, rel_tol=1e-6)


step_description_prompt: Please use Python to generate a function named evaluate_intensity_profile. This function accepts various complex-valued input types, verifies input validity, calculates modulus for each complex element, avoids numerical overflow during computation, and returns the result as a list.
function_header: def evaluate_intensity_profile(complex_state):
test_cases: for signal, reference in [
    ([3 + 4j, 0 - 1j], [5.0, 1.0]),
    ([1 + 1j], [math.sqrt(2)]),
    ([0 + 0j, -5 + 0j], [0.0, 5.0]),
]:
    output = evaluate_intensity_profile(signal)
    assert all(math.isclose(o, r, rel_tol=1e-9) for o, r in zip(output, reference))

General solution:

General tests: