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

Context parameter in openeo.UDF.from_file() causes confusion #520

Open
JeroenVerstraelen opened this issue Dec 18, 2023 · 6 comments
Open

Comments

@JeroenVerstraelen
Copy link
Contributor

A user let us know that the following code does not pass the context to his UDF:

cube = cube.apply_neighborhood(
    openeo.UDF.from_file("test_udf.py"),
    size=[
        {"dimension": "x", "unit": "px", "value": 32},
        {"dimension": "y", "unit": "px", "value": 32}
    ],
    overlap=[],
    context={"test_variable": "Definitely not None"}
)

The solution was to pass the context in the from_file method instead:

cube = cube.apply_neighborhood(
    openeo.UDF.from_file("test_udf.py", context={"test_variable": "Definitely not None"}),
    size=[
        {"dimension": "x", "unit": "px", "value": 32},
        {"dimension": "y", "unit": "px", "value": 32}
    ],
    overlap=[],
)

We should either:

  • Make it clear that the context parameter should not be used when an UDF object is passed
  • Merge the two context parameters in the process graph
@soxofaan
Copy link
Member

soxofaan commented Jan 9, 2024

I'd like to point out that this is not only a client issue, but a less obvious part of openeo process graphs with run_udf.

There are multiple ways to get "configuration" or context into a UDF:

Directly in run_udf:

 {
   "process_id": "run_udf"
    "arguments": {
      ...
      "context": {"color": "red"}     

or through the parent process, e.g. apply

  {
    "process_id": "apply",
    "arguments": {
      ...
      "process": {
        ...
        "runudf1": {
          "process_id": "run_udf",
          "arguments": {
            "context": {"from_parameter": "context"}
            ...
        .....
      "context": {"color": "red"}  

note that the context from apply has to be passed through explicitly by run_udf with {"from_parameter": "context"}.
If you forget that passing through you get in the situation mentioned above

the following code does not pass the context to his UDF ...

The first solution (direct context in run_udf) is obviously the easiest, e.g. as proposed above too

solution was to pass the context in the from_file method instead

However, the solution with passing through the context from "upstream" is still important to cover, e.g. in UDPs or services where the context or parts of the context come from (UDP) parameters.

@soxofaan
Copy link
Member

soxofaan commented Jan 9, 2024

regardless, we can at least throw warnings client side when it looks like the user might have forgotten something to get the context inside the UDF properly

@soxofaan
Copy link
Member

soxofaan commented Jan 9, 2024

an alternative solution is to use {"from_parameter": "context"} by default in run_udf if there is a context set by the parent process.

@soxofaan
Copy link
Member

soxofaan commented Jan 9, 2024

This is also something we could check for (e.g. in /validation or runtime warning) back-end side

@jdries
Copy link
Collaborator

jdries commented Jan 16, 2024

Note that most of our examples in python client do not show how to use the context. Just adding that there would probably help a lot, as users can then just copy-paste a working example?

@soxofaan
Copy link
Member

an alternative solution is to use {"from_parameter": "context"} by default in run_udf if there is a context set by the parent process.

=>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants