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

Simple Squiggle Calculators #2265

Merged
merged 23 commits into from Sep 21, 2023
Merged

Simple Squiggle Calculators #2265

merged 23 commits into from Sep 21, 2023

Conversation

OAGr
Copy link
Contributor

@OAGr OAGr commented Sep 9, 2023

No description provided.

@changeset-bot
Copy link

changeset-bot bot commented Sep 9, 2023

🦋 Changeset detected

Latest commit: c030b44

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@quri/squiggle-lang Patch
@quri/squiggle-components Patch
@quri/prettier-plugin-squiggle Patch
vscode-squiggle Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Sep 9, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
quri-hub ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 20, 2023 0:46am
squiggle-components ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 20, 2023 0:46am
squiggle-website ✅ Ready (Inspect) Visit Preview Sep 20, 2023 0:46am
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
quri-ui ⬜️ Ignored (Inspect) Visit Preview Sep 20, 2023 0:46am

@codecov
Copy link

codecov bot commented Sep 9, 2023

Codecov Report

Patch coverage has no change and project coverage change: -0.72% ⚠️

Comparison is base (4bee95a) 73.04% compared to head (9da7a89) 72.32%.
Report is 10 commits behind head on main.

❗ Current head 9da7a89 differs from pull request most recent head c030b44. Consider uploading reports for the commit c030b44 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2265      +/-   ##
==========================================
- Coverage   73.04%   72.32%   -0.72%     
==========================================
  Files         107      109       +2     
  Lines        5349     5405      +56     
  Branches     1035     1051      +16     
==========================================
+ Hits         3907     3909       +2     
- Misses       1435     1489      +54     
  Partials        7        7              

see 9 files with indirect coverage changes

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

@OAGr
Copy link
Contributor Author

OAGr commented Sep 10, 2023

Some changes to make:

  • Fix Context / SqValuePath
  • Try to have the thing be more stable, as the code to the calculator itself gets modified.

Potential changes for future PRs:

  • Try out different layouts?
  • Think through text input vs. text area.
  • Min/max values, for functions
  • Alternative syntax, when functions take in Dict.

@OAGr OAGr temporarily deployed to Preview September 14, 2023 06:03 — with GitHub Actions Inactive
@@ -0,0 +1,212 @@
import React, { Reducer } from "react";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: I've moved much of this functionality to ViewerProvider, so this file now isn't used much.

@OAGr OAGr temporarily deployed to Preview September 19, 2023 19:32 — with GitHub Actions Inactive
* main:
  another publish fix
  attempt to fix publish script
  Version Packages
  build squiggle-lang on releases
  update-system-version in changeset-version
  update-system-version npm script
  publish to npm and vscode marketplace
  correct vscode ext link
  filter out "Patched changes" entries
  update _meta.json
  changeset-version script
  split Changelog into multiple pages
  fix hydration error
  remove unused combine-dependabot workflow
  fix codeql workflow
Copy link
Collaborator

@berekuk berekuk left a comment

Choose a reason for hiding this comment

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

I'll clean up things around Calculator and CalculatorUI myself (with custom hooks; linter warnings are concerning).

Rest of the comments flag a few minor things, nothing that would block the merge.

One more thing for the future is that I think there might be potential race conditions in asyncActions, but that's not important right now because calculator runs are synchronous.

Congrats on getting through this!

@@ -17,6 +17,7 @@ export default {
},
plugins: [
require("@quri/squiggle-components/tailwind-plugin"),
require("@tailwindcss/typography"),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Any addition to this list requires an update to the components README (Styles, section 1 and 3).

@@ -15,7 +15,16 @@ Raw functions and distributions are plotted with default parameters, while plot
Plots one or more labeled distributions on the same plot. Distributions can be either continuous, discrete, or a single number.

```
Plot.dists: ({dists: list<{name: string, value: distribution | number}>, xScale: scale, yScale: scale, title: string, showSummary: bool}) => plot
Plot.dists: ({
Copy link
Collaborator

Choose a reason for hiding this comment

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

Unrelated changes, unrelated comment: I wish this was a real syntax. Hope we'll get there eventually, when we add more kinds of parameter annotations.

@@ -41,9 +41,10 @@ export class SqValueContext {
let ast = this.valueAst;

let newAst: ASTNode | undefined;
const itemisNotTableIndex = item.type !== "cellAddress";
const itemisNotTableIndexOrCalculator =
Copy link
Collaborator

Choose a reason for hiding this comment

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

Semantic name might be better, e.g. isExtendable.


export type MergedItemSettings = PlaygroundSettings;

export const pathItemFormat = (item: PathItem): string => {
if (item.type === "cellAddress") {
return `Cell (${item.value.row},${item.value.column})`;
} else if (item.type === "calculator") {
return `calculator`;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggestion: either capitalized "Calculator", or some other notation that's not a valid variable name.

Then there'd be no ambiguity here:

Captura de pantalla 2023-09-20 a la(s) 15 26 14

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. I imagine we'll also iterate on this more over time (maybe add an icon or something with it)

@@ -107,14 +110,19 @@ export class SqValuePath {
});
}

itemsAsValuePaths() {
return this.items.map(
itemsAsValuePaths({ includeRoot = false }) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Whoa, i didn't know that this is allowed and type-safe.

I usually do fn({ param = false }: { param?: boolean }).

You'd still have to do that if you want to allow fn() instead of fn({}), though.

// This is the one that we use in the ProviderContext to store information about the calculator.
const allItems = pathItem.itemsAsValuePaths({ includeRoot: true });
const previousPathItem: SqValuePath | undefined =
allItems.length > 1 ? allItems[allItems.length - 2] : undefined;
Copy link
Collaborator

Choose a reason for hiding this comment

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

allItems.at(-2) is a nice shortcut for this.

): SqValue | undefined {
// The previous path item is the one that is the parent of the calculator result.
// This is the one that we use in the ProviderContext to store information about the calculator.
const allItems = pathItem.itemsAsValuePaths({ includeRoot: true });
Copy link
Collaborator

Choose a reason for hiding this comment

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

itemsAsValuePaths is quadratic on path length, and this function is called from extractSubvalueByPath which has a loop over itemsAsValuePaths too.

I checked that there's no O(N^4) here, unless N is the number of nested calculators, so it's fine, but it still makes me slightly nervous (what if we decide to call extractSubvalueByPath on each subpath, for some reason, or something like that?)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Should be CalculatorUI.tsx, to match the component name.

(it's somewhat hard to change on macOS, the best way I know is to git mv {c,C}alculatorUI.tsx and then to reopen in VS Code or even restart it).

)}
</div>
calculator &&
calculatorState && (
Copy link
Collaborator

Choose a reason for hiding this comment

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

Aren't both of these always defined?

@OAGr
Copy link
Contributor Author

OAGr commented Sep 21, 2023

Okay, merging now, can clean up more later.

@OAGr OAGr merged commit ff2c2a1 into main Sep 21, 2023
8 checks passed
@OAGr OAGr deleted the calculators branch September 21, 2023 23:42
This was referenced Sep 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

2 participants