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

get first frame during initialize and start paused #457

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

interim17
Copy link
Contributor

@interim17 interim17 commented Feb 25, 2025

Time Estimate or Size

medium

Problem

@meganrm found some bugs resulting from recent prefetching branch merge

Solution

These changes:

  • use isPreFetching (along with isPlaying) as state variable to control prefetching behavior (previously: streaming)
  • clarify logic related to frame selection, streaming, and cache overflow handling
  • update default totalSteps in client simulators to be Infinity because frame clamping in goToFrame was conflicting with totalSteps that were lower than the number of frames actually emitted by the binding sim
  • update simulator initialize methods to always request frame 0 during initialization
  • remove some unneeded streaming change callback from viewport callbacks
  • pare down cache and streaming log display in the test-bed

This is intended as a prompt fix for bugs, and implies a few ongoing pieces of work:

  • Bug fix (non-breaking change which fixes an issue)

Copy link

github-actions bot commented Feb 25, 2025

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 24.7% 2713 / 10983
🔵 Statements 24.7% 2713 / 10983
🔵 Functions 27.91% 170 / 609
🔵 Branches 82.18% 383 / 466
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
examples/src/Viewer.tsx 0% 0% 0% 0% 1-1080
examples/src/Components/CacheAndStreamingLogs.tsx 0% 0% 0% 0% 1-51
examples/src/simulators/BindingSimulator2D.ts 0% 0% 0% 0% 1-389
examples/src/simulators/CurveSimulator.ts 0% 0% 0% 0% 1-179
examples/src/simulators/MetaballSimulator.ts 0% 0% 0% 0% 1-185
examples/src/simulators/PointSimulator.ts 0% 0% 0% 0% 1-144
examples/src/simulators/PointSimulatorLive.ts 0% 0% 0% 0% 1-170
examples/src/simulators/SingleCurveSimulator.ts 0% 0% 0% 0% 1-158
src/controller/index.ts 25.47% 66.66% 19.23% 25.47% 81-82, 90-107, 127-181, 184-188, 191-196, 199-200, 206-220, 224-225, 237-240, 243-246, 249-274, 284-285, 288-291, 294-313, 334-339, 342-343, 355-357, 360-373, 385-387, 390-399, 402-415, 418-426, 429-475, 478-485, 488-489, 492-493, 496-506, 509-512, 515-523, 526-534, 537-567, 570-571, 574-580, 590-591, 594-595, 598-599, 602-603, 606-607, 610-611, 614-615, 618-619, 622-623
src/simularium/ClientSimulator.ts 11.17% 100% 0% 11.17% 26-39, 42-45, 47-50, 52-53, 56-123, 126-131, 134-137, 149-162, 165-169, 172-176, 179-183, 186-194, 197-204, 207-214
src/simularium/LocalFileSimulator.ts 19.19% 100% 0% 19.19% 22-36, 39-42, 44-47, 49-50, 53-61, 64-66, 69-81, 84-87, 90-91, 94-101, 104-107, 111-112, 120-132, 135-136
src/simularium/RemoteSimulator.ts 51.82% 100% 34.37% 51.82% 33, 42, 45, 59-60, 67-68, 75-95, 98-105, 114-116, 119-121, 124-126, 129-138, 188-189, 200-203, 209-214, 217-226, 257-264, 267-274, 277-287, 301-309, 312-320, 323-324
src/simularium/VisData.ts 73.78% 82.92% 78.57% 73.78% 29-43, 62-63, 66-67, 70-71, 91, 110-114, 150-151, 194, 205-207, 213-219, 228-234, 246-248, 292-298
src/simularium/VisDataCache.ts 78.26% 80% 92.3% 78.26% 52-53, 59-70, 74-81, 115, 126-127, 133-134, 177-178, 186-190, 218-220, 229-230, 252-253, 255-257, 262-267
src/test/DummyRemoteSimulator.ts 68.7% 85.71% 57.14% 68.7% 72-73, 76-78, 92-93, 105-108, 114-115, 117-119, 131-149, 162-171
src/viewport/index.tsx 27.22% 100% 0% 27.22% 117-118, 121-176, 179-243, 246-294, 297-307, 310-399, 532-540, 543-551, 556-582, 585-589, 592-597, 600-604, 607-622, 625-629, 632-676, 679-706, 709-713, 716-720, 723-745
Generated in workflow #574 for commit 8ddc95e by the Vitest Coverage Report Action

@@ -247,6 +247,9 @@ export class RemoteSimulator implements ISimulator {
"Start Trajectory File Playback"
);
})
.then(() => {
this.requestFrame(0);
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the websocket request is not a promise my understanding is there is no guarantee that the request has completed before this next block is executed. Could that cause any problems?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In practice, they seem to be landing in the proper order without issue, but you're right that there is no guarantee without a promise, which theoretically makes a race condition here.

The most precise fix here would be to change sendWebSocketRequest to return a promise. Hackier fix would be to resolve a Promise here with a tiny arbitrary delay, or just leave as is for the moment because things seem to be landing in the correct order.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you move the this.requestFrame within the webSocketRequest switch bracket?

})
.then(() => {
this.requestFrame(0);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like I asked about this before, but can’t this.requestFrame(0) just be in the previous block?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

@@ -433,7 +412,7 @@ export default class SimulariumController {
// calls simulator.abort()
this.stop();

this.visData.WaitForFrame(0);
this.visData.waitForFrame(0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What’s the difference between waitForFrame and requestFrame?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

requestFrame is a core method on ISimulator intended to be the way that the front end requests a single frame of data from a simulator by passing in a frame number.

waitForFrame is something internal to visData that basically sets an internal flags lockedForFrame and frameToWaitFor in order to reject incoming frames that are not the one we most recently requested. I haven't really put a lot of thought into this set up as it predates me and I haven't had much need to change/use it, but that's my understanding.

@interim17 interim17 marked this pull request as ready for review February 28, 2025 16:49
@interim17 interim17 requested a review from a team as a code owner February 28, 2025 16:49
@interim17 interim17 requested review from meganrm, ShrimpCryptid and toloudis and removed request for a team February 28, 2025 16:49
@interim17 interim17 marked this pull request as draft February 28, 2025 19:04
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