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

View File

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

View File

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

View File

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