Skip to content

conclurer/kitt4sme

Repository files navigation

KITT4SME

KITT4SME Project

Jupyter Lab

Run

source local.env
jupyter lab --port=8888

Environments

  • .env is intended for the docker compose environment
  • local.env is intended for Jupyter Notebook and the terminal environment
  • kitt4sme_project/conclurer_ai_service/.env is intended for the AI service when used directly with Python

Conclurer Python

Manage Conclurer Python library:

pip install .
pip list | grep conclurer
pip install --upgrade .
pip uninstall pyconclurer

Persistence

Start the MongoDB and GUI:

docker compose -f config/compose/development/compose.yaml up -d

KITT4SME Platform

Start

Start the platform and the AI service.

docker compose -f compose.yaml -f config/compose/k4sme/compose.yaml build
docker compose -f compose.yaml -f config/compose/k4sme/compose.yaml up -d
docker compose -f compose.yaml -f config/compose/k4sme/compose.yaml ps
docker compose -f compose.yaml -f config/compose/k4sme/compose.yaml down

docker compose -f compose.yaml -f config/compose/k4sme/compose.yaml -f config/compose/k4sme/utils/compose.yaml up -d
docker compose -f compose.yaml -f config/compose/k4sme/compose.yaml -f config/compose/k4sme/utils/compose.yaml down

docker compose -f compose.yaml -f config/compose/k4sme/compose.yaml -f config/compose/k4sme/utils/compose.yaml -f config/compose/k4sme/development.yaml up -d

Initialize QuantumLeap subscription to the Orion Context Broker:

sh config/init/local/leap_subscription.sh

Usage

List of entities: http://127.0.0.1:1026/v2/entities

CrateDB UI: http://localhost:4200

Status of AI service: http://localhost:5000/api/v1/status

Notes

{"error":"BadRequest","description":"invalid attrsFormat, accepted values: legacy, normalized, keyValues, values"}

AI Service

  • Data Extraction
    • Requirement: Edelog instance and appropriate databases need to be accessible
    • Takes long and needs to push process updates to the client
      • Should use SSE
    • Represents an ongoing process that should be reflected in the status and executed only once at a time
    • Data should be reset in order to trigger the process again with empty database
  • Model Training
    • Requirement: training and validation data needs to be available
    • Training parameters must be chosen including features, training epochs, preprocessing and the size of the test data set
    • At first only one model is managed by the service
    • Like data extraction represents an ongoing process thus SSE endpoint and status updates
  • Prediction
    • Requirement: ai model must be ready to use
    • Prediction for a given component entity without error codes
    • The features selected for training must be present
    • Prediction result is also published as entity to the Orion broker
    • Predictions are calculated only once per object Id
  • Model Updating
    • Requirement: ai model must be ready to use
    • Update with a batch of component entities alongside error codes
    • The features selected for training must be present for each entity

API

Status

Retrieve the current status:

GET /api/v1/status

Response payload:

{
  "environment": {
    "KEY": "Value",
    "...": "..."
  },
  "data": {
    "isLoadingData": false,
    "isDeletingData": false,
    "available": {
      "plants": 0,
      "problem reports": 0,
      "materials": 0,
      "production orders": 0,
      "components": 0,
      "error codes": 0
    }
  },
  "model": {
    "isModelAvailable": true,
    "isTraining": false,
    "isUpdating": false,
    "parameters": {
      "features": [
        {
          "feature": "sensor_thickness",
          "dataMeasurementScale": "ratio"
        },
        {
          "feature": "rack_number",
          "dataMeasurementScale": "nominal"
        },
        {
          "feature": "environment_temperature",
          "dataMeasurementScale": "interval"
        }
      ]
    },
    "useRandomOverSampling": true,
    "testDataPercentage": 0.2,
    "trainingEpochs": 10,
    "updateEntityCount": 140
  }
}

Init the NGSI subscriptions to the configured Orion broker:

POST /api/v1/init/ngsi
200 OK

Response payload:

[
  {
    "label": "",
    "description": "",
    "status_code": 200
  }
]

Data Extraction

Request the data extraction:

PUT /api/v1/data/load
202 Accepted / 400 Bad Request / 409 Conflict

SSE /api/v1/data/load?update_rate=0.5

Request payload:

{
  "plants_db_type_id": "94a3c628-d913-4e07-a997-e799edc002e3",
  "error_codes_db_type_id": "5ca8f62e-6ea2-43e3-a514-380d142dbd70",
  "problem_reports_db_type_id": "d68dd67b-cb06-48e3-bee0-04cda381caa6",
  "materials_db_type_id": "2b749171-9900-4d3f-a9e9-db68673634fe",
  "production_orders_db_type_id": "88e2ac79-127e-47ad-83e6-bbdc07c3c7a4",
  "components_db_type_id": "12ff8025-a416-4faa-b26a-89a32e3146e2",
  "plant_number": "2300"
}

Response payload:

[
  {
    "dataTypeId": "94a3c628-d913-4e07-a997-e799edc002e3",
    "label": "plants",
    "count": 12,
    "inserted": 10,
    "total": 16,
    "time": 0.935278
  },
  {
    "dataTypeId": "12ff8025-a416-4faa-b26a-89a32e3146e2",
    "label": "components",
    "count": 50000,
    "inserted": 20000,
    "total": 100000,
    "time": 370.745241
  }
]

Reset the data:

DELETE /api/v1/data
202 Accepted / 409 Conflict

Response payload:

{
  "deleteCounts": [
    {
      "dataTypeId": "94a3c628-d913-4e07-a997-e799edc002e3",
      "label": "plants",
      "count": 16
    }
  ]
}

Model Training

Train the model using the currently available data:

PUT /api/v1/ai/model
202 Accepted / 400 Bad Request

SSE /api/v1/ai/model

Request payload:

{
  "predictionFeatures": [
    {
      "feature": "sensor_thickness",
      "dataMeasurementScale": "nominal|ordinal|interval|ratio"
    },
    {
      "feature": "rack_number",
      "dataMeasurementScale": "nominal|ordinal|interval|ratio"
    },
    {
      "feature": "environment_temperature",
      "dataMeasurementScale": "nominal|ordinal|interval|ratio"
    }
  ],
  "useRandomOverSampling": true,
  "testDataPercentage": 0.2,
  "trainingEpochs": 10
}

SSE Event types:

  • update: reports with json objects below
  • training_finished: indicates the training process is over

First parts of SSE response payload look like this:

{
  "...": "..."
}

Plus: Response payload for SSE Training:

{
  "binary": {
    "trainingLoss": 0.5,
    "trainingAccuracy": 0.9,
    "validationLoss": 0.6,
    "validationAccuracy": 0.8,
    "epoch": 9,
    "epochTime": 35.7,
    "totalTime": 331.9
  },
  "multiclass": {
    "trainingLoss": 0.5,
    "...": "..."
  },
  "multilabel": {
    "...": "..."
  }
}

For "training_finished":

{
  "success": true,
  "message": "..."
}

Delete the current model:

DELETE /api/v1/ai/model
200 OK / 404 Not Found

Prediction

Request a prediction:

POST /api/v1/ai/predictions
200 OK / 400 Bad Request / 404 Not Found

Request payload:

{
  "objectId": "9e9e44a2-2fde-445e-b14e-e7eaf0e58904",
  "features": {
    "oven_temperature": 23.5,
    "rack_number": "0123-1231",
    "humidity": 5.123
  }
}

Response payload:

{
  "objectId": "1637ae07-ab18-4577-9207-98c3f2cc5118",
  "binaryProbability": 0.4,
  "probabilities": {
    "C01": 0.1,
    "C11": 0.0067,
    "C141": 0.02
  },
  "probabilityDistribution": {
    "C01": 0.1,
    "C11": 0.0067,
    "C141": 0.02
  },
  "timestamp": "2023-09-06T22:00:00Z",
  "error_codes": {
    "C01": {
      "id": "x",
      "description": "text",
      "plant": {
        "id": "y",
        "dataTypeId": "x",
        "...": "..."
      }
    }
  }
}

Model Updating

Request a model update:

POST /api/v1/ai/samples
202 Accepted / 400 Bad Request / 404 Not Found

Request payload:

[
  {
    "objectId": "9e9e44a2-2fde-445e-b14e-e7eaf0e58904",
    "features": {
      "oven_temperature": 23.5,
      "rack_number": "0123-1231",
      "humidity": 5.123
    },
    "error_codes": ["C01", "C11"]
  },
  {
    "...": "..."
  }
]

Kubernetes Deployment

cd config/kubernetes
helm dependency update ./edelog-k4sme
helm install -f values.yaml edelog-k4sme ./edelog-k4sme
helm uninstall edelog-k4sme
helm list
helm get values edelog-k4sme
helm upgrade -f values.yaml edelog-k4sme ./edelog-k4sme
kubectl get pods -l app=edelog-k4sme-ai

Argo CD

Setup:

brew install argocd
kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
kubectl get all -n argocd
argocd admin initial-password -n argocd
argocd login edelog-cfm-k4sme-argocd.edel.cloud
# Use and change admin pw via UI or CLI
kubectl describe secret argocd-initial-admin-secret -n argocd
kubectl delete secret argocd-initial-admin-secret -n argocd

cd config/kubernetes
kubectl apply -f infrastructure/argocd-server-ingress.yaml
kubectl get ingress argocd-server-ingress -n argocd
kubectl describe secret argocd-server-tls -n argocd

Add private Git repo:

argocd repo add https://github.com/conclurer/kitt4sme.git --username <user> --password <password>

Deploy app without helm charts:

kubectl config set-context --current --namespace=argocd
argocd app create edelog-k4sme --repo https://github.com/conclurer/kitt4sme.git --path config/kubernetes/argocd --dest-server https://kubernetes.default.svc --dest-namespace default
argocd app get edelog-k4sme
argocd app sync edelog-k4sme
# after using argocd set back the context
kubectl config set-context --current --namespace=default

Dependencies

cd config/kubernetes

AI service:

helm install k4sme-ai-mongo oci://registry-1.docker.io/bitnamicharts/mongodb -f dependencies/ai-mongo-values.yaml
helm install k4sme-ai-redis oci://registry-1.docker.io/bitnamicharts/redis -f dependencies/ai-redis-values.yaml
  • MongoDB service: k4sme-ai-mongo-mongodb
  • Redis service: k4sme-ai-redis-headless

Mongo DB test:

mongosh --host 127.0.0.1 --authenticationDatabase admin -u user -p $MONGODB_ROOT_PASSWORD
mongosh mongodb://root:$MONGODB_ROOT_PASSWORD@localhost:27017/some_db --authenticationDatabase admin

Kitt4SME platform components:

helm repo add fiware https://fiware.github.io/helm-charts
helm install orion -f k4sme/orion-values.yaml fiware/orion
  • Orion Broker: orion:1026

References:

About

KITT4SME Project

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages