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

CT: cannot normalize a zero-magnitude vector #178

Closed
KatieWoe opened this issue Sep 9, 2021 · 19 comments
Closed

CT: cannot normalize a zero-magnitude vector #178

KatieWoe opened this issue Sep 9, 2021 · 19 comments

Comments

@KatieWoe
Copy link

KatieWoe commented Sep 9, 2021

geometric-optics : xss-fuzz
https://bayes.colorado.edu/continuous-testing/ct-snapshots/1631173379982/geometric-optics/geometric-optics_en.html?continuousTest=%7B%22test%22%3A%5B%22geometric-optics%22%2C%22xss-fuzz%22%5D%2C%22snapshotName%22%3A%22snapshot-1631173379982%22%2C%22timestamp%22%3A1631192038011%7D&brand=phet&ea&fuzz&stringTest=xss&memoryLimit=1000
Query: brand=phet&ea&fuzz&stringTest=xss&memoryLimit=1000
Uncaught Error: Cannot normalize a zero-magnitude vector
Error: Cannot normalize a zero-magnitude vector
at Vector2.normalized (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1631173379982/dot/js/Vector2.js:257:13)
at LightRays.getRayDirections (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1631173379982/geometric-optics/js/common/model/LightRays.js:160:61)
at https://bayes.colorado.edu/continuous-testing/ct-snapshots/1631173379982/geometric-optics/js/common/model/LightRays.js:82:33
at listener (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1631173379982/axon/js/Multilink.js:47:11)
at TinyProperty.emit (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1631173379982/axon/js/TinyEmitter.js:86:9)
at DerivedProperty._notifyListeners (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1631173379982/axon/js/Property.js:271:23)
at DerivedProperty.set (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1631173379982/axon/js/Property.js:186:14)
at DerivedProperty.getDerivedPropertyListener (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1631173379982/axon/js/DerivedProperty.js:112:13)
at TinyProperty.emit (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1631173379982/axon/js/TinyEmitter.js:86:9)
at Vector2Property._notifyListeners (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1631173379982/axon/js/Property.js:271:23)
id: Bayes Chrome
Snapshot from 9/9/2021, 1:42:59 AM
@pixelzoom pixelzoom changed the title CT cannot normalize a zero-magnitude vector CT: cannot normalize a zero-magnitude vector Sep 15, 2021
@pixelzoom pixelzoom assigned pixelzoom and unassigned veillette Sep 18, 2021
@phetsims phetsims deleted a comment from KatieWoe Sep 29, 2021
@pixelzoom
Copy link
Contributor

pixelzoom commented Sep 29, 2021

Here's the call to normalized in LightRays.js that's failing, in the code path for 'marginal' rays:

    // direction of a ray to the top of the optic
    const topDirection = topPoint.minus( sourcePosition ).normalized();

@arouinfar should this be addressed for the prototype? I have not investigated whether it causes the sim to crash in practice.

@arouinfar
Copy link
Contributor

@pixelzoom this seems a bit different than the assertion failures we passed over in #215. If it's a rare issue or doesn't cause a built sim to crash, I'm fine with deferring for the prototype.

Perhaps we should ask QA to try and reproduce? What do would you recommend @pixelzoom?

@pixelzoom
Copy link
Contributor

It's almost certainly a sim logic error, and non-fatal. While I'm not 100% certain, I'm fairly confident that this issue will not occur in practice, and can be deferred for the prototype. It occurs in other sims in CT, and we've (so far) ignored it in production deploys for those sims. So... Unassigning until post-prototype.

@pixelzoom pixelzoom removed their assignment Oct 1, 2021
@pixelzoom
Copy link
Contributor

I was never able to reproduce this error, and it has not occurred in CT for many months (almost 4 months?) And now that the source object cannot be moved as close to the optic, I'm confident that the offending vector can no longer have zero magnitude. So I'm going to close this issue. We can reopen if it reappears.

@pixelzoom
Copy link
Contributor

pixelzoom commented Mar 14, 2022

Reopening, this is back. Mostly showng up in geometric-optics-basics:

geometric-optics-basics : phet-io-fuzz : unbuilt
https://bayes.colorado.edu/continuous-testing/ct-snapshots/1647275824145/geometric-optics-basics/geometric-optics-basics_en.html?continuousTest=%7B%22test%22%3A%5B%22geometric-optics-basics%22%2C%22phet-io-fuzz%22%2C%22unbuilt%22%5D%2C%22snapshotName%22%3A%22snapshot-1647275824145%22%2C%22timestamp%22%3A1647283290005%7D&ea&brand=phet-io&phetioStandalone&fuzz&memoryLimit=1000
Query: ea&brand=phet-io&phetioStandalone&fuzz&memoryLimit=1000
Uncaught Error: Cannot normalize a zero-magnitude vector
Error: Cannot normalize a zero-magnitude vector
at Vector2.normalized (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1647275824145/chipper/dist/js/dot/js/Vector2.js:212:13)
at getRayDirections (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1647275824145/chipper/dist/js/geometric-optics/js/common/model/LightRays.js:128:38)
at https://bayes.colorado.edu/continuous-testing/ct-snapshots/1647275824145/chipper/dist/js/geometric-optics/js/common/model/LightRays.js:64:26
at listener (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1647275824145/chipper/dist/js/axon/js/Multilink.js:46:11)
at TinyProperty.emit (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1647275824145/chipper/dist/js/axon/js/TinyEmitter.js:69:9)
at Vector2Property._notifyListeners (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1647275824145/chipper/dist/js/axon/js/Property.js:227:23)
at Vector2Property.set (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1647275824145/chipper/dist/js/axon/js/Property.js:156:14)
at Vector2Property.set value [as value] (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1647275824145/chipper/dist/js/axon/js/Property.js:297:10)
at DragListener.reposition (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1647275824145/chipper/dist/js/scenery/js/listeners/DragListener.js:566:36)
at DragListener._dragAction.PhetioAction.parameters.name (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1647275824145/chipper/dist/js/scenery/js/listeners/DragListener.js:168:16)
id: Bayes Chrome
Snapshot from 3/14/2022, 10:37:04 AM

@pixelzoom pixelzoom reopened this Mar 14, 2022
@pixelzoom pixelzoom self-assigned this Mar 14, 2022
@pixelzoom
Copy link
Contributor

I fuzzed tested the unbuilt sim for 30 minutes and did not encounter this problem.
URL: geometric-optics_en.html?brand=phet&ea&debugger&fuzz

@pixelzoom pixelzoom removed their assignment Mar 17, 2022
@KatieWoe
Copy link
Author

geometric-optics-basics : fuzz : unbuilt
https://bayes.colorado.edu/continuous-testing/ct-snapshots/1647574186761/geometric-optics-basics/geometric-optics-basics_en.html?continuousTest=%7B%22test%22%3A%5B%22geometric-optics-basics%22%2C%22fuzz%22%2C%22unbuilt%22%5D%2C%22snapshotName%22%3A%22snapshot-1647574186761%22%2C%22timestamp%22%3A1647579661668%7D&brand=phet&ea&fuzz&memoryLimit=1000
Query: brand=phet&ea&fuzz&memoryLimit=1000
Uncaught Error: Cannot normalize a zero-magnitude vector
Error: Cannot normalize a zero-magnitude vector
at Vector2.normalized (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1647574186761/chipper/dist/js/dot/js/Vector2.js:211:13)
at getRayDirections (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1647574186761/chipper/dist/js/geometric-optics/js/common/model/LightRays.js:128:38)
at https://bayes.colorado.edu/continuous-testing/ct-snapshots/1647574186761/chipper/dist/js/geometric-optics/js/common/model/LightRays.js:64:26
at listener (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1647574186761/chipper/dist/js/axon/js/Multilink.js:46:11)
at TinyProperty.emit (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1647574186761/chipper/dist/js/axon/js/TinyEmitter.js:68:9)
at DerivedProperty._notifyListeners (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1647574186761/chipper/dist/js/axon/js/Property.js:227:23)
at DerivedProperty.set (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1647574186761/chipper/dist/js/axon/js/Property.js:156:14)
at DerivedProperty.getDerivedPropertyListener (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1647574186761/chipper/dist/js/axon/js/DerivedProperty.js:112:13)
at TinyProperty.emit (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1647574186761/chipper/dist/js/axon/js/TinyEmitter.js:68:9)
at NumberProperty._notifyListeners (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1647574186761/chipper/dist/js/axon/js/Property.js:227:23)
id: Bayes Chrome
Snapshot from 3/17/2022, 9:29:46 PM

@pixelzoom
Copy link
Contributor

This is a non-blocking error. It won't cause the sim to crash, and is unlikely to result in any noticeable problems in practice. 1.1 was published with this as a known issue.

@KatieWoe
Copy link
Author

KatieWoe commented Sep 9, 2022

Can you confirm if this issue is still needed? I don't see it in CT right now, but it is noted as rare. For phetsims/qa#832

@pixelzoom
Copy link
Contributor

Yes, please keep this open.

@pixelzoom pixelzoom removed their assignment Sep 9, 2022
@pixelzoom
Copy link
Contributor

It is not necessary to address this for #278, the 1.3 PhET-iO release.

@samreid
Copy link
Member

samreid commented Sep 22, 2023

This recurred in the 9/21/2023 5:41:05pm column. At this week's iteration planning meeting, we agreed we have an iteration goal to address CT errors this iteration. Can/should we remove the deferred label from this? Who should take the lead?

@pixelzoom
Copy link
Contributor

This happens rarely. But I'll have a look.

@pixelzoom pixelzoom self-assigned this Sep 22, 2023
pixelzoom added a commit that referenced this issue Sep 22, 2023
@pixelzoom
Copy link
Contributor

pixelzoom commented Sep 22, 2023

I'm unable to reproduce locally after 20 minutes of fuzzing.

And it's unclear how this error can ever occur. The vector that's reported as having zero magnitude is objectOpticVector in LightRays, computed like this:

  const objectOpticVector = optic.positionProperty.value.minus( opticalObjectPosition );

So for objectOpticVector to have zero magnitude, the optic and object would have to be at the same position. And that's explicitly not allowed in this sim. In GOConstants:

  MIN_DISTANCE_FROM_OBJECT_TO_OPTIC: 40, // cm

In the above commit, I added this more detailed assertion in LightRays, and I'll will wait for the next failure in CT before doing further investigation:

  const objectOpticVector = optic.positionProperty.value.minus( opticalObjectPosition );

+  //TODO https://github.com/phetsims/geometric-optics/issues/178
+  assert && assert( objectOpticVector.magnitude !== 0,
+    `unexpected zero-magnitude vector: objectOpticVector=${objectOpticVector}, ` +
+    `optic.position=${optic.positionProperty.value}, opticalObjectPosition=${opticalObjectPosition}` );

@pixelzoom
Copy link
Contributor

Nothing in CT for 5 days, and I cannot reproduce this locally. Since this happens rarely, it's unlikely to be masking other problems, and I'd like to keep this issue open. But I'm going to unassigned until this sim is worked on again.

@pixelzoom
Copy link
Contributor

pixelzoom commented Jan 3, 2024

Still occurring occassionally:

geometric-optics-basics : multitouch-fuzz : unbuilt
http://128.138.93.172/continuous-testing/ct-snapshots/1704309105853/geometric-optics-basics/geometric-optics-basics_en.html?continuousTest=%7B%22test%22%3A%5B%22geometric-optics-basics%22%2C%22multitouch-fuzz%22%2C%22unbuilt%22%5D%2C%22snapshotName%22%3A%22snapshot-1704309105853%22%2C%22timestamp%22%3A1704309663958%7D&brand=phet&ea&fuzz&fuzzPointers=2&supportsPanAndZoom=false
Query: brand=phet&ea&fuzz&fuzzPointers=2&supportsPanAndZoom=false
Uncaught Error: Cannot normalize a zero-magnitude vector
Error: Cannot normalize a zero-magnitude vector
at (Vector2.ts:200:12)
at normalized (LightRays.ts:172:38)
at getRayDirections (LightRays.ts:94:38)
at callback (Multilink.ts:111:10)
at listener (TinyEmitter.ts:123:8)
at emit (ReadOnlyProperty.ts:328:22)
at _notifyListeners (ReadOnlyProperty.ts:275:13)
at unguardedSet (ReadOnlyProperty.ts:259:11)
at set (Property.ts:54:10)
at (DragListener.ts:687:34)
[URL] http://128.138.93.172/continuous-testing/aqua/html/sim-test.html?url=..%2F..%2Fct-snapshots%2F1704309105853%2Fgeometric-optics-basics%2Fgeometric-optics-basics_en.html&simQueryParameters=brand%3Dphet%26ea%26fuzz%26fuzzPointers%3D2%26supportsPanAndZoom%3Dfalse&testInfo=%7B%22test%22%3A%5B%22geometric-optics-basics%22%2C%22multitouch-fuzz%22%2C%22unbuilt%22%5D%2C%22snapshotName%22%3A%22snapshot-1704309105853%22%2C%22timestamp%22%3A1704309663958%7D
[NAVIGATED] http://128.138.93.172/continuous-testing/aqua/html/sim-test.html?url=..%2F..%2Fct-snapshots%2F1704309105853%2Fgeometric-optics-basics%2Fgeometric-optics-basics_en.html&simQueryParameters=brand%3Dphet%26ea%26fuzz%26fuzzPointers%3D2%26supportsPanAndZoom%3Dfalse&testInfo=%7B%22test%22%3A%5B%22geometric-optics-basics%22%2C%22multitouch-fuzz%22%2C%22unbuilt%22%5D%2C%22snapshotName%22%3A%22snapshot-1704309105853%22%2C%22timestamp%22%3A1704309663958%7D
[NAVIGATED] about:blank
[NAVIGATED] http://128.138.93.172/continuous-testing/ct-snapshots/1704309105853/geometric-optics-basics/geometric-optics-basics_en.html?continuousTest=%7B%22test%22%3A%5B%22geometric-optics-basics%22%2C%22multitouch-fuzz%22%2C%22unbuilt%22%5D%2C%22snapshotName%22%3A%22snapshot-1704309105853%22%2C%22timestamp%22%3A1704309663958%7D&brand=phet&ea&fuzz&fuzzPointers=2&supportsPanAndZoom=false
[CONSOLE] enabling assert
[CONSOLE] continuous-test-load
[PAGE ERROR] Error: Error: Cannot normalize a zero-magnitude vector
at Vector2.normalized (http://128.138.93.172/continuous-testing/ct-snapshots/1704309105853/chipper/dist/js/dot/js/Vector2.js:193:13)
at getRayDirections (http://128.138.93.172/continuous-testing/ct-snapshots/1704309105853/chipper/dist/js/geometric-optics/js/common/model/LightRays.js:138:38)
at http://128.138.93.172/continuous-testing/ct-snapshots/1704309105853/chipper/dist/js/geometric-optics/js/common/model/LightRays.js:71:26
at listener (http://128.138.93.172/continuous-testing/ct-snapshots/1704309105853/chipper/dist/js/axon/js/Multilink.js:50:11)
at TinyProperty.emit (http://128.138.93.172/continuous-testing/ct-snapshots/1704309105853/chipper/dist/js/axon/js/TinyEmitter.js:96:9)
at Vector2Property._notifyListeners (http://128.138.93.172/continuous-testing/ct-snapshots/1704309105853/chipper/dist/js/axon/js/ReadOnlyProperty.js:252:23)
at Vector2Property.unguardedSet (http://128.138.93.172/continuous-testing/ct-snapshots/1704309105853/chipper/dist/js/axon/js/ReadOnlyProperty.js:201:14)
at Vector2Property.set (http://128.138.93.172/continuous-testing/ct-snapshots/1704309105853/chipper/dist/js/axon/js/ReadOnlyProperty.js:186:12)
at set value [as value] (http://128.138.93.172/continuous-testing/ct-snapshots/1704309105853/chipper/dist/js/axon/js/Property.js:48:11)
at DragListener.reposition (http://128.138.93.172/continuous-testing/ct-snapshots/1704309105853/chipper/dist/js/scenery/js/listeners/DragListener.js:534:36)
[CONSOLE] continuous-test-error

id: "Sparky Node Puppeteer"
Snapshot from 1/3/2024, 12:11:45 PM

And here's the failure location in LightRays:

172     directions.push( firstFocalVector.normalized() );

@pixelzoom
Copy link
Contributor

I added this workaround in the above commit. Will leave this issue open to confirm that CT is happy.

    if ( firstFocalVector.equals( Vector2.ZERO ) ) {
      // Prevent attempt to normalize a zero vector by ensuring that there is always a small non-zero x component.
      // See https://github.com/phetsims/geometric-optics/issues/178
      firstFocalVector.addXY( 1e-20, 0 );
    }

pixelzoom added a commit that referenced this issue Jan 3, 2024
@pixelzoom pixelzoom self-assigned this Jan 3, 2024
@pixelzoom
Copy link
Contributor

CT is happy. Closing.

@phet-dev phet-dev reopened this Jan 6, 2024
@phet-dev
Copy link
Contributor

phet-dev commented Jan 6, 2024

Reopening because there is a TODO marked for this issue.

pixelzoom added a commit that referenced this issue Jan 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants