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

20746: MAJOR Engine updates for reactAggregate #9

Merged
merged 9 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ jobs:
with:
build-type: ${{ inputs.build-type }}
optional-release-tag: ${{ inputs.optional-release-tag }}

# Add NPM test here when the time is right

npm-test:
uses: howsoai/.github/.github/workflows/npm-test.yml@main
secrets: inherit

release:
needs:
Expand All @@ -33,4 +35,4 @@ jobs:
uses: howsoai/.github/.github/workflows/npm-release.yml@main
secrets: inherit
with:
version: ${{ needs.metadata.outputs.version }}
version: ${{ needs.metadata.outputs.version }}
42 changes: 21 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"build": "tsc --build",
"lint": "tsc --noEmit && eslint 'src/**'",
"lint:fix": "eslint --fix 'src/**'",
"prepack": "npm run build"
"prepack": "npm run build",
"test": "tsc --noEmit && eslint 'src/**'"
},
"files": [
"LICENSE.txt",
Expand All @@ -36,8 +37,8 @@
"./package.json": "./package.json"
},
"dependencies": {
"@howso/amalgam-lang": "^0.0.10",
"@howso/openapi-client": "^1.0.1",
"@howso/amalgam-lang": "^0.0.11",
"@howso/openapi-client": "^2.0.0",
"@microsoft/fetch-event-source": "^2.0.1",
"uuid": "^9.0.0"
},
Expand All @@ -52,7 +53,7 @@
"eslint-plugin-prettier": "^5.1.3",
"prettier": "^3.2.5",
"rimraf": "^5.0.5",
"typescript": "^5.3.3"
"typescript": "^5.5.3"
},
"eslintConfig": {
"root": true,
Expand Down
15 changes: 3 additions & 12 deletions src/client/capabilities/trainees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,19 @@ import type {
FeatureAttributes,
FeatureConviction,
FeatureConvictionRequest,
FeatureContributionsRequest,
FeaturePredictionStats,
FeaturePredictionStatsRequest,
FeatureMarginalStats,
FeatureMarginalStatsRequest,
FeatureResidualsRequest,
FeatureMdaRequest,
TrainRequest,
ReactRequest,
ReactResponse,
ReactIntoFeaturesRequest,
ReactIntoFeaturesResponse,
ReactSeriesRequest,
ReactSeriesResponse,
ReactIntoTraineeRequest,
ReactIntoTraineeResponse,
SetAutoAnalyzeParamsRequest,
TraineeIdentity,
TraineeWorkflowAttributesRequest,
TraineeWorkflowAttributes,
} from "@howso/openapi-client/models";
import { Trainee } from "../../trainees/index";

Expand All @@ -40,16 +35,12 @@ export interface ITraineeClient {
setAutoAnalyzeParams(traineeId: string, request: SetAutoAnalyzeParamsRequest): Promise<void>;
react(traineeId: string, request: ReactRequest): Promise<ReactResponse>;
reactSeries(traineeId: string, request: ReactSeriesRequest): Promise<ReactSeriesResponse>;
reactIntoTrainee(traineeId: string, request: ReactIntoTraineeRequest): Promise<ReactIntoTraineeResponse>;
reactIntoFeatures(traineeId: string, request: ReactIntoFeaturesRequest): Promise<ReactIntoFeaturesResponse>;
getCases(traineeId: string, request?: CasesRequest): Promise<Cases>;
getInternalParams(traineeId: string, request: TraineeWorkflowAttributesRequest): Promise<TraineeWorkflowAttributes>;
getNumTrainingCases(traineeId: string): Promise<number>;
setFeatureAttributes(traineeId: string, attributes: Record<string, FeatureAttributes>): Promise<void>;
getFeatureAttributes(traineeId: string): Promise<Record<string, FeatureAttributes>>;
getFeatureConviction(traineeId: string, request: FeatureConvictionRequest): Promise<FeatureConviction>;
getFeatureResiduals(traineeId: string, request: FeatureResidualsRequest): Promise<Record<string, number>>;
getFeatureContributions(traineeId: string, request: FeatureContributionsRequest): Promise<Record<string, number>>;
getFeatureMda(traineeId: string, request: FeatureMdaRequest): Promise<Record<string, number>>;
getPredictionStats(traineeId: string, request: FeaturePredictionStatsRequest): Promise<FeaturePredictionStats>;
getMarginalStats(traineeId: string, request: FeatureMarginalStatsRequest): Promise<FeatureMarginalStats>;
}
145 changes: 39 additions & 106 deletions src/client/wasm/client.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import type { AmalgamRequest, AmalgamResponseBody, AmalgamCommand } from "@howso/amalgam-lang/worker";
import type { Capabilities, ITraineeClient, ISessionClient } from "../capabilities/index.js";
import { AmalgamCoreResponse, prepareCoreRequest, prepareCoreResponse } from "./core.js";

import { AmalgamOptions } from "@howso/amalgam-lang/wasm";
import {
AnalyzeRequest,
Cases,
CasesRequest,
CaseCountResponse,
FeatureAttributes,
FeaturePredictionStats,
FeaturePredictionStatsRequest,
FeatureMarginalStats,
FeatureMarginalStatsRequest,
TrainRequest,
Expand All @@ -27,18 +24,11 @@ import {
TraineeIdentity,
ReactIntoFeaturesRequest,
ReactIntoFeaturesResponse,
ReactIntoTraineeRequest,
ReactIntoTraineeResponse,
FeatureContributionsRequest,
FeatureMdaRequest,
FeatureConviction,
FeatureConvictionRequest,
FeatureResidualsRequest,
CasesRequestToJSON,
FeatureAttributesToJSON,
FeatureAttributesFromJSON,
FeaturePredictionStatsFromJSON,
FeaturePredictionStatsRequestToJSON,
FeatureMarginalStatsFromJSON,
FeatureMarginalStatsRequestToJSON,
SessionToJSON,
Expand All @@ -52,17 +42,19 @@ import {
ReactSeriesResponseFromJSON,
ReactIntoFeaturesRequestToJSON,
ReactIntoFeaturesResponseFromJSON,
ReactIntoTraineeRequestToJSON,
ReactIntoTraineeResponseFromJSON,
FeatureConvictionRequestToJSON,
FeatureContributionsRequestToJSON,
FeatureResidualsRequestToJSON,
FeatureMdaRequestToJSON,
AnalyzeRequestToJSON,
ReactAggregateResponse,
ReactAggregateRequest,
ReactAggregateResponseContent,
ReactAggregateResponseFromJSON,
ReactAggregateRequestToJSON,
TraineeWorkflowAttributesRequest,
TraineeWorkflowAttributesFromJSON,
TraineeWorkflowAttributesRequestToJSON,
} from "@howso/openapi-client/models";
import { RequiredError, mapValues } from "@howso/openapi-client/runtime";
import { v4 as uuid } from "uuid";

import { Trainee } from "../../trainees/index.js";
import { BaseClient, TraineeBaseCache } from "../capabilities/index";
import { ProblemError } from "../errors";
Expand Down Expand Up @@ -627,6 +619,20 @@ export class WasmClient extends BaseClient implements ITraineeClient, ISessionCl
await this.autoPersistTrainee(trainee.id);
}

/**
* Set the parameters use by auto analyze.
*/
public async getInternalParams(traineeId: string, request: TraineeWorkflowAttributesRequest = {}) {
await this.autoResolveTrainee(traineeId);

const response = this.execute(
traineeId,
"get_internal_parameters",
TraineeWorkflowAttributesRequestToJSON(request),
);
return TraineeWorkflowAttributesFromJSON(response);
}

/**
* Set the parameters use by auto analyze.
* @param traineeId The trainee identifier.
Expand Down Expand Up @@ -704,6 +710,23 @@ export class WasmClient extends BaseClient implements ITraineeClient, ISessionCl
return ReactResponseFromJSON({ warnings, content });
}

/**
* React to a trainee.
* @param traineeId The trainee identifier.
* @param request The react parameters.
* @returns The react response.
*/
public async reactAggregate(traineeId: string, request: ReactAggregateRequest): Promise<ReactAggregateResponse> {
const trainee = await this.autoResolveTrainee(traineeId);
this.preprocessReactRequest(trainee, request);
const { warnings = [], content } = await this.execute<ReactAggregateResponseContent>(
traineeId,
"react_aggregate",
ReactAggregateRequestToJSON(request),
);
return ReactAggregateResponseFromJSON({ warnings, content });
}

/**
* React in series to a trainee.
* @param traineeId The trainee identifier.
Expand Down Expand Up @@ -741,42 +764,6 @@ export class WasmClient extends BaseClient implements ITraineeClient, ISessionCl
return ReactIntoFeaturesResponseFromJSON({ warnings });
}

/**
* Compute and cache specified feature interpretations.
* @param traineeId The trainee identifier.
* @param request The react into trainee request.
* @returns The react into trainee response.
*/
public async reactIntoTrainee(
traineeId: string,
request: ReactIntoTraineeRequest,
): Promise<ReactIntoTraineeResponse> {
await this.autoResolveTrainee(traineeId);

const { warnings = [] } = await this.execute<never>(traineeId, "react_into_trainee", {
...ReactIntoTraineeRequestToJSON(request),
});
return ReactIntoTraineeResponseFromJSON({ warnings });
}

/**
* Get prediction stats of a trainee.
* @param traineeId The trainee identifier.
* @param request The prediction stats request.
* @returns The prediction stats.
*/
public async getPredictionStats(
traineeId: string,
request: FeaturePredictionStatsRequest,
): Promise<FeaturePredictionStats> {
await this.autoResolveTrainee(traineeId);

const { content, warnings = [] } = await this.execute<never>(traineeId, "get_prediction_stats", {
...FeaturePredictionStatsRequestToJSON(request),
});
return FeaturePredictionStatsFromJSON({ content, warnings });
}

/**
* Get marginal stats of a trainee.
* @param traineeId The trainee identifier.
Expand Down Expand Up @@ -810,60 +797,6 @@ export class WasmClient extends BaseClient implements ITraineeClient, ISessionCl
return content;
}

/**
* Get contributions for features.
* @deprecated Use getPredictionStats instead.
* @param traineeId The trainee identifier.
* @param request The feature contributions request.
* @returns A map of feature name to contribution value.
*/
public async getFeatureContributions(
traineeId: string,
request: FeatureContributionsRequest,
): Promise<Record<string, number>> {
await this.autoResolveTrainee(traineeId);

const { content } = await this.execute<Record<string, number>>(traineeId, "get_feature_contributions", {
...FeatureContributionsRequestToJSON(request),
});
return content;
}

/**
* Get residuals for features.
* @deprecated Use getPredictionStats instead.
* @param traineeId The trainee identifier.
* @param request The feature residuals request.
* @returns A map of feature name to residual value.
*/
public async getFeatureResiduals(
traineeId: string,
request: FeatureResidualsRequest,
): Promise<Record<string, number>> {
await this.autoResolveTrainee(traineeId);

const { content } = await this.execute<Record<string, number>>(traineeId, "get_feature_residuals", {
...FeatureResidualsRequestToJSON(request),
});
return content;
}

/**
* Get mean decrease in accuracy for features.
* @deprecated Use getPredictionStats instead.
* @param traineeId The trainee identifier.
* @param request The feature MDA request.
* @returns A map of feature name to MDA value.
*/
public async getFeatureMda(traineeId: string, request: FeatureMdaRequest): Promise<Record<string, number>> {
await this.autoResolveTrainee(traineeId);

const { content } = await this.execute<Record<string, number>>(traineeId, "get_feature_mda", {
...FeatureMdaRequestToJSON(request),
});
return content;
}

/**
* Preprocess a request for react or react series.
* @param trainee The trainee identifier.
Expand Down