Testing with hypar run

When developing a function, it's useful to be able to make changes and visualize them immediately. The Hypar CLI provides a way to run your function locally and test it in the context of a workflow.
notion image
Return to your workflow, and remove your function from the workflow by clicking the "X."
notion image
Then go to the Hypar menu in the upper-right hand corner of the window, and select
Test a Local Function
notion image
Click the "Copy to clipboard" button under the command:
Then return to your terminal, ensure you're in your project directory ("StarterFunction") and paste the copied command, which should look like this:
hypar run --workflow-id=6bcece6c-2fa5-4a4d-a5c7-43732bff053b
Wait until you see this message:
Workflow update subscription acknowledgement received with id 518f1c6f-1b07-40e9-8461-fbc8fdbe3c06. Waiting for workspace updates...
notion image
And then return to the workflow and click the "Ready" button.
Now, when you edit the inputs of the function, they're passed to your locally-running function, instead of being executed on the cloud.

hypar run

The hypar run command we pasted earlier stays running continuously until we exit. While it's running, it serves the local function, and also monitors your code for changes. If you make changes to hypar.json or to your C# code, it will rebuild the function and re-execute dynamically. This makes it easy to write code, quickly try things out, and visualize how they will function on Hypar.
Let's make some changes to our code, with hypar run still running. We'll insert a void running through our mass. For this we'll need to create a smaller rectangle inside our first one, and create a profile from those two rectangles. First, we'll make the second rectangle:
var innerRectangle = Polygon.Rectangle(input.Width * 0.5, input.Length * 0.5);
And then a Profile from the two rectangles:
var profile = new Profile(rectangle, innerRectangle);
And then edit the line where we make the Mass to use our new profile:
var mass = new Mass(profile, input.Height, material);
The updated execute method should look like this:
public static StarterFunctionOutputs Execute(Dictionary<string, Model> inputModels, StarterFunctionInputs input) { // create an output object var output = new StarterFunctionOutputs(input.Width * input.Length * input.Height, input.Width * input.Length); // create a rectangle var rectangle = Polygon.Rectangle(input.Width, input.Length); // create an inner void rectangle var innerRectangle = Polygon.Rectangle(input.Width * 0.5, input.Length * 0.5); // create a profile from the two rectangles var profile = new Profile(rectangle, innerRectangle); // create a new material var material = new Material("Box Color", input.MassColor); // create a mass from the rectangle var mass = new Mass(profile, input.Height, material); // add the mass to the output model output.Model.AddElement(mass); return output; }
As soon as you save your code, you should see the function results update in your workflow:
notion image
When you're happy with your local changes, hit ctrl+C in the terminal to stop hypar run.
Finally, publish your updated function with hypar publish. The next time you use it in a workflow, it will reflect the changes you made. Anyone you've shared your function with will also have access to the latest and greatest version you just published.
This diagram summarizes the steps we've taken to edit and test our function with live preview:
notion image