# Load Objectives

Loads optimization objectives for a trial in globalMOO.

## Endpoint

`POST /models/{model_id}/projects/{project_id}/trials/{trial_id}/objectives`

## Path Parameters

| Parameter   | Type    | Required | Description       |
| ----------- | ------- | -------- | ----------------- |
| model\_id   | integer | Yes      | ID of the model   |
| project\_id | integer | Yes      | ID of the project |
| trial\_id   | integer | Yes      | ID of the trial   |

## Request Parameters

| Parameter      | Type           | Required    | Description                                           |
| -------------- | -------------- | ----------- | ----------------------------------------------------- |
| objectives     | array\[float]  | Yes         | Target values for each objective                      |
| objectiveTypes | array\[string] | Yes         | Type for each objective (see below)                   |
| initialInput   | array\[float]  | Yes         | Initial input values (must match project input count) |
| initialOutput  | array\[float]  | Yes         | Initial output values (must match objectives count)   |
| desiredL1Norm  | float          | Yes         | Desired L1 norm for objectives (default: 0.0)         |
| minimumBounds  | array\[float]  | Conditional | Lower bounds (required for percent/value types)       |
| maximumBounds  | array\[float]  | Conditional | Upper bounds (required for percent/value types)       |

### Objective Types

Valid objective types are:

* `exact` - Match target value exactly within L1 norm
* `percent` - Within a percentage range of target value (requires bounds)
* `value` - Within an absolute range of target value (requires bounds)
* `lessthan` - Less than target value
* `lessthan_equal` - Less than or equal to target value
* `greaterthan` - Greater than target value
* `greaterthan_equal` - Greater than or equal to target value
* `minimize` - Find minimum possible value
* `maximize` - Find maximum possible value

## Request Format

```json
{
    "objectives": [100.0, 50.0, 25.0],
    "objectiveTypes": ["percent", "value", "percent"],
    "initialInput": [1.0, 2.0, 3.0],
    "initialOutput": [90.0, 45.0, 20.0],
    "desiredL1Norm": 0.0,
    "minimumBounds": [-5.0, -2.0, -1.0],
    "maximumBounds": [5.0, 2.0, 1.0]
}
```

## Response Format

```json
{
    "id": 123,
    "trialId": 456,
    "objectives": [100.0, 50.0, 25.0],
    "objectiveTypes": ["percent", "value", "percent"],
    "initialInput": [1.0, 2.0, 3.0],
    "initialOutput": [90.0, 45.0, 20.0],
    "l1Norm": 0.0,
    "minimumBounds": [-5.0, -2.0, -1.0],
    "maximumBounds": [5.0, 2.0, 1.0],
    "createdAt": "2025-01-31T10:00:00.000Z",
    "updatedAt": "2025-01-31T10:00:00.000Z",
    "results": [
        {
            "number": 0,
            "type": "percent",
            "objective": 100.0,
            "minimumBound": null,
            "maximumBound": null,
            "output": 90.0,
            "error": 10.0,
            "detail": "Error exceeds L1 norm threshold",
            "satisfied": false
        },
        {
            "number": 1,
            "type": "value",
            "objective": 50.0,
            "minimumBound": -2.0,
            "maximumBound": 2.0,
            "output": 45.0,
            "error": -5.0,
            "detail": "Output within absolute bounds",
            "satisfied": true
        }
    ]
}
```

## Examples

{% tabs %}
{% tab title="Python" %}

```python
from globalmoo import Client, ObjectiveType

client = Client(api_key="your-api-key")
objectives = client.load_objectives(
    model_id=123,
    project_id=456,
    trial_id=789,
    objectives=[100.0, 50.0, 25.0],
    objective_types=[
        ObjectiveType.PERCENT,
        ObjectiveType.VALUE,
        ObjectiveType.PERCENT
    ],
    initial_input=[1.0, 2.0, 3.0],
    initial_output=[90.0, 45.0, 20.0],
    minimum_bounds=[-5.0, -2.0, -1.0],
    maximum_bounds=[5.0, 2.0, 1.0]
)

# Checking detailed results
for result in objectives.results:
    print(f"Objective {result.number}:")
    print(f"  Type: {result.type}")
    print(f"  Target: {result.objective}")
    print(f"  Output: {result.output}")
    print(f"  Error: {result.error}")
    print(f"  Satisfied: {'✓' if result.satisfied else '✗'}")
    print(f"  Detail: {result.detail}")
```

{% endtab %}

{% tab title="Node.js" %}

```javascript
const { Client } = require('globalmoo');

const client = new Client('your-api-key');
const objectives = await client.loadObjectives({
    modelId: 123,
    projectId: 456,
    trialId: 789,
    objectives: [100.0, 50.0, 25.0],
    objectiveTypes: ["exact", "value", "percent"],
    initialInput: [1.0, 2.0, 3.0],
    initialOutput: [90.0, 45.0, 20.0],
    minimumBounds: [-5.0, -2.0, -1.0],
    maximumBounds: [5.0, 2.0, 1.0]
});
```

{% endtab %}

{% tab title="PHP" %}

```php
$client = new Client("your-api-key");

$objectives = $client->loadObjectives([
    "modelId" => 123,
    "projectId" => 456,
    "trialId" => 789,
    "objectives" => [100.0, 50.0, 25.0],
    "objectiveTypes" => ["exact", "value", "percent"],
    "initialInput" => [1.0, 2.0, 3.0],
    "initialOutput" => [90.0, 45.0, 20.0],
    "minimumBounds" => [-5.0, -2.0, -1.0],
    "maximumBounds" => [5.0, 2.0, 1.0]
]);
```

{% endtab %}
{% endtabs %}

## Error Responses

| Status Code | Description                                                                     |
| ----------- | ------------------------------------------------------------------------------- |
| 400         | Invalid request - Missing required fields, invalid format, or validation errors |
| 401         | Unauthorized - Invalid API key                                                  |
| 404         | Model, project, or trial not found                                              |
| 429         | Too many requests - Rate limit exceeded                                         |
| 500         | Internal server error                                                           |

## Server-Side Validation

The API performs the following validations:

* Model, project, and trial IDs must be positive integers
* Array lengths must be consistent:
  * objectives and objectiveTypes must have the same length
  * initialInput length must match the project's input count
  * initialOutput length must match objectives length
  * minimumBounds/maximumBounds must match objectives length when required
* All numeric values must be valid floating point numbers
* Objective types must be valid types as listed above
* For percent and value objectives:
  * minimumBounds and maximumBounds are required
  * maximumBounds values must be greater than minimumBounds
* desiredL1Norm must be provided and non-negative (defaults to 0.0)
* Trial must exist and be in an active state


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://globalmoo.gitbook.io/globalmoo-documentation/endpoints/objectives/load.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
