probmods / webppl-editor Goto Github PK
View Code? Open in Web Editor NEWBrowser-based editor for WebPPL
License: Other
Browser-based editor for WebPPL
License: Other
This gives the user some assurance that things are still working
The ReferenceError is successfully caught here:
print('start 2');
meh
hist(repeat(1e5, flip))
print('end 2')
But not here:
print('start 2');
hist(repeat(1e5, flip))
meh
print('end 2')
For manually suppressing things like the beta underflow / overflow
Alternatively, we could only intercept the info
, warn
, and error
methods (this would require going into webppl and changing some log
s to info
s)
icon absent:
console.info('foo')
but it's present if we do it twice:
console.info('foo')
console.info('foo')
This is needed for the Javascript boxes on dippl. I tried the following workaround, but it doesn't reliably print to the correct results box (and instead adds to the results for a previous webppl box):
var printResult = function(x){
var container = wpEditor.makeResultContainer();
container.appendChild(document.createTextNode(x));
}
I get a call stack error for a model that consists of just 128 lines, each line a flip()
call.
The error happens on the line in the compiled code right before we start running the trampoline:
var t = p(s, k, a);
This appears to work okay on the command line.
for, e.g., parameters of erps and inference algorithms.
Like on probmods.org, use localStorage
to store user modifications of code boxes and allow them to revert back to the default.
(Particularly helpful if the browser crashes -- you don't lose all your work)
My PR just got merged (here), so as soon the version on npm is updated, you can switch from using my fork to the official react-codemirror
node module.
That shows the seed that was used and the runtime (hidden by default but pops out when you click an icon in the upper right hand side of the results box)
Reproducing a Slack conversation:
andreas: on recent dev, we've changed how the trampolineRunner can be accessed (because we needed it for the mongodb params store and the old way would have made accessing it there complicated): https://github.com/probmods/webppl/blob/7df4adce7e057b34a2e634f2af1a27a042e51ad0/src/main.js#L231 — i think this means that the editor needs to adapt as well. can you take a look? i think it might be a very small change. if it looks like a bigger deal, let me know
long: i suspect that this doesn't matter. but for a somewhat bad reason. the editor creates a base runner and passes that into prepare. and then editor keeps a reference to the base runner around for things like resuming trampolining. i think that what the editor should do is keep a reference to the wrapped runner. in which case the recent access changes would matter. and i'm surprised that keeping only a ref to the base runner hasn't surfaced more errors
The editor shows a readable error message for code that calls this function:
window.foo = function() { throw new Error('foo') };
However, it doesn't show any message for code that calls this function:
window.bar = function() { throw 'bar' };
In various places in webppl (and probably also in its dependencies), errors are thrown as strings, so it's important to handle this case.
probably using Jest
I've added callbacks to webppl's MCMC
method will allow us to experiment with an inference progress interface at some point.
As a proof of concept, I made an example of using these callbacks to drive a progress bar in node.
The interface for this is very similar to the one we discussed earlier.
We're using a WebPPL editor for class assignments, and some students have complained that the cursor is jumping back to the start of the textbox while they're editing.
This only happens after webppl has thrown an error. I've tracked it down, and commenting out this line fixes it for us:
Line 551 in c9cd579
What's the run clock for? Is there a reason we shouldn't comment this line out?
Cheers,
Luke
This came up during summer school planning. I'm not sure exactly what can be done, but I think the idea is to make use of the extra information we'll get from probmods/webppl#292 and probmods/webppl#314.
We need to implement custom stack parsers to handle non-Chrome
WebPPL is a big library and takes a while to load (and, in the current version, to compile packages as well). Pages that include code boxes would look better if the code blocks could immediately be transformed into CodeMirror boxes, even if WebPPL isn't available yet.
e.g.,
var objectWithComplexDefinition = /*<fold>*/complexStuff({
thatStretchesOverMultipleLines: true,
...
})/*</fold>*/
just for the sake of quickly seeing where data/conditions happen in a model, it'd be nice if factor
, condition
, and observe
had a special color.
while we're at it, i guess sample
could also have a special color. (but then there's the natural desire for the sampling helpers like gaussian
to be colored... maybe too that's much.)
The error isn't displayed beneath the code box as expected. The following error is logged to the console:
TypeError: undefined is not an object (evaluating 'e.message')
onerror - editor.js:71806
I'm not sure which browsers you're targeting, but I thought I should mention it.
A code box that looks like this should be evaluated as Javascript:
// language: javascript
...
So that the result box is always appropriately sized to the content.
This provides additional motivation for refactoring viz to pass React elements back to editor, rather than viz rendering them itself.
(Other libraries might not be so considerate, though, so I think I need to think harder about this)
So that, e.g., webppl util.warn
results show up in the results box.
Once probmods/webppl#675 is merged, program code will no longer be parsed by sweet.js. I've tested this change with the editor to make sure that the bit where you parse exception text for syntax errors hasn't broken. As far as I can see (though you may want to check) it still basically works, although there may be a small problem with formatting:
(Update: I've just noticed that the line number reported for syntax errors differs by 1 following this change. See the example in the webppl PR.)
On the plus side, it looks like this PR fixes your 'syntax - hanging dot' todo from the editor demo page.
When I use the editor with current webppl dev (f24238e) and try to run a code box, it never exits the “running” state.
webppl-editor.min.js:14 Warning: Failed propType: Invalid prop `codeMirrorInstance` of type `function` supplied to `CodeMirror`, expected `object`. Check the render method of `CodeEditor`
After probmods/webppl#425 is merged, make a reified runner by calling util.trampolineRunners.web
on an error-handling function.
non-performant example added in 9a33aff:
repeat(1000, function() { console.log(uniform(0,1))})
By default, we should trim the output for code blocks with formatting whitespace before and after:
<pre><code>
var a = 'foo';
</code>
</pre>
For a model with ~3800 characters (~500 words), there is already a small but noticeable delay between typing and characters appearing.
If I run the following model on the editor test page...
var myDraw1 = Draw(200, 200, true);
loadImage(myDraw1, "http://dippl.org/assets/img/the_scream.jpg");
var myDraw2 = Draw(200, 200, true);
loadImage(myDraw2, "http://dippl.org/assets/img/box.png");
...I observe this error in the console:
Uncaught TypeError: resumeTrampoline is not a function
Obj.onload @ draw.js:116
console.log(1)
console.log(1)
console.log(1)
console.log(2)
console.log(2)
console.log(2)
console.log(3)
Currently, it is a gitignore'd symlink inside the compiled
directory, which is brittle.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.