Skip to content

Commit

Permalink
Fix CLS caused by img tag, replace with markdown img syntax (#372)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaryanporwal authored Feb 3, 2025
1 parent 9a596a1 commit 4e9b991
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 40 deletions.
64 changes: 24 additions & 40 deletions docs/core-concepts/run-udfs/run.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ Fused UDF functions really shine once you start calling them from anywhere. You
- Less than 120s to execute
- Using less than a few Gb of RAM to run

These jobs run in "real-time" with no start-up time so are quick to run, but with limited resources and time-out if taking too long.
These jobs run in "real-time" with no start-up time so are quick to run, but with limited resources and time-out if taking too long.

## [`fused.run()`](/python-sdk/top-level-functions/#run)

[`fused.run()`](/python-sdk/top-level-functions/#run) is the simplest & most common way to execute a UDF from any Python script or notebook.
[`fused.run()`](/python-sdk/top-level-functions/#run) is the simplest & most common way to execute a UDF from any Python script or notebook.

The simplest way to call a public UDF is using a [public UDF name](/core-concepts/run-udfs/run-small-udfs/#public-udf-name) and calling it as: `UDF_` + name. Let's take this UDF that returns [the location of the Eiffel Tower](https://github.com/fusedio/udfs/tree/main/public/Single_point_Eiffel_Tower) in a `GeoDataFrame` as an example:

Expand All @@ -32,13 +32,11 @@ import fused
fused.run("UDF_Single_point_Eiffel_Tower")
```

import ImgSimpleETUDF from '@site/static/img/core-concepts/run-udfs/running_simple_eiffel_tower_udf.png';

<div style={{textAlign: 'center'}}>
<img src={ImgSimpleETUDF} alt="Simple UDF fused.run() returning a geodataframe" style={{width: 400}} />
</div>
![Simple UDF fused.run() returning a geodataframe](/img/core-concepts/run-udfs/running_simple_eiffel_tower_udf.png)

There are a few other ways to run a UDF:

- [By name from your account](/core-concepts/run-udfs/run-small-udfs/#name-from-your-account)
- [By public UDF name](/core-concepts/run-udfs/run-small-udfs/#public-udf-name)
- [Using a token](/core-concepts/run-udfs/run-small-udfs/#token)
Expand All @@ -54,23 +52,17 @@ You can call any UDFs you have made simply by calling it by name (given when you

(Note: This requires authentication)

import ImgHelloWorldUDF from '@site/static/img/core-concepts/run-udfs/hello_world_bbox_udf.png';

<div style={{textAlign: 'center'}}>
<img src={ImgHelloWorldUDF} alt="Hello World UDF" style={{width: 700}} />
</div>
![Hello World UDF](/img/core-concepts/run-udfs/hello_world_bbox_udf.png)

This UDF can then be run in a notebook locally (granted that you have authenticated):

```python showLineNumbers
fused.run("Hello_World_bbox")
```

import ImgRunHWUDF from '@site/static/img/core-concepts/run-udfs/running_hello_world_bbox_udf.png';

<div style={{textAlign: 'center'}}>
<img src={ImgRunHWUDF} alt="RunningHello World UDF" style={{width: 700}} />
</div>
![Running Hello World UDF](/img/core-concepts/run-udfs/running_hello_world_bbox_udf.png)

### _Public UDF Name_

Expand All @@ -91,6 +83,7 @@ _When to use: Whenever you want someone to be able to execute a UDF but might no
You can get the token from a UDF either in [Workbench](/workbench/) (Save your UDF then go to "Settings" -> "Share" -> "Fused App") or returning the token in Python.

Here's a toy UDF that we want others to be able to run, but we don't want them to see the code:

```python showLineNumbers
import fused

Expand All @@ -108,7 +101,7 @@ my_super_duper_private_udf.to_fused()
```

:::note
`my_udf.to_fused()` saves your UDF to your personal user UDFs. These are private to you and your team. You can create a token than anyone (even outside your team) can use to run your UDF but by default these UDFs are private.
`my_udf.to_fused()` saves your UDF to your personal user UDFs. These are private to you and your team. You can create a token than anyone (even outside your team) can use to run your UDF but by default these UDFs are private.
:::

We can create a token for this `my_super_duper_private_udf` and share it:
Expand All @@ -125,13 +118,13 @@ This would return something like: `'fsh_**********q6X'` (You can recognise this
```python showLineNumbers
fused.run(token, my_udf_input="I'm directly using the token object")
```

or directly:

```python showLineNumbers
fused.run('fsh_**********q6X', my_udf_input="I can't see you're private UDF but can still run it")
```


### _UDF_ object

_When to run: When you're writing your UDF in the same Python file / jupyter notebook and want to refer to the Python object directly. You might want to do this to test your UDF works locally for example_
Expand Down Expand Up @@ -160,11 +153,12 @@ fused.run(gh_udf)
```

:::warning
We do NOT recommend you use this approach as your UDF might break if changes are done to it
We do NOT recommend you use this approach as your UDF might break if changes are done to it

Especially using a URL pointing to a `main` branch means that your UDF will change if someone else pushes towards it, in a way that isn't visible to you.

For that reason we recommend using [git commit hash](/core-concepts/run-udfs/run-small-udfs/#git-commit-hash-recommended-for-most-stable-use-cases) instead

:::

### _Git commit hash_ (recommended for most stable use cases)
Expand All @@ -179,11 +173,9 @@ This does mean you need to update the commit where your UDFs are being called if

Let's again take the example of the Simple Eiffel Tower UDF:

import ImgCommitHash from '@site/static/img/core-concepts/run-udfs/commit_hash_demo.png';
import ImgCommitHash from "@site/static/img/core-concepts/run-udfs/commit_hash_demo.png";

<div style={{textAlign: 'center'}}>
<img src={ImgCommitHash} alt="RunningHello World UDF" style={{width: 700}} />
</div>
![Running Hello World UDF](/img/core-concepts/run-udfs/commit_hash_demo.png)

```python showLineNumbers
commit_hash = "bdfb4d0"
Expand Down Expand Up @@ -221,11 +213,12 @@ fused.run(my_udf, inputs="hello world")
```

A [`fused.run()`](/python-sdk/top-level-functions/#run) call will require the following arguments:

1. [Mandatory] The first argument needs to be the UDF to run (name, object, token, etc [as seen above](/core-concepts/run-udfs/run-small-udfs/#fusedrun))
2. [Optional] Any arguments of the UDF itself (if it has any). In the example above that's `inputs` because `my_udf` takes `inputs` as argument.
3. [Optional] Any protected arguments as seen in the dedicated [API docs page](/python-sdk/top-level-functions/#run) (if applicable). These include for example:
- `bbox` -> A geographical bounding box (as a GeoDataFrame or shapely Geometry) defining the area of interest.
- `x`, `y`, `z` -> Tile coordinates for tile-based UDF execution.
- `bbox` -> A geographical bounding box (as a GeoDataFrame or shapely Geometry) defining the area of interest.
- `x`, `y`, `z` -> Tile coordinates for tile-based UDF execution.

## Running multiple small [`fused.run()`](/python-sdk/top-level-functions/#run) jobs in parallel

Expand All @@ -245,9 +238,10 @@ Say we wanted to run this `udf` 10 times over `inputs = [0,1,2,3,4,5,6,7,8,9]`:
#### [Experimental] Using `run_pool` and `PoolRunner`

:::note
This is not a feature directly implemented in `fused`. Instead we're going to use a code from the [`udfs.public.common`](https://github.com/fusedio/udfs/tree/main/public/common) utils module, that might change over time
This is not a feature directly implemented in `fused`. Instead we're going to use a code from the [`udfs.public.common`](https://github.com/fusedio/udfs/tree/main/public/common) utils module, that might change over time

You can learn more about import utils from UDFs [here](/core-concepts/write/#import-utils-from-other-udfs)

:::

[`PoolRunner`](https://github.com/fusedio/udfs/blob/main/public/common/utils.py#L2164) allows to quickly run a UDF a few times over a dataset or a list of inputs. Using a `lambda` function you can map the function to pass to `PoolRunner`:
Expand All @@ -259,25 +253,19 @@ runner.get_result_all()

In a notebook `runner.get_result_all()` prints the progress status over time until the job is done:

import ImgPoolRunner from '@site/docs/core-concepts/run-udfs/poolrunner-get_results_all.png';

<div style={{textAlign: 'center'}}>
<img src={ImgPoolRunner} alt="Pool Runner" style={{width: 600}} />
</div>
![Pool Runner](/img/core-concepts/run-udfs/poolrunner-get_results_all.png)

#### Getting "real-time" results

You can then get all your results by concatinating them:

```python showLineNumbers
# In this example udf() returns a Pandas DataFrame so `.get_concat()`
# In this example udf() returns a Pandas DataFrame so `.get_concat()`
result = runner.get_concat()
```

with `type(result)` being a `pandas.core.frame.DataFrame`

import ImgSingleUDFTime from '@site/docs/core-concepts/run-udfs/PoolRunner_timer_single_udf.png';
import Img10UDFTime from '@site/docs/core-concepts/run-udfs/PoolRunner_timer_10_udfs.png';

<details>
<summary>Simple `PoolRunner` Benchmark</summary>
Expand All @@ -302,17 +290,13 @@ import Img10UDFTime from '@site/docs/core-concepts/run-udfs/PoolRunner_timer_10_
fused.run(udf, val=1)
```

<div style={{textAlign: 'center'}}>
<img src={ImgSingleUDFTime} alt="Pool Runner" style={{width: 600}} />
</div>
![Pool Runner](/img/core-concepts/run-udfs/PoolRunner_timer_single_udf.png)

This takes 1.8s: A few ms of overhead to send the UDF to Fused server & run + 1s of `time.sleep(1)`

Now using `PoolRunner` to run this over `range(10)`:

<div style={{textAlign: 'center'}}>
<img src={Img10UDFTime} alt="Pool Runner" style={{width: 600}} />
</div>
![Pool Runner](/img/core-concepts/run-udfs/PoolRunner_timer_10_udfs.png)

This takes a few more seconds, but not 10s. `PoolRunner` is a helpful way to scale a single UDF to many inputs in a timely manner.

Expand Down

0 comments on commit 4e9b991

Please sign in to comment.