Merge pull request #436 from quantified-uncertainty/quinn-reducer-dev

fixed typescript (to `reducer-dev`) apr29
This commit is contained in:
Umur Ozkul 2022-04-29 21:35:13 +02:00 committed by GitHub
commit b85ea5b419
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 48 additions and 17 deletions

View File

@ -2,9 +2,12 @@ import * as _ from "lodash";
import {
genericDist,
samplingParams,
environment,
evaluatePartialUsingExternalBindings,
evaluateUsingOptions,
externalBindings,
expressionValue,
recordEV,
errorValue,
distributionError,
toPointSet,
@ -15,6 +18,8 @@ import {
mixedShape,
sampleSetDist,
symbolicDist,
defaultEnvironment,
defaultSamplingEnv,
} from "../rescript/TypescriptInterface.gen";
export {
makeSampleSetDist,
@ -50,10 +55,7 @@ import {
} from "../rescript/Distributions/DistributionOperation/DistributionOperation.gen";
export type { samplingParams, errorValue, externalBindings as bindings };
export let defaultSamplingInputs: samplingParams = {
sampleCount: 10000,
xyPointLength: 10000,
};
export let defaultSamplingInputs: samplingParams = defaultSamplingEnv;
export type result<a, b> =
| {
@ -90,8 +92,9 @@ export type squiggleExpression =
| tagged<"symbol", string>
| tagged<"string", string>
| tagged<"call", string>
| tagged<"lambda", [string[], internalCode]>
| tagged<"lambda", [string[], recordEV, internalCode]>
| tagged<"array", squiggleExpression[]>
| tagged<"arrayString", string[]>
| tagged<"boolean", boolean>
| tagged<"distribution", Distribution>
| tagged<"number", number>
@ -100,16 +103,19 @@ export type squiggleExpression =
export function run(
squiggleString: string,
bindings?: externalBindings,
samplingInputs?: samplingParams
samplingInputs?: samplingParams,
environ?: environment
): result<squiggleExpression, errorValue> {
let b = bindings ? bindings : {};
let si: samplingParams = samplingInputs
? samplingInputs
: defaultSamplingInputs;
let result: result<expressionValue, errorValue> =
evaluateUsingExternalBindings(squiggleString, b);
return resultMap(result, (x) => createTsExport(x, si));
let e = environ ? environ : defaultEnvironment;
let res: result<expressionValue, errorValue> = evaluateUsingOptions(
{ externalBindings: b, environment: e },
squiggleString
); // , b, e);
return resultMap(res, (x) => createTsExport(x, si));
}
// Run Partial. A partial is a block of code that doesn't return a value
@ -118,7 +124,11 @@ export function runPartial(
bindings: externalBindings,
_samplingInputs?: samplingParams
): result<externalBindings, errorValue> {
return evaluatePartialUsingExternalBindings(squiggleString, bindings);
return evaluatePartialUsingExternalBindings(
squiggleString,
bindings,
defaultEnvironment
);
}
function createTsExport(
@ -158,6 +168,8 @@ function createTsExport(
}
})
);
case "EvArrayString":
return tag("arrayString", x.value);
case "EvBool":
return tag("boolean", x.value);
case "EvCall":
@ -219,6 +231,8 @@ function convertRawToTypescript(
return tag("string", result._0);
case 7: // EvSymbol
return tag("symbol", result._0);
case 8: // EvArrayString
return tag("arrayString", result._0);
}
}
@ -275,6 +289,10 @@ type rescriptExport =
| {
TAG: 7; // EvSymbol
_0: string;
}
| {
TAG: 8; // EvArrayString
_0: string[];
};
type rescriptDist =

View File

@ -1,12 +1,12 @@
module ExpressionValue = ReducerInterface_ExpressionValue
type expressionValue = ReducerInterface_ExpressionValue.expressionValue
let runGenericOperation = DistributionOperation.run(
~env={
let defaultEnv: DistributionOperation.env = {
sampleCount: MagicNumbers.Environment.defaultSampleCount,
xyPointLength: MagicNumbers.Environment.defaultXYPointLength,
},
)
}
let runGenericOperation = DistributionOperation.run(~env=defaultEnv)
module Helpers = {
let arithmeticMap = r =>

View File

@ -1,3 +1,4 @@
let defaultEnv: DistributionOperation.env
let dispatch: (
ReducerInterface_ExpressionValue.functionCall,
ReducerInterface_ExpressionValue.environment,

View File

@ -49,6 +49,9 @@ type externalBindings = Reducer.externalBindings
@genType
type expressionValue = ReducerInterface_ExpressionValue.expressionValue
@genType
type recordEV = ReducerInterface_ExpressionValue.record
@genType
type errorValue = Reducer_ErrorValue.errorValue
@ -72,3 +75,12 @@ let distributionErrorToString = DistributionTypes.Error.toString
@genType
type internalCode = ReducerInterface_ExpressionValue.internalCode
@genType
let defaultSamplingEnv = ReducerInterface_GenericDistribution.defaultEnv
@genType
type environment = ReducerInterface_ExpressionValue.environment
@genType
let defaultEnvironment = ReducerInterface_ExpressionValue.defaultEnvironment