Skip to content

Fix AssertionError of number of streams per layer for uniform_air - #96

Merged
ghislainp merged 1 commit into
smrt-model:masterfrom
linazsche:master
Oct 7, 2026
Merged

ghislainp merged 1 commit into
smrt-model:masterfrom
linazsche:master

Conversation

@linazsche

Copy link
Copy Markdown
Contributor

Bug Fix for uniform_air

In 7e5af0b, the previously correct assert all(streams.n > 2) under compute_stream_uniform() was changed to assert all(np.size(n) > 2 for n in streams.n), which always fails since the size of a scalar is 1. This commit changes the assert back to its original purpose while keeping the element-wise comparison: assert all(n > 2 for n in streams.n).

Related: The assert under compute_stream_gaussian() seems to always pass following 7e5af0b, but n is apparently checked properly within gauss_legendre_quadrature().

Using stream_mode=uniform_air caused the following error:

  File "smrt\src\smrt\core\model.py", line 628, in run_single_simulation
    result = rtsolver.solve(
             ^^^^^^^^^^^^^^^
  File "smrt\src\smrt\rtsolver\dort.py", line 205, in solve
    self.prepare_streams()
  File "smrt\src\smrt\rtsolver\rtsolver_utils.py", line 89, in prepare_streams
    self.streams = compute_stream(self.n_max_stream, rtsolver.effective_permittivity, mode=self.stream_mode)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "smrt\src\smrt\rtsolver\streams.py", line 142, in compute_stream
    return compute_stream_uniform(n_max_stream, permittivity)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "smrt\src\smrt\rtsolver\streams.py", line 300, in compute_stream_uniform
    assert all(np.size(n) > 2 for n in streams.n)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError

Minimal code example:

from smrt import make_model, make_snowpack, sensor_list

sensor = sensor_list.passive(37e9, 55)
snowpack = make_snowpack(
    thickness=[1],
    microstructure_model="exponential",
    density=300,
    corr_length=1e-4,
    temperature=260,
)
model = make_model("iba", "dort", rtsolver_options={"stream_mode": "uniform_air"})

model.run(sensor, snowpack).TbV()

@ghislainp

ghislainp commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

Thank you for the PR. Note that the "uniform_air" mode has never been well tested. Use with care.

@ghislainp
ghislainp merged commit 2f5739d into smrt-model:master Oct 7, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants