Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise a meaningful error in import3d_gui.hoc for invalide soma #2609

Merged
merged 1 commit into from
Nov 15, 2023

Conversation

WeinaJi
Copy link
Collaborator

@WeinaJi WeinaJi commented Nov 14, 2023

Requested by users from the Blue Brain Project.
Fix #2602

@WeinaJi WeinaJi requested a review from 1uc November 14, 2023 10:37
Copy link

sonarcloud bot commented Nov 14, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@1uc
Copy link
Collaborator

1uc commented Nov 14, 2023

The reasoning is that in the next line we do:

minor.div(minor.mag)

to build a system of reference with two directions: minor and major. However, if minor.mag == 0. then we're unable to determine that the two directions. Therefore, it might be nice to throw a more meaningful error message here, since we know that semantically it's not just related to dividing something by zero, but that it's due to some degeneracy in the input contour.

Copy link

✔️ 1ed07bd -> Azure artifacts URL

@nrnhines
Copy link
Member

to build a system of reference with two directions: minor and major. However, if minor.mag == 0. then we're unable to determine that the two directions.

Yes. This approximates the (2-d) contour (sometimes a shape like a potato or a banana) by an ellipse with a major and minor axis.
One heuristic might be to raise an error if the minor/major ratio is less than 0.01 . Of course this won't catch errors of the form that the 3-d point author actually entered soma centroid points that are not in a straight line. In this case the analysis would just connect the first and last point to close the contour.

Copy link

codecov bot commented Nov 14, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (6f2e087) 66.19% compared to head (1ed07bd) 66.19%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2609   +/-   ##
=======================================
  Coverage   66.19%   66.19%           
=======================================
  Files         559      559           
  Lines      108937   108939    +2     
=======================================
+ Hits        72109    72112    +3     
+ Misses      36828    36827    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@1uc
Copy link
Collaborator

1uc commented Nov 14, 2023

With ratios and relative errors the problem is often that the reference could be zero, e.g. in this case if major.mag is close to zero, the we can't rely the ratio minor.mag / major.mag to be informative. If we go the relative path, then I'd suggest:

if(major.mag < ATOL || minor.mag / major.mag < RTOL) {

If it's impossible to give a value for ATOL, then one would use the relative threshold by itself.

As for 0.01, and I'm sorry for being annoying, it feels very large. If we throw, it means we block users from simulating anything with such a thin soma. Intuitively, I was expecting a relative error of 1e-6 or smaller.

@nrnhines nrnhines merged commit 15bbeb2 into master Nov 15, 2023
36 checks passed
@nrnhines nrnhines deleted the weji/loadmorph_error branch November 15, 2023 14:34
@1uc
Copy link
Collaborator

1uc commented Nov 15, 2023

We never added the proposed changes. Hence what's currently merged is the check:

if(minor.mag == 0.0)

@nrnhines we're unsure if this is an oversight. Would you like us to create a new PR to check:

if(minor.mag / (major.mag + 1e-100) < 1e-6) {

@nrnhines nrnhines restored the weji/loadmorph_error branch November 15, 2023 15:38
@nrnhines nrnhines deleted the weji/loadmorph_error branch November 15, 2023 15:39
@nrnhines
Copy link
Member

So shall I throw when if (minor.mag/major.mag < 1e-6)?

My mistake, I thought that had been added. But

if(minor.mag / (major.mag + 1e-100) < 1e-6) {

is better. I guess this mistake is best corrected with a new PR.

1uc added a commit that referenced this pull request Nov 15, 2023
Improves the floating point comparison with zero. The strategy is to use
a relative tolerance for the ratio `minor.mag/major.mag`.

The softening constant `1e-100` is chosen such that:
1. If `minor.mag == 0.0` then the ratio is always `0.0` and no division
   by zero occurs.
2. The value of `major.mag + 1e-100 == major.mag` for all biophysically
   sensible values of `major.mag`.

If both `minor.mag` and `major.mag` are zero as floating point number,
then check may fail to raise a exception.
1uc added a commit that referenced this pull request Nov 15, 2023
Improves the floating point comparison with zero. The strategy is to use
a relative tolerance for the ratio `minor.mag/major.mag`.

The softening constant `1e-100` is chosen such that:
1. If `minor.mag == 0.0` then the ratio is always `0.0` and no division
   by zero occurs.
2. The value of `major.mag + 1e-100 == major.mag` for all biophysically
   sensible values of `major.mag`.

If both `minor.mag` and `major.mag` are zero as floating point number,
then check may fail to raise a exception.
1uc added a commit that referenced this pull request Nov 15, 2023
Improves the floating point comparison with zero. The strategy is to use
a relative tolerance for the ratio `minor.mag/major.mag`.

The softening constant `1e-100` is chosen such that:
1. If `minor.mag == 0.0` then the ratio is always `0.0` and no division
   by zero occurs.
2. The value of `major.mag + 1e-100 == major.mag` for all biophysically
   sensible values of `major.mag`.

If both `minor.mag` and `major.mag` are zero as floating point number,
then check may fail to raise a exception.
ohm314 pushed a commit that referenced this pull request Nov 16, 2023
Improves the floating point comparison with zero. The strategy is to use
a relative tolerance for the ratio `minor.mag/major.mag`.

The softening constant `1e-100` is chosen such that:
1. If `minor.mag == 0.0` then the ratio is always `0.0` and no division
   by zero occurs.
2. The value of `major.mag + 1e-100 == major.mag` for all biophysically
   sensible values of `major.mag`.

If both `minor.mag` and `major.mag` are zero as floating point number,
then check may fail to raise a exception.
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.

Different behaviours from loading an ascii morphology file in hoc and in python
4 participants