Working With the Task Distributional Output
Sampling from distributions
Samples from uncertainty-tracking (UT) C0 or C0 Pro core runs
The Signaloid Cloud Compute Engine API provides the /samples
endpoint which expects as input a distribution encoded in the form of an
Uncertainty Hexadecimal (“Ux”) string and returns random samples from this input distribution.
This guide describes how you can get the Ux string values from the output
(either stdout
or stderr
) of uncertainty-tracking (UT) tasks. The /samples
endpoint also accepts the query parameter count
to instruct it
how many samples to generate.
The code snippet below shows how to generate 10 samples from the distribution of the variable sigmaCMpa
as calculated either using a source
code task or a repository task.
- TypeScript
- cURL
// Helper function for fetching variable samples
async function extractUxStringValues(taskOutput: string) {
const regex = /([-+]?(?:\d+\.\d*|\.\d+)(?:[eE][-+]?\d+)?)(Ux[0-9a-fA-F]{40,})/g;
return [...taskOutput.matchAll(regex)].map((m) => ({ value: m[1], uxString: m[2] }));
}
async function getSamplesFromUxString(uxString: string) {
try {
// get task data from API
const sampleRequestResponse = await signaloidClient.get(`/samples`, {
params: { count: 10 },
data: {
UxValue: uxString
}
});
if (sampleRequestResponse.data) {
console.log(`Samples from the variable "sigmaCMpa" (Alloy strength): `, sampleRequestResponse.data);
}
} catch (error) {
console.log("Error:", error);
}
}
async function parseOutputAndGetSamplesFromUxString() {
if (taskStdout) {
const uxStringsExtracted = await extractUxStringValues(taskStdout);
const uxString = uxStringsExtracted[uxStringsExtracted.length - 1].uxString;
if (uxString) {
console.log(`Generating samples from the distribution of the variable "sigmaCMpa" (Alloy strength) with uxString: ${uxString}`);
await getSamplesFromUxString(uxString);
}
} else {
// wait for the outputs to be available
setTimeout(async () => {
// Note: this function should ideally be called inside `getTaskOutputs` after setting `taskStdout`.
await parseOutputAndGetSamplesFromUxString();
}, 1000);
}
}
await parseOutputAndGetSamplesFromUxString();
UxString="Ux0400000000000010004086182D94915B0500000040405417BDA0AC9B250188F2CF171EF8E0405B6757D802080F01AA44F4C3CE568040605E6EDBDD0AA702040E39582CDA604062549EC48E6D54020049C5A87763C040640CD2FABF29F1022269E95ECAD3204065A2D65BCAA361022F84B7CF914A00406727AAD835034E022C821EA01770804068ABA18A9EE5DC0233ECFFBF89D480406A1A71BCBA96AA021309E840103300406B7F731CA16D9D023008CD59709980406CEA500FE458BE0216D7D76EA0CD60406E4625AE7BBFB2020894010FDC81C0406FAE24D94A8ED3022E84F454DD4DC0407091C94C35C8CD021F4E4D67909B6040714ADA1EC604E7020934E1AD5155C04072073BE9D7C24002380BAD55143FA04072C877D44122360219C4964B2DEDC040738B6D24BC0CB3023624DCF65BCEE0407468DAE5A46FD102348E828B9D4040407539A19D9F821B022AA3BD78F283204076167CFC01CEE8021EAFD30F8D4F804076FEEB22272855022FD02B048E12004077F8D99DA024F4021FBFEDEFCF39E0407911F818FF1163024B9A05B43447E0407A44B81557DD0B020AC5B8BAED2980407B8E07EC978C0101FD737CB6050FB0407D0E31FBF77D3601C9D92AB5DDC9C0407EE3846D4850FB01B43118EE7BDFA040807F8E3216120901A47793B2ACECE04081B8804AECCFDC01C654E526CDF2404082F417B2B6626101E413F66F2E0BE040840D1DBA88D35701CEBE2AB6CD70C0408523C73B05C890021438342616F4C04086298D67225EC6020013D66E8E76C040871E9A2AA378710230A511292A23804087F9B09002581701D759C8D68904604088C7B205CAB0AB021E0FB3C15CA2804089965E2291CDE7021DA9F67BE6FF20408A698B9837CD60024A1C4F46724F80408B36CFF7F80044020D42C0D2B48740408BF982A4EA135402177F700F0C7260408CB56FF95BF061020DC70452029680408D7F1051A80FE2024B9180F3388240408E4C026194A08602254479374CCCE0408F11E4C8CC147E0233CFEF28534EA0408FE9FE2B2171910259E3427835FB0040905B657856A26A01FFD69C48900AE04090C529DBCEB142023ECCA96C147E40409131C144D49BCE01F9712FECEDF4E040919F70F107944E022F3F8EEA118040409217F42CBAA75902099DCD5C4478804092925B872D66D202148613EE120C60409321859F3242A901CDABBE98092FD04093B3D8892B772B01C170077C3F2280409447C6AFCE86FE01B05B17344BD5E04094E93148DE8CB301DE50DA37D36D0040959763034D4D0E01C5164F700D8CA040965B0C13AC387B01FD2C401BCDB7E04097247B8B31A85E01A2730BD05949004097FDF4B706DFC001E33E60D12A90D04098F3FDDF43582D01BA699075EEE5D0409A0E41FFBE591C01CABF57DA2AF080409B90AD8877191901BC28A982C0B7C0409E41771B832D090117EFFC3F286460"
# Get samples from an output distribution of an uncertainty-tracking (UT) core task
samples=$(curl -s --request GET --location 'https://api.signaloid.io/samples?count=10' \
--header "Authorization: $signaloidAPIKey" \
--header "Content-Type: application/json" \
--data '{"UxValue":"'"$UxString"'"}')
echo $samples
The response from this endpoint will have the following shape:
{
"Samples": [
1479.8029446132969, 266.390706351501, 858.8775223090213, 546.4088466714376, 645.0190538880073,
321.2449635555817, 701.89858850263, 675.9114708254975, 663.4408244950512, 1538.206118918603
],
"Count": 10
}
Please refer to the sample generation endpoint API reference for more details.
Samples from C0 or C0 Pro Reference core runs
For downloading the samples generated during the execution of applications on Reference cores, the Signaloid Cloud Compute Engine API provides the /tasks/{TaskID}/values/{ValueID}/samples
endpoint.
The endpoint URL contains the task ID (TaskID
) and value ID (ValueID
) of the expression that was traced.
This guide describes how you can get the ValueID
from the output
(either stdout
or stderr
) of a Reference core task. The endpoint also accepts the query parameter count
to instruct it how many samples to download.
The endpoint returns up to 10,000
samples. To allow you to download more than 10,000
samples, if they exist, the endpoint also returns a ContinuationToken
that you can add as the query parameter continuationToken
to download a subsequent batch of samples.
The code snippet below shows how to generate 10 samples from the distribution of the variable sigmaCMpa
as calculated either using a source
code or a repository Reference core task. The task of the examples was executed on the default C0-Reference core which results in 32 samples.
The code asks for a first batch of ten samples and then using the ContinuationToken
it asks for a second batch of 10 samples.
- TypeScript
- cURL
// Helper function for fetching variable samples
async function extractValueIDTags(taskOutput: string) {
const regex = /([-+]?(?:\d+\.\d*|\.\d+)(?:[eE][-+]?\d+)?)<ValueID>(.*?)<\/ValueID>/g;
return [...taskOutput.matchAll(regex)].map((m) => ({ value: m[1], valueID: m[2] }));
}
async function getSamplesFromVariable(taskID: string, valueID: string) {
try {
// get task data from API
const sampleRequestResponse = await signaloidClient.get(`/tasks/${taskID}/values/${valueID}/samples`, {
params: { count: 10 },
});
if (sampleRequestResponse.data) {
console.log(`Samples from the variable "sigmaCMpa" (Alloy strength): `, sampleRequestResponse.data);
}
} catch (error) {
console.log("Error :>> ", error); // [TODO]: handle errors
}
}
async function parseOutputAndGetSamples() {
if (taskStdout) {
const values = await extractValueIDTags(taskStdout);
const sigmaCMpa_valueID = values[values.length - 1].valueID;
if (sigmaCMpa_valueID) {
console.log(
`Generating samples from the distribution of the variable "sigmaCMpa" (Alloy strength) with valueID: ${sigmaCMpa_valueID}`
);
await getSamplesFromVariable(taskID, sigmaCMpa_valueID);
}
} else {
// wait for the outputs to be available
setTimeout(async () => {
// Note: this function should ideally be called inside `getTaskOutputs` after setting `taskStdout`.
await parseOutputAndGetSamples();
}, 1000);
}
}
await parseOutputAndGetSamples();
# Get samples from an output distribution of a reference core task
samplesEndpointReturn=$(curl -s --request GET --location 'https://api.signaloid.io/tasks/'$TaskID'/values/'$ValueID'/samples?count=10' \
--header "Authorization: $signaloidAPIKey" \
--header "Content-Type: application/json")
samplesBatchA=$(echo $samplesEndpointReturn | jq -r '.Samples')
samplesContinuationToken=$(echo $samplesEndpointReturn | jq -r '.ContinuationToken')
echo $samplesBatchA
# Get samples from an output distribution of a reference core task
samplesEndpointReturn=$(curl -s --request GET --location 'https://api.signaloid.io/tasks/'$TaskID'/values/'$ValueID'/samples?count=10&continuationToken='$samplesContinuationToken \
--header "Authorization: $signaloidAPIKey" \
--header "Content-Type: application/json")
samplesBatchB=$(echo $samplesEndpointReturn | jq -r '.Samples')
echo $samplesBatchB
The response from this endpoint will have the following shape:
{
"Samples": [
446.8395834203027, 563.2602152805459, 447.5357763646873, 1254.257413026913, 713.1036552505653,
851.148622921381, 1102.751946844017, 818.0114347199466, 766.5801430096062, 551.714077743751
],
"Count": 10,
"ContinuationToken": "eyJ2ZXJzaW9uIjogMCwgImxhc3RfYnl0ZV9yZWFkIjogMTEwNCwgInRvdGFsX3NhbXBsZXMiOiAzMn0="
}
Please refer to the sample generation endpoint API reference for more details.
Plotting distributions
Distributional plots from uncertainty-tracking (UT) C0 or C0 Pro core runs
The Signaloid Cloud Compute Engine API provides the /plot
which takes as input (payload
) a distribution encoded in the form of an
Uncertainty Hexadecimal (“Ux”) string and generates a plot of the probability density function of its input distribution.
This guide describes how you get the Ux string values from the output
(either stdout
or stderr
) of uncertainty-tracking (UT) tasks. The following code snippets show how to generate a plot of the distributional value of sigmaCMpa
using the Signaloid API.
- TypeScript
- cURL
const plotRequestResponse = await signaloidClient.post(`/plot`, { payload: uxString });
# Plot an output distribution of an uncertainty-tracking (UT) core task
plot=$(curl -s --request POST --location 'https://api.signaloid.io/plot' \
--header "Authorization: $signaloidAPIKey" \
--header "Content-Type: application/json" \
--data '{"payload":"'"$UxString"'"}')
# Get presigned URL of the plot
plotURL=$(echo $plot | jq -r '.presignedURL')
# Download the plot
curl -s "$plotURL" > distribution-plot-of-sigmaCMpa.png
The plot response will have the following shape:
{
"plotID": "879bcae6-d6d9-4e2f-9550-43fb84615d30", // ID of the plot
"presignedURL": "https://.... " // presigned URL to download the plot
}
The presignedURL
field of the response object will contain a presigned URL to an image of the plot. You can use this URL to download the plot and display it in your application.
sigmaCMpa
of an uncertainty-tracking UT core task.Distributional plots from Reference C0 or C0 Pro core runs
The Signaloid Cloud Compute Engine API provides the /tasks/{TaskID}/values/{ValueID}/plot
endpoint that generates a plot of the probability density function of your variables and returns a URL to it.
The endpoint for Reference core runs expects the task ID and value ID as path parameters taskID
and valueID
, respectively.
The following code snippets show how to generate a plot of the distributional value of sigmaCMpa
using the Signaloid API.
- TypeScript
- cURL
const plotRequestResponse = await signaloidClient.post(`/tasks/${taskID}/values/${valueID}/plot`);
# Plot an output distribution of a reference core task
plot=$(curl -s --request POST --location "https://api.signaloid.io/tasks/$TaskID/values/$ValueID/plot" \
--header "Authorization: $signaloidAPIKey" \
--header "Content-Type: application/json")
echo $plot
# Get presigned URL of the plot
plotURL=$(echo $plot | jq -r '.presignedURL')
# Download the plot
curl -s "$plotURL" > reference-distribution-plot-of-sigmaCMpa.png
The plot response will have the following shape:
{
"plotID": "879bcae6-d6d9-4e2f-9550-43fb84615d30", // ID of the plot
"presignedURL": "https://.... " // presigned URL to download the plot
}
The presignedURL
field of the response object will contain a presigned URL to an image of the plot. You can use this URL to download the plot and display it in your application.
sigmaCMpa
of a Reference core task.