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

Improve documentation of IncludeWorkflows #40

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
41 changes: 41 additions & 0 deletions .bonsai/Setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#! /bin/bash

SETUP_SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)"

DEFAULT_VERSION="latest"
VERSION="$DEFAULT_VERSION"

while [[ "$#" -gt 0 ]]; do
case $1 in
--version) VERSION="$2"; shift ;;
*) echo "Unknown parameter passed: $1"; exit 1 ;;
esac
shift
done

echo "Setting up Bonsai v=$VERSION environment..."

if [ ! -f "$SETUP_SCRIPT_DIR/Bonsai.exe" ]; then
CONFIG="$SETUP_SCRIPT_DIR/Bonsai.config"
if [ -f "$CONFIG" ]; then
DETECTED=$(xmllint --xpath '//PackageConfiguration/Packages/Package[@id="Bonsai"]/@version' "$CONFIG" | sed -e 's/^[^"]*"//' -e 's/"$//')
echo "Version detected v=$DETECTED."
RELEASE="https://github.com/bonsai-rx/bonsai/releases/download/$DETECTED/Bonsai.zip"
else
if [ $VERSION = "latest" ]; then
RELEASE="https://github.com/bonsai-rx/bonsai/releases/latest/download/Bonsai.zip"
else
RELEASE="https://github.com/bonsai-rx/bonsai/releases/download/$VERSION/Bonsai.zip"
fi
fi
echo "Download URL: $RELEASE"
wget $RELEASE -O "$SETUP_SCRIPT_DIR/temp.zip"
mv -f "$SETUP_SCRIPT_DIR/NuGet.config" "$SETUP_SCRIPT_DIR/temp.config"
unzip -d "$SETUP_SCRIPT_DIR" -o "$SETUP_SCRIPT_DIR/temp.zip"
mv -f "$SETUP_SCRIPT_DIR/temp.config" "$SETUP_SCRIPT_DIR/NuGet.config"
rm -rf "$SETUP_SCRIPT_DIR/temp.zip"
rm -rf "$SETUP_SCRIPT_DIR/Bonsai32.exe"
fi

source "$SETUP_SCRIPT_DIR/activate"
source "$SETUP_SCRIPT_DIR/run" --no-editor
15 changes: 15 additions & 0 deletions .bonsai/activate
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
# activate.sh
if [[ -v BONSAI_EXE_PATH ]]; then
echo "Error! Cannot have multiple bonsai environments activated at the same time. Please deactivate the current environment before activating the new one."
return
fi
BONSAI_ENV_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)"
export BONSAI_ENV_DIR
export BONSAI_EXE_PATH="$BONSAI_ENV_DIR/Bonsai.exe"
export ORIGINAL_PS1="$PS1"
export PS1="($(basename "$BONSAI_ENV_DIR")) $PS1"
alias bonsai='source "$BONSAI_ENV_DIR"/run'
alias bonsai-clean='GTK_DATA_PREFIX= source "$BONSAI_ENV_DIR"/run'
alias deactivate='source "$BONSAI_ENV_DIR"/deactivate'
echo "Activated bonsai environment in $BONSAI_ENV_DIR"
8 changes: 8 additions & 0 deletions .bonsai/deactivate
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
unset BONSAI_EXE_PATH
export PS1="$ORIGINAL_PS1"
unset ORIGINAL_PS1
unalias bonsai
unalias bonsai-clean
unalias deactivate
echo "Deactivated bonsai environment."
58 changes: 58 additions & 0 deletions .bonsai/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/bash
# run.sh

SETUP_SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)"
CONFIG="$SETUP_SCRIPT_DIR/Bonsai.config"

cleanup() {
update_paths_to_windows
}

update_paths_to_linux() {
ASSEMBLYLOCATIONS=$(xmllint --xpath '//PackageConfiguration/AssemblyLocations/AssemblyLocation/@location' "$CONFIG" | sed -e 's/^[^"]*"//' -e 's/"$//')
for ASSEMBLYLOCATION in $ASSEMBLYLOCATIONS; do
NEWASSEMBLYLOCATION="${ASSEMBLYLOCATION//\\/\/}"
xmlstarlet edit --inplace --update "/PackageConfiguration/AssemblyLocations/AssemblyLocation[@location='$ASSEMBLYLOCATION']/@location" --value "$NEWASSEMBLYLOCATION" "$CONFIG"
done

LIBRARYFOLDERS=$(xmllint --xpath '//PackageConfiguration/LibraryFolders/LibraryFolder/@path' "$CONFIG" | sed -e 's/^[^"]*"//' -e 's/"$//')
for LIBRARYFOLDER in $LIBRARYFOLDERS; do
NEWLIBRARYFOLDER="${LIBRARYFOLDER//\\/\/}"
xmlstarlet edit --inplace --update "//PackageConfiguration/LibraryFolders/LibraryFolder[@path='$LIBRARYFOLDER']/@path" --value "$NEWLIBRARYFOLDER" "$CONFIG"
done
}

update_paths_to_windows() {
ASSEMBLYLOCATIONS=$(xmllint --xpath '//PackageConfiguration/AssemblyLocations/AssemblyLocation/@location' "$CONFIG" | sed -e 's/^[^"]*"//' -e 's/"$//')
for ASSEMBLYLOCATION in $ASSEMBLYLOCATIONS; do
NEWASSEMBLYLOCATION="${ASSEMBLYLOCATION//\//\\}"
xmlstarlet edit --inplace --update "/PackageConfiguration/AssemblyLocations/AssemblyLocation[@location='$ASSEMBLYLOCATION']/@location" --value "$NEWASSEMBLYLOCATION" "$CONFIG"
done

LIBRARYFOLDERS=$(xmllint --xpath '//PackageConfiguration/LibraryFolders/LibraryFolder/@path' "$CONFIG" | sed -e 's/^[^"]*"//' -e 's/"$//')
for LIBRARYFOLDER in $LIBRARYFOLDERS; do
NEWLIBRARYFOLDER="${LIBRARYFOLDER//\//\\}"
xmlstarlet edit --inplace --update "//PackageConfiguration/LibraryFolders/LibraryFolder[@path='$LIBRARYFOLDER']/@path" --value "$NEWLIBRARYFOLDER" "$CONFIG"
done
}

if [[ -v BONSAI_EXE_PATH ]]; then
if [ ! -f "$BONSAI_EXE_PATH" ]; then
bash "$BONSAI_ENV_DIR"/Setup.sh
bash "$BONSAI_ENV_DIR"/run "$@"
else
BONSAI_VERSION=$(xmllint --xpath "//PackageConfiguration/Packages/Package[@id='Bonsai']/@version" "$CONFIG" | sed -e 's/^[^"]*"//' -e 's/"$//')
if [[ -z ${BONSAI_VERSION+x} ]] && [ "$BONSAI_VERSION" \< "2.8.4" ]; then
echo "Updating paths to Linux format..."
trap cleanup EXIT INT TERM
update_paths_to_linux
mono "$BONSAI_EXE_PATH" "$@"
cleanup
else
mono "$BONSAI_EXE_PATH" "$@"
fi
fi
else
echo "BONSAI_EXE_PATH is not set. Please set the path to the Bonsai executable."
return
fi
3 changes: 2 additions & 1 deletion src/Bonsai.ML.HiddenMarkovModels/CheckFitFinished.bonsai
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
xmlns:p1="clr-namespace:Bonsai.ML;assembly=Bonsai.ML"
xmlns:scr="clr-namespace:Bonsai.Scripting.Expressions;assembly=Bonsai.Scripting.Expressions"
xmlns="https://bonsai-rx.org/2018/workflow">
<Description>Periodically evaluates the `get_fit_finished` function of the HMM. Returns whether the `fit_finished` attribute is true. This should only be used after the `RunFitAsync` function has already been started.</Description>
<Workflow>
<Nodes>
<Expression xsi:type="WorkflowInput">
<Name>Source1</Name>
</Expression>
<Expression xsi:type="ExternalizedMapping">
<Property Name="Name" DisplayName="Name" Category="ModelReference" />
<Property Name="Name" DisplayName="Name" Description="The name of the Python variable referencing the model object." Category="ModelReference" />
<Property Name="TimerFrequency" DisplayName="TimerFrequency" Description="The frequency with which to check if the asynchronous fit loop is complete." Category="Polling" />
</Expression>
<Expression xsi:type="rx:SelectMany">
Expand Down
13 changes: 7 additions & 6 deletions src/Bonsai.ML.HiddenMarkovModels/CreateHMM.bonsai
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
xmlns:p2="clr-namespace:Bonsai.ML.HiddenMarkovModels;assembly=Bonsai.ML.HiddenMarkovModels"
xmlns:py="clr-namespace:Bonsai.Scripting.Python;assembly=Bonsai.Scripting.Python"
xmlns="https://bonsai-rx.org/2018/workflow">
<Description>Creates a new HMM Python object inside of the HMM module and assigns it to a named Python variable.</Description>
<Workflow>
<Nodes>
<Expression xsi:type="ExternalizedMapping">
<Property Name="Name" Category="ModelReference" />
<Property Name="Name" DisplayName="Name" Description="The name of the Python variable referencing the model object." Category="ModelReference" />
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="p1:CreateModelReference">
Expand All @@ -26,11 +27,11 @@
<Name>Source1</Name>
</Expression>
<Expression xsi:type="ExternalizedMapping">
<Property Name="NumStates" />
<Property Name="Dimensions" />
<Property Name="ObservationsModelType" />
<Property Name="StateParameters" />
<Property Name="TransitionsModelType" />
<Property Name="NumStates" Description="The number of discrete latent states in the HMM." />
<Property Name="Dimensions" Description="The dimensionality of the observations going into the HMM." />
<Property Name="ObservationModelType" Description="The type of distribution that the HMM will use to model the emission of data observations." />
<Property Name="StateParameters" Description="The optional state parameters of the HMM. If an observation model or transition model is defined within the state parameters, these will override the values set in the observation model type and transition model type properties, respectively." />
<Property Name="TransitionModelType" Description="The type of model that the HMM will use to calculate the probabilities of transitioning between states."/>
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="p2:ModelParameters">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
xmlns:rx="clr-namespace:Bonsai.Reactive;assembly=Bonsai.Core"
xmlns:p2="clr-namespace:Bonsai.ML.HiddenMarkovModels.Observations;assembly=Bonsai.ML.HiddenMarkovModels"
xmlns="https://bonsai-rx.org/2018/workflow">
<Description>Computes the statistics of the Gaussian observations in the HMM. Only works for models with Gaussian observations.</Description>
<Workflow>
<Nodes>
<Expression xsi:type="WorkflowInput">
Expand All @@ -16,7 +17,7 @@
<Combinator xsi:type="py:ObserveOnGIL" />
</Expression>
<Expression xsi:type="ExternalizedMapping">
<Property Name="Name" />
<Property Name="Name" DisplayName="Name" Description="The name of the Python variable referencing the model object." Category="ModelReference" />
</Expression>
<Expression xsi:type="SubscribeSubject" TypeArguments="p1:ModelReference">
<Name>hmm</Name>
Expand Down
3 changes: 2 additions & 1 deletion src/Bonsai.ML.HiddenMarkovModels/InferState.bonsai
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
xmlns:rx="clr-namespace:Bonsai.Reactive;assembly=Bonsai.Core"
xmlns:p2="clr-namespace:Bonsai.ML.HiddenMarkovModels;assembly=Bonsai.ML.HiddenMarkovModels"
xmlns="https://bonsai-rx.org/2018/workflow">
<Description>Infers the state of the HMM given the observations.</Description>
<Workflow>
<Nodes>
<Expression xsi:type="WorkflowInput">
Expand All @@ -15,7 +16,7 @@
<Combinator xsi:type="py:ObserveOnGIL" />
</Expression>
<Expression xsi:type="ExternalizedMapping">
<Property Name="Name" />
<Property Name="Name" DisplayName="Name" Description="The name of the Python variable referencing the model object." Category="ModelReference" />
</Expression>
<Expression xsi:type="SubscribeSubject" TypeArguments="p1:ModelReference">
<Name>hmm</Name>
Expand Down
1 change: 1 addition & 0 deletions src/Bonsai.ML.HiddenMarkovModels/LoadHMMModule.bonsai
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
xmlns:rx="clr-namespace:Bonsai.Reactive;assembly=Bonsai.Core"
xmlns:py="clr-namespace:Bonsai.Scripting.Python;assembly=Bonsai.Scripting.Python"
xmlns="https://bonsai-rx.org/2018/workflow">
<Description>Loads the HMM module into the workflow.</Description>
<Workflow>
<Nodes>
<Expression xsi:type="WorkflowInput">
Expand Down
8 changes: 4 additions & 4 deletions src/Bonsai.ML.HiddenMarkovModels/ModelParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public class ModelParameters : PythonStringBuilder
private StateParameters stateParameters = null;

/// <summary>
/// The number of states of the HMM model.
/// The number of discrete latent states in the HMM model.
/// </summary>
[Description("The number of discrete latent states of the HMM model")]
[Description("The number of discrete latent states in the HMM.")]
[Category("ModelSpecification")]
public int NumStates
{
Expand All @@ -44,9 +44,9 @@ public int NumStates
}

/// <summary>
/// The dimensionality of the observations into the HMM model.
/// The dimensionality of the observations going into the HMM.
/// </summary>
[Description("The dimensionality of the observations into the HMM model")]
[Description("The dimensionality of the observations going into the HMM.")]
[Category("ModelSpecification")]
public int Dimensions
{
Expand Down
15 changes: 8 additions & 7 deletions src/Bonsai.ML.HiddenMarkovModels/RunFitAsync.bonsai
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
xmlns:p1="clr-namespace:Bonsai.ML;assembly=Bonsai.ML"
xmlns:scr="clr-namespace:Bonsai.Scripting.Expressions;assembly=Bonsai.Scripting.Expressions"
xmlns="https://bonsai-rx.org/2018/workflow">
<Description>Runs the asynchronous fit loop of the HMM.</Description>
<Workflow>
<Nodes>
<Expression xsi:type="WorkflowInput">
<Name>Source1</Name>
</Expression>
<Expression xsi:type="ExternalizedMapping">
<Property Name="Value" DisplayName="BatchSize" Category="TrainingData" />
<Property Name="Value" DisplayName="BatchSize" Description="The size of the batch used for fitting the model." Category="TrainingData" />
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="IntProperty">
Expand Down Expand Up @@ -47,7 +48,7 @@
<Combinator xsi:type="py:ObserveOnGIL" />
</Expression>
<Expression xsi:type="ExternalizedMapping">
<Property Name="Name" />
<Property Name="Name" DisplayName="Name" Description="The name of the Python variable referencing the model object." Category="ModelReference" />
</Expression>
<Expression xsi:type="SubscribeSubject" TypeArguments="p1:ModelReference">
<Name>hmm</Name>
Expand All @@ -64,39 +65,39 @@
</Combinator>
</Expression>
<Expression xsi:type="ExternalizedMapping">
<Property Name="Value" DisplayName="NumIterations" Category="Hyperparameters" />
<Property Name="Value" DisplayName="NumIterations" Description="The number of iterations used for fitting the model to a single batch of data." Category="Hyperparameters" />
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="IntProperty">
<Value>50</Value>
</Combinator>
</Expression>
<Expression xsi:type="ExternalizedMapping">
<Property Name="Value" DisplayName="FlushDataBetweenBatches" Category="TrainingData" />
<Property Name="Value" DisplayName="FlushDataBetweenBatches" Description="Determines whether to append new batches of data to the existing batch or whether to flush the previous batch and fit only on the new batch." Category="TrainingData" />
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="BooleanProperty">
<Value>false</Value>
</Combinator>
</Expression>
<Expression xsi:type="ExternalizedMapping">
<Property Name="Value" DisplayName="InitialStateDistribution" Category="ParametersToFit" />
<Property Name="Value" DisplayName="InitialStateDistribution" Description="Determines whether or not the model will fit the initial state distribution." Category="ParametersToFit" />
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="BooleanProperty">
<Value>true</Value>
</Combinator>
</Expression>
<Expression xsi:type="ExternalizedMapping">
<Property Name="Value" DisplayName="TransitionParams" Category="ParametersToFit" />
<Property Name="Value" DisplayName="TransitionParams" Description="Determines whether or not the model will fit the state transition parameters." Category="ParametersToFit" />
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="BooleanProperty">
<Value>true</Value>
</Combinator>
</Expression>
<Expression xsi:type="ExternalizedMapping">
<Property Name="Value" DisplayName="ObservationParams" Category="ParametersToFit" />
<Property Name="Value" DisplayName="ObservationParams" Description="Determines whether or not the model will fit the observation model parameters." Category="ParametersToFit" />
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="BooleanProperty">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
xmlns:p2="clr-namespace:Bonsai.ML.LinearDynamicalSystems.Kinematics;assembly=Bonsai.ML.LinearDynamicalSystems"
xmlns:py="clr-namespace:Bonsai.Scripting.Python;assembly=Bonsai.Scripting.Python"
xmlns="https://bonsai-rx.org/2018/workflow">
<Description>Creates a Kalman filter model for kinematics estimation based on the discrete Weiner process acceleration model.</Description>
<Workflow>
<Nodes>
<Expression xsi:type="ExternalizedMapping">
<Property Name="Name" Category="ModelReference" />
<Property Name="Name" DisplayName="Name" Description="The name of the Python variable referencing the model object." Category="ModelReference" />
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="p1:CreateModelReference" />
Expand All @@ -24,17 +25,17 @@
<Name>Source1</Name>
</Expression>
<Expression xsi:type="ExternalizedMapping">
<Property Name="Fps" Category="ModelParams" />
<Property Name="Pos_x0" Category="ModelParams" />
<Property Name="Pos_y0" Category="ModelParams" />
<Property Name="Vel_x0" Category="ModelParams" />
<Property Name="Vel_y0" Category="ModelParams" />
<Property Name="Acc_x0" Category="ModelParams" />
<Property Name="Acc_y0" Category="ModelParams" />
<Property Name="Sigma_a" Category="ModelParams" />
<Property Name="Sigma_x" Category="ModelParams" />
<Property Name="Sigma_y" Category="ModelParams" />
<Property Name="Sqrt_diag_V0_value" Category="ModelParams" />
<Property Name="Fps" Description="The frames per second of the observations." Category="ModelParams" />
<Property Name="Pos_x0" Description="The initial x position." Category="ModelParams" />
<Property Name="Pos_y0" Description="The initial y position." Category="ModelParams" />
<Property Name="Vel_x0" Description="The initial x velocity." Category="ModelParams" />
<Property Name="Vel_y0" Description="The initial y velocity." Category="ModelParams" />
<Property Name="Acc_x0" Description="The initial x acceleration." Category="ModelParams" />
<Property Name="Acc_y0" Description="The initial y acceleration." Category="ModelParams" />
<Property Name="Sigma_a" Description="A scalar value representing the measurement noise." Category="ModelParams" />
<Property Name="Sigma_x" Description="A scalar value representing the prediction noise along the x axis." Category="ModelParams" />
<Property Name="Sigma_y" Description="A scalar value representing the prediction noise along the y axis." Category="ModelParams" />
<Property Name="Sqrt_diag_V0_value" Description="The initial value of the diagonal of the state covariance matrix." Category="ModelParams" />
Comment on lines +28 to +38
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general in Bonsai / C# we would use Pascal casing rather than snake case, but no need to change anything now, this is just a general comment for us to think about regarding casing of properties coming from Python.

</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="p2:KFModelParameters">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p1="clr-namespace:Bonsai.ML.LinearDynamicalSystems.Kinematics;assembly=Bonsai.ML.LinearDynamicalSystems"
xmlns="https://bonsai-rx.org/2018/workflow">
<Description>Creates a 2 dimensional object with the properties X and Y from the input.</Description>
<Workflow>
<Nodes>
<Expression xsi:type="WorkflowInput">
Expand Down
Loading