Skip to content

New UI features#31

Merged
bnmajor merged 13 commits intomasterfrom
new-ui-features
Mar 26, 2025
Merged

New UI features#31
bnmajor merged 13 commits intomasterfrom
new-ui-features

Conversation

@bnmajor
Copy link
Copy Markdown
Collaborator

@bnmajor bnmajor commented Mar 17, 2025

image

Fixes #22, #23, #26

bnmajor added 3 commits March 17, 2025 15:39
Use agent, action and reward information for an episode to create some initial,
simple plots.
Points of interest are currently just any step that received a reward for one
(or more) agent(s). Clicking on a point will jump to that point of interest,
displaying the current frame and information for any associated agent steps
(agent name, action, and reward).
@bnmajor bnmajor requested a review from brianhelba March 17, 2025 23:05
bnmajor added 4 commits March 21, 2025 10:54
This will very likely need to be re-thought as the project grows, but for now
we can simply hard-code mappings of actions to string representations for
environments with discrete action spaces.
- Stagger text to handle crowded timelines
- Format float values
bnmajor added 2 commits March 21, 2025 14:14
- Use dot operator rather than subscripts
- Use better naming
- Leverage Python's standard library to simplify code
Comment thread mixtape/core/views.py
Comment thread mixtape/environments/mappings.py Outdated
Comment thread mixtape/core/views.py
Comment thread mixtape/core/views.py
plot_data['action_v_reward'][entry.agent][action] += entry.total_rewards
plot_data['action_v_frequency'][action] += entry.action_frequency

key_steps = steps.annotate(total_rewards=Sum('agent_steps__reward', default=0)).order_by(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could this be combined with the original steps definition, so we don't need to execute 2 separate queries when steps and key_steps are evaluated? The extra .annotate shouldn't impact the use of steps, but maybe you don't want steps to have a different ordering by number (although that seems like a sensible ordering)?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

However, if you think it's better to keep these logically separated to make future refactoring easier, that's a reasonable price to pay for one more query.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

As you mentioned, these have remained separate queries for the ease of refactoring. This "any reward was received" as a metric for determining points of interest should be dropped altogether in the future in favor of more advanced insights once they've been added.

<div class="content-center w-1/2 h-full min-h-full">
<img class="max-w-full h-auto" src="{{ step.image.url }}" alt="Step Image">
<div class="grid grid-cols-12">
<div class="col-span-3 content-center" x-data="{
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would it help to split each of these plots into its own template and {% include them? I'm not sure if that would be more readable, but I think this file is getting pretty big.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I think that would make sense! I did not do that in this PR, but my WIP to produce aggregated results across many episodes does include changes to break out components and then include them as needed.

Comment thread mixtape/core/templates/core/base.html Outdated
Comment thread mixtape/core/models/agent_step.py
Comment thread mixtape/core/views.py Outdated
Comment thread mixtape/core/templates/core/distribution_plot.html Outdated
Comment thread mixtape/core/templates/core/distribution_plot.html Outdated
Comment thread mixtape/core/templates/core/insights.html Outdated
Comment thread mixtape/core/templates/core/insights.html Outdated
Comment thread mixtape/core/templates/core/insights.html Outdated
Comment thread mixtape/core/templates/core/insights.html Outdated
:disabled="currentStep === 0"
@click="currentStep = 0"
>
<!-- Rewind Icon -->
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It might be a lot easier to use an icon library. I've used https://remixicon.com/ for several other server-rendered applications.

You should just need to add

<link href="https://unpkg.com/remixicon/fonts/remixicon.css" rel="stylesheet"/>

then you'll be able to use something like

< i class="ri-rewind-line"></i>

instead of all this SVG.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I have a follow-up branch with additional cleanup for styles. I will include this change in that PR.

</div>
<div class="grid grid-cols-12">
<div class="col-span-6">
{% for step in steps %}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Assuming that the step-based views are going to continue, I think we should definitely switch to a more scalable method for rendering this much data. Emitting this much HTML at once may be problematic for many users (I'm worried we're already in "it works on my machine" territory, given that developers have over-powered machines relative to many users).

#19 is one approach, though I'm happy to discuss others.

This change is out of scope for this PR, but it'd be good to get this fixed ASAP, unless we're not planning to allow the selection of individual steps (or things of equivalent cardinality) anymore.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I've opened this up as a new issue for follow-up once this PR is in.

Comment thread mixtape/core/views.py
key_steps = steps.annotate(total_rewards=Sum('agent_steps__reward', default=0)).order_by(
'number'
)
plot_data['rewards_over_time'] = list(accumulate(ks.total_rewards for ks in key_steps))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think you can make the database do this for you with a Window function, something like

Window(Sum('total_rewards'), order_by='number')

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I was only able to get this approach to work with a sub-query (apparently you cannot pass an aggregate into a Window function) and this consistently increased both my query times as well as time to load the page so I did not make this change in this PR. Open to suggestions though if I'm maybe just missing something here...

bnmajor added 2 commits March 25, 2025 08:56
- Use more meaningful variable names
- Simplify code to improve readability
- Use unpkg for all packages
@bnmajor
Copy link
Copy Markdown
Collaborator Author

bnmajor commented Mar 26, 2025

@brianhelba I'm going to merge this in for now so that but please let me know if you have any additional concerns and I can address them in some follow-up PRs.

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.

Create reward and action distribution plots

2 participants