<jupyter_start><jupyter_text>funcX TutorialfuncX is a Function-as-a-Service (FaaS) platform for science that enables you to convert almost any computing resource into a high-performance function serving device. Deploying a funcX endpoint will integrate your resource into the function serving fabric, allowing you to dynamically send, monitor, and receive results from function invocations. funcX is built on top of Parsl, allowing you to connect your endpoint to large compute resources via traditional batch queues, where funcX will dynamically provision, use, and release resources on-demand to fulfill function requests.Here we provide an example of using funcX to register a function and run it on a publicly available tutorial endpoint. We start by creating a funcX client to interact with the service.<jupyter_code>from funcx.sdk.client import FuncXClient

fxc = FuncXClient()<jupyter_output><empty_output><jupyter_text>Registering a functionHere we define an example function to be used. This function will report the name of the machine it is executed on. funcX functions can be applied to almost any endpoint the user is permitted to use, so we can reuse this function across endpoints.<jupyter_code>def platform(items):
    import platform
    return platform.uname()<jupyter_output><empty_output><jupyter_text>We first register the function WITHOUT a container. This means the function will be executed with either the default python environment the worker is deployed in, or, in the case of a Kubernetes endpoint, the default container used by the endpoint.<jupyter_code>func_uuid1 = fxc.register_function(platform,
                                   description="A function to list platform info")
print(func_uuid1)<jupyter_output>62966e2c-7b84-416e-ad37-ac1341a14cae<jupyter_text>Now that the function has been registered with the funcX service we can invoke it.This code specifies the public funcX tutorial endpoint. Any user is permitted to use this endpoint. The function returns a task_id that can subsequently be used to retrieve the result of its execution.<jupyter_code>payload = []

endpoint_uuid = '4b116d3c-1703-4f8f-9f6f-39921e5864df' # Public tutorial endpoint

res1 = fxc.run(payload, endpoint_id=endpoint_uuid, function_id=func_uuid1)
print(res1)
fxc.get_result(res1)<jupyter_output><empty_output><jupyter_text>Note that the function's result shows that the function was executed on an Amazon EC2 machine.  Running on RiverNow we can try running the function on the River K8s cluster. To do this we simply change the endpoint_uuid and the function will be performed using the default container.  IMPORTANT: The River endpoint is restricted to members of a Globus Auth Group.  To join this group please email Zhuozhao (<EMAIL>).<jupyter_code>river_ep_uuid = '2c92a06a-015d-4bfa-924c-b3d0c36bdad7' # River endpoint

res2 = fxc.run(payload, endpoint_id=river_ep_uuid, function_id=func_uuid1)
print(res2)
fxc.get_result(res2)<jupyter_output><empty_output><jupyter_text>Note that the result now shows the function was executed on River.  Registering a function WITH a contontainer.When registering a function you can associate a specific container with it. If a container is specified, the container will be staged to the endpoint and used to run the function. Here we show how a container is included in the function registration.<jupyter_code>func_uuid2 = fxc.register_function(platform,
                                   container_uuid='00d68bd4-ca6a-4804-a6fa-6ed23b23f607',   # A docker container
                                   description="A function to list platform info")
print(func_uuid2)
payload = [1]

endpoint_uuid = "2c92a06a-015d-4bfa-924c-b3d0c36bdad7" # River endpoint

res3 = fxc.run(payload, endpoint_id=river_ep_uuid, function_id=func_uuid2)
print(res3)<jupyter_output>e7a9772f-0f10-4117-826a-bb43d7bf9aad<jupyter_text>It may take sometime to get the result at the first time, since the endpoint needs to start a pod to run the function for the<jupyter_code>fxc.get_result(res3)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.05447374907567168, 'fraction_numerical': 0.03278284446635445, 'mean_word_length': 5.093093093093093, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '323121', 'license': 'Apache-1.1', 'n_tokens_mistral': 1214, 'n_tokens_neox': 1141, 'n_words': 461, 'path': 'examples/Tutorial-River-Endpoint.ipynb', 'repo_name': 'arokem/funcX', 'size': '4071'}