Skip to content

Conversation

@DavidLanders95
Copy link
Member

No description provided.

@uellue
Copy link
Contributor

uellue commented Sep 9, 2025

It looks like Microscope Calibration works fine after rebasing #4 to this and adapting to run_iter() changes. I can't really say much about the rest! From my perspective one can merge this.

@uellue
Copy link
Contributor

uellue commented Sep 11, 2025

Also turned out that jax is aggressively casting down to float32. I've sprinkled import jax; jax.config.update("jax_enable_x64", True) all over the code and start requesting float64 explicitly where necessary. That seems to be an important part of resolving this!

PS: Success! With float64 and manually specified inverse we now pass atol and rtol of 1e-12 for the linearized solution!

    x, residuals, rank, s = np.linalg.lstsq(input_samples, output_samples)

    assert len(residuals) == rank
    # Confirm that the solution is exact, in particular that
    # the model is linear
    assert np.allclose(residuals, 0., rtol=1e-12, atol=1e-12)
    assert rank == 5

    for i in range(len(input_samples)):
        assert np.allclose(
            output_samples[i],
            input_samples[i] @ x,
            rtol=1e-12,
            atol=1e-12
        )
    return x

@DavidLanders95
Copy link
Member Author

Also turned out that jax is aggressively casting down to float32. I've sprinkled import jax; jax.config.update("jax_enable_x64", True) all over the code and start requesting float64 explicitly where necessary. That seems to be an important part of resolving this!

PS: Success! With float64 and manually specified inverse we now pass atol and rtol of 1e-12 for the linearized solution!

    x, residuals, rank, s = np.linalg.lstsq(input_samples, output_samples)

    assert len(residuals) == rank
    # Confirm that the solution is exact, in particular that
    # the model is linear
    assert np.allclose(residuals, 0., rtol=1e-12, atol=1e-12)
    assert rank == 5

    for i in range(len(input_samples)):
        assert np.allclose(
            output_samples[i],
            input_samples[i] @ x,
            rtol=1e-12,
            atol=1e-12
        )
    return x

For me I by default think it's necessary to turn on this feature, since the scales, and the disparity in scales we work at demand it.
We could just enable it by default package wide?

I have been just enabling float64 at the top of any notebook. Then I don't need to explicitly make anything float64, and it will automatically do so (at least I haven't found a case where it used float32 when I didn't want it to).

@DavidLanders95
Copy link
Member Author

It looks like Microscope Calibration works fine after rebasing #4 to this and adapting to run_iter() changes. I can't really say much about the rest! From my perspective one can merge this.

Ok, after adding more tests and lots of examples, I will merge now.

@DavidLanders95 DavidLanders95 merged commit 39d20b7 into main Sep 15, 2025
7 checks passed
@uellue
Copy link
Contributor

uellue commented Sep 15, 2025

For me I by default think it's necessary to turn on this feature, since the scales, and the disparity in scales we work at demand it.
We could just enable it by default package wide?

Yes! Microscope Calibration already enables by default, validates the precision and accuracy of linearizations, and will raise an error if it detects discrepancies that exceed tolerances achievable with float64 .

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.

3 participants