-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Stub example files for model chaining example * Fix duplicate license headers in Python runtime * Simplify execution graph for model import * Simplify graph nodes * Update graph builder for simplified nodes, add first draft of build_flow * Experimental work - use typed wrapper classes for node results * Graph fixes to allow using_data example to run * Engine fixes following graph updates * Engine fixes following graph updates * Fix CI for the oldest supported version of PySpark, following a breaking change in PyPanDoc * Remove NodeResult wrapper classes * Engine updates * Rename DataSpec class * Update handling of section dependencies in graph builder * Move config quoting into config_parser module * Use YAML instead of JSON for example flow definition in the chaining exmaple * Run the chaining example in the example tests * Autowire flows as part of dev mode translation * Generate flow parameters in dev mode * Build flow fixes in dev_mode and graph_builder * Update model chaining example * Run flow work * Run flow work * Run flow work * Run flow work * Chaining example working in the runtime * Dependency graph updates * Fix Python 3.7 support in runtime engine type match check * Fix Python 3.7 support in runtime engine type match check * Make get_origin and get_args util functions in the runtime * Minor fixes in using_data example * Add E2E test for run flow * Rename RunModelOrFlow as base class for model and flow job logic * Working E2E RUN_FLOW job for the common case (minimal error handling) * Provide a structured interface class for NodeContext in the runtime functions module * Remove unneeded engine-level context class * Complete type checking for node results and lookups * Handle nodes with bundle results (type checks and logging still needed in NodeProcessor) * Set missing node types in exec.graph * Check node result types for bundles and other generic types * Update runtime node logging * Fix one todo in NodeLogger * Bump netty version for compliance checks * Move GCP SDK to major version 2 on latest stable * Set version of Netty dependencies in -lib-test * Compliance version bumps for protobuf and grpc * Compliance - force versions of Google HTTP client in GCP SDK * Compliance - false positive for gson * Put the CDDL exclusion back in the gradle file for the GCP config plugin
- Loading branch information
Martin Traverse
authored
May 25, 2022
1 parent
27bea0e
commit c4a4c8c
Showing
38 changed files
with
2,671 additions
and
1,261 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
job: | ||
runFlow: | ||
|
||
flow: ./chaining_flow.yaml | ||
|
||
parameters: | ||
param_1: 42 | ||
param_2: "2015-01-01" | ||
param_3: 1.5 | ||
|
||
inputs: | ||
customer_loans: "inputs/loan_final313_100.csv" | ||
currency_data: "inputs/currency_data_sample.csv" | ||
|
||
outputs: | ||
profit_by_region: "outputs/hello_pandas/profit_by_region.csv" | ||
|
||
models: | ||
model_1: model_1.FirstModel | ||
model_2: model_2.SecondModel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
nodes: | ||
|
||
customer_loans: | ||
nodeType: "INPUT_NODE" | ||
|
||
currency_data: | ||
nodeType: "INPUT_NODE" | ||
|
||
model_1: | ||
nodeType: "MODEL_NODE" | ||
modelStub: | ||
inputs: [customer_loans, currency_data] | ||
outputs: [preprocessed_data] | ||
|
||
model_2: | ||
nodeType: "MODEL_NODE" | ||
modelStub: | ||
inputs: [preprocessed_data] | ||
outputs: [profit_by_region] | ||
|
||
profit_by_region: | ||
nodeType: "OUTPUT_NODE" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Copyright 2022 Accenture Global Solutions Limited | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import datetime as dt | ||
import typing as tp | ||
|
||
import tracdap.rt.api as trac | ||
|
||
|
||
class FirstModel(trac.TracModel): | ||
|
||
def define_parameters(self) -> tp.Dict[str, trac.ModelParameter]: | ||
|
||
return trac.declare_parameters( | ||
trac.P("param_1", trac.INTEGER, "First parameter"), | ||
trac.P("param_2", trac.DATE, "Second parameter", default_value=dt.date(2001, 1, 1))) | ||
|
||
def define_inputs(self) -> tp.Dict[str, trac.ModelInputSchema]: | ||
|
||
customer_loans = trac.declare_input_table( | ||
trac.F("id", trac.BasicType.STRING, label="Customer account ID", business_key=True), | ||
trac.F("loan_amount", trac.BasicType.DECIMAL, label="Principal loan amount", format_code="CCY:EUR"), | ||
trac.F("total_pymnt", trac.BasicType.DECIMAL, label="Total amount repaid", format_code="CCY:EUR"), | ||
trac.F("region", trac.BasicType.STRING, label="Customer home region", categorical=True), | ||
trac.F("loan_condition_cat", trac.BasicType.INTEGER, label="Loan condition category", categorical=True)) | ||
|
||
currency_data = trac.declare_input_table( | ||
trac.F("ccy_code", trac.BasicType.STRING, label="Currency code", categorical=True), | ||
trac.F("spot_date", trac.BasicType.DATE, label="Spot date for FX rate"), | ||
trac.F("dollar_rate", trac.BasicType.DECIMAL, label="Dollar FX rate", format_code="CCY:USD")) | ||
|
||
return {"customer_loans": customer_loans, "currency_data": currency_data} | ||
|
||
def define_outputs(self) -> tp.Dict[str, trac.ModelOutputSchema]: | ||
|
||
preprocessed = trac.declare_output_table( | ||
trac.F("id", trac.BasicType.STRING, label="Customer account ID", business_key=True), | ||
trac.F("some_quantity_x", trac.BasicType.DECIMAL, label="Some quantity X", format_code="CCY:EUR")) | ||
|
||
return {"preprocessed_data": preprocessed} | ||
|
||
def run_model(self, ctx: trac.TracContext): | ||
|
||
loans = ctx.get_pandas_table("customer_loans") | ||
currencies = ctx.get_pandas_table("currency_data") | ||
|
||
loans["some_quantity_x"] = loans["loan_amount"] - loans["total_pymnt"] | ||
|
||
preproc = loans[["id", "some_quantity_x"]] | ||
|
||
ctx.put_pandas_table("preprocessed_data", preproc) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Copyright 2022 Accenture Global Solutions Limited | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import datetime as dt | ||
import decimal | ||
import typing as tp | ||
|
||
import pandas as pd | ||
|
||
import tracdap.rt.api as trac | ||
|
||
|
||
class SecondModel(trac.TracModel): | ||
|
||
def define_parameters(self) -> tp.Dict[str, trac.ModelParameter]: | ||
|
||
return trac.declare_parameters( | ||
trac.P("param_2", trac.DATE, "A data parameter", default_value=dt.date(2000, 1, 1)), | ||
trac.P("param_3", trac.FLOAT, "A float parameter")) | ||
|
||
def define_inputs(self) -> tp.Dict[str, trac.ModelInputSchema]: | ||
|
||
preprocessed = trac.declare_input_table( | ||
trac.F("id", trac.BasicType.STRING, label="Customer account ID", business_key=True), | ||
trac.F("some_quantity_x", trac.BasicType.DECIMAL, label="Some quantity X", format_code="CCY:EUR")) | ||
|
||
return {"preprocessed_data": preprocessed} | ||
|
||
def define_outputs(self) -> tp.Dict[str, trac.ModelOutputSchema]: | ||
|
||
profit_by_region = trac.declare_output_table( | ||
trac.F("region", trac.BasicType.STRING, label="Customer home region", categorical=True), | ||
trac.F("gross_profit", trac.BasicType.DECIMAL, label="Total gross profit", format_code="CCY:USD")) | ||
|
||
return {"profit_by_region": profit_by_region} | ||
|
||
def run_model(self, ctx: trac.TracContext): | ||
|
||
preproc = ctx.get_pandas_table("preprocessed_data") | ||
|
||
profit_by_region = pd.DataFrame(data={ | ||
"region": ["uk", "us"], | ||
"gross_profit": [decimal.Decimal(24000000), decimal.Decimal(13000000)]}) | ||
|
||
ctx.put_pandas_table("profit_by_region", profit_by_region) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
ccy_code,spot_date,dollar_rate | ||
EUR,2022-05-17,1.05 | ||
GBP,2022-05-17,1.25 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.