From 8a40f4beb8f4c0cf7ee3b784977582272ed795e6 Mon Sep 17 00:00:00 2001 From: Loic Maurin Date: Thu, 20 Nov 2025 16:52:46 +0100 Subject: [PATCH 1/7] genai transformations --- loki/transformations/__init__.py | 1 + loki/transformations/genai/__init__.py | 1 + loki/transformations/genai/genai.py | 158 +++++++++++++++++++++++++ pyproject.toml | 5 + 4 files changed, 165 insertions(+) create mode 100644 loki/transformations/genai/__init__.py create mode 100644 loki/transformations/genai/genai.py diff --git a/loki/transformations/__init__.py b/loki/transformations/__init__.py index 388a0168b..1e795944d 100644 --- a/loki/transformations/__init__.py +++ b/loki/transformations/__init__.py @@ -38,3 +38,4 @@ from loki.transformations.dependency import * # noqa from loki.transformations.pragma_model import * # noqa from loki.transformations.temporaries import * # noqa +from loki.transformations.genai import * diff --git a/loki/transformations/genai/__init__.py b/loki/transformations/genai/__init__.py new file mode 100644 index 000000000..a6440c5fd --- /dev/null +++ b/loki/transformations/genai/__init__.py @@ -0,0 +1 @@ +from loki.transformations.genai.genai import * \ No newline at end of file diff --git a/loki/transformations/genai/genai.py b/loki/transformations/genai/genai.py new file mode 100644 index 000000000..b0fd40a24 --- /dev/null +++ b/loki/transformations/genai/genai.py @@ -0,0 +1,158 @@ +import requests +from gt4py.eve.codegen import format_source + +from loki.backend.fgen import fgen +from loki.subroutine import Subroutine +from loki.batch import Transformation +from functools import partial +import logging + + +class AccGenAITransformation(Transformation): + def __init__(self, api_endpoint: str): + self.insert_openacc_directives = partial( + insert_openacc_directives, api_endpoint=api_endpoint + ) + + def transform_subroutine(self, routine, **kwargs): + return self.insert_openacc_directives(routine) + + +class PythonGenAITransformation(Transformation): + def __init__(self, api_endpoint: str): + self.fortran2python = partial(fortran2python, api_endpoint=api_endpoint) + + def transform_subroutine(self, routine, **kwargs): + return self.fortran2python(routine) + + +class DaceGenAITransformation(Transformation): + def __init__(self, api_endpoint: str): + self.python2dace = partial(python2dace, api_endpoint=api_endpoint) + + def transform_file(self, code_string: str): + return self.python2dace(code_string) + + +class PromptedGenAITransformation(Transformation): + def __init__(self, command): + self.command = command + + def transform_subroutine(self, routine, **kwargs): + return generic_prompt(routine, self.command) + + +def query_llm(prompt: str, api_endpoint: str): + """Query llm listening on an api endpoint with a prompt + + Args: + prompt (str): prompt to provide + api_endpoint (str): api_endpoint of llm + + Returns: + _type_: _description_ + """ + + data = {"model": "codestral", "prompt": prompt, "stream": False} + + response = requests.post(api_endpoint, json=data) + return response.json() + + +def test_api(): + return query_llm("Tell me a joke.") + + +def fortran2python(routine: Subroutine, api_endpoint: str) -> str: + """Return python code given a fortran subroutine + + Args: + fsub (Subroutine): fortran subroutine + + Returns: + str: python generated code + """ + + prompt = f"Translate this routine from fortran in python {fgen(routine)}" + + # Call API + response_data = query_llm(prompt, api_endpoint) + response_content = response_data["response"] + + print(response_content) + + # Cut python code in response + python_code = response_content.split("```python")[1].split("```")[0] + + rendered_code = format_source("python", python_code) + return rendered_code + + +def python2dace(python_code: str, api_endpoint: str): + """Generate dace code from a python code. + + Args: + python_code (str): _description_ + + Returns: + _type_: _description_ + """ + + prompt = f"Optimize this routine with dace {python_code}" + + # Call API + response_data = query_llm(prompt, api_endpoint) + response_content = response_data["response"] + + # Cut python code in response + dace_code = response_content.split("```python")[1].split("```")[0] + + rendered_code = format_source("python", dace_code) + return rendered_code + + +def insert_openacc_directives(routine: Subroutine, api_endpoint): + """Generate openacc directives for a fortran subroutine + + Args: + routine (Subroutine): _description_ + + Returns: + _type_: _description_ + """ + + prompt = f"Add OpenACC directives to this routine {fgen(routine)}" + + # Call API + response_data = query_llm(prompt, api_endpoint) + response_content = response_data["response"] + + # Cut response + fortran_code = response_content.split("```fortran")[1].split("```")[0].split("fortran")[-1] + + transformed_routine = Subroutine.from_source(fortran_code, preprocess=True) + return transformed_routine + + +def generic_prompt(routine: Subroutine, command: str, api_endpoint: str): + """Builds a prompt based on a command + a routine + + Args: + routine (Subroutine): routine to transform + command (str): instruction to prompt + + Returns: + _type_: _description_ + """ + + prompt = command + fgen(routine) + + # Call API + response_data = query_llm(prompt, api_endpoint) + response_content = response_data["response"] + + # Cut response + fortran_code = response_content.split("```")[1].split("```")[0].split("fortran")[-1] + + transformed_routine = Subroutine.from_source(fortran_code, preprocess=True) + return transformed_routine diff --git a/pyproject.toml b/pyproject.toml index e1596f45a..2924b7c59 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -92,3 +92,8 @@ namespaces = false # Enable SCM versioning [tool.setuptools_scm] + +[dependency-groups] +dev = [ + "ruff", +] From 0757ff0fe30d8578f88961b095a9cb3d92b1ac00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Maurin?= Date: Wed, 2 Apr 2025 10:37:26 +0000 Subject: [PATCH 2/7] fortran2python transformation --- loki/transformations/genai/fortran2python.py | 49 +++++++ loki/transformations/genai/genai.py | 135 ++++-------------- loki/transformations/genai/tests/__init__.py | 0 .../transformations/genai/tests/test_genai.py | 47 ++++++ 4 files changed, 124 insertions(+), 107 deletions(-) create mode 100644 loki/transformations/genai/fortran2python.py create mode 100644 loki/transformations/genai/tests/__init__.py create mode 100644 loki/transformations/genai/tests/test_genai.py diff --git a/loki/transformations/genai/fortran2python.py b/loki/transformations/genai/fortran2python.py new file mode 100644 index 000000000..f1be4ef23 --- /dev/null +++ b/loki/transformations/genai/fortran2python.py @@ -0,0 +1,49 @@ +from loki.backend.fgen import fgen +from loki.subroutine import Subroutine +from loki.batch import Transformation +from functools import partial +from ollama import ChatResponse, chat, ResponseError +from gt4py.eve.codegen import format_source +import logging + +from loki.transformations.genai.genai import query_llm + +class Fortran2PythonTransformation(Transformation): + def __init__(self): + self.fortran2python = fortran2python + + def transform_subroutine(self, routine, **kwargs): + return self.fortran2python(routine) + +def fortran2python(routine: Subroutine) -> str: + """Return python code given a fortran subroutine + + Args: + fsub (Subroutine): fortran subroutine + + Returns: + str: python generated code + """ + + # Call API + try: + response: ChatResponse = chat(model='codestral:22b', messages=[ + { + 'role': 'user', + 'content': f'Translate this routine from fortran in python {fgen(routine)}', + }, + ]) + except ResponseError as e: + logging.error(f"Error {e.error}") + + + # Cut python code in response + + response_msg = response.message.content + logging.info(f"Response content : {response_msg}") + + + python_code = response_msg.split("```python")[1].split("```")[0] + rendered_code = format_source("python", python_code) + + return rendered_code diff --git a/loki/transformations/genai/genai.py b/loki/transformations/genai/genai.py index b0fd40a24..217db3fae 100644 --- a/loki/transformations/genai/genai.py +++ b/loki/transformations/genai/genai.py @@ -1,38 +1,9 @@ import requests -from gt4py.eve.codegen import format_source +from ollama import chat, ChatResponse from loki.backend.fgen import fgen from loki.subroutine import Subroutine from loki.batch import Transformation -from functools import partial -import logging - - -class AccGenAITransformation(Transformation): - def __init__(self, api_endpoint: str): - self.insert_openacc_directives = partial( - insert_openacc_directives, api_endpoint=api_endpoint - ) - - def transform_subroutine(self, routine, **kwargs): - return self.insert_openacc_directives(routine) - - -class PythonGenAITransformation(Transformation): - def __init__(self, api_endpoint: str): - self.fortran2python = partial(fortran2python, api_endpoint=api_endpoint) - - def transform_subroutine(self, routine, **kwargs): - return self.fortran2python(routine) - - -class DaceGenAITransformation(Transformation): - def __init__(self, api_endpoint: str): - self.python2dace = partial(python2dace, api_endpoint=api_endpoint) - - def transform_file(self, code_string: str): - return self.python2dace(code_string) - class PromptedGenAITransformation(Transformation): def __init__(self, command): @@ -53,7 +24,7 @@ def query_llm(prompt: str, api_endpoint: str): _type_: _description_ """ - data = {"model": "codestral", "prompt": prompt, "stream": False} + data = {'model': 'codestral', 'prompt': prompt, 'stream': False} response = requests.post(api_endpoint, json=data) return response.json() @@ -62,78 +33,6 @@ def query_llm(prompt: str, api_endpoint: str): def test_api(): return query_llm("Tell me a joke.") - -def fortran2python(routine: Subroutine, api_endpoint: str) -> str: - """Return python code given a fortran subroutine - - Args: - fsub (Subroutine): fortran subroutine - - Returns: - str: python generated code - """ - - prompt = f"Translate this routine from fortran in python {fgen(routine)}" - - # Call API - response_data = query_llm(prompt, api_endpoint) - response_content = response_data["response"] - - print(response_content) - - # Cut python code in response - python_code = response_content.split("```python")[1].split("```")[0] - - rendered_code = format_source("python", python_code) - return rendered_code - - -def python2dace(python_code: str, api_endpoint: str): - """Generate dace code from a python code. - - Args: - python_code (str): _description_ - - Returns: - _type_: _description_ - """ - - prompt = f"Optimize this routine with dace {python_code}" - - # Call API - response_data = query_llm(prompt, api_endpoint) - response_content = response_data["response"] - - # Cut python code in response - dace_code = response_content.split("```python")[1].split("```")[0] - - rendered_code = format_source("python", dace_code) - return rendered_code - - -def insert_openacc_directives(routine: Subroutine, api_endpoint): - """Generate openacc directives for a fortran subroutine - - Args: - routine (Subroutine): _description_ - - Returns: - _type_: _description_ - """ - - prompt = f"Add OpenACC directives to this routine {fgen(routine)}" - - # Call API - response_data = query_llm(prompt, api_endpoint) - response_content = response_data["response"] - - # Cut response - fortran_code = response_content.split("```fortran")[1].split("```")[0].split("fortran")[-1] - - transformed_routine = Subroutine.from_source(fortran_code, preprocess=True) - return transformed_routine - - def generic_prompt(routine: Subroutine, command: str, api_endpoint: str): """Builds a prompt based on a command + a routine @@ -145,14 +44,36 @@ def generic_prompt(routine: Subroutine, command: str, api_endpoint: str): _type_: _description_ """ - prompt = command + fgen(routine) + prompt = f"{command} :" + fgen(routine) # Call API response_data = query_llm(prompt, api_endpoint) response_content = response_data["response"] # Cut response - fortran_code = response_content.split("```")[1].split("```")[0].split("fortran")[-1] + raw_answer = response_content.split("```")[1] + + return raw_answer + +if __name__ == "__main__": + +# response: ChatResponse = chat(model='codestral:22b', messages=[ +# { +# 'role': 'user', +# 'content': 'Why is the sky blue?', +# }, +# ]) +# print(response['message']['content']) +# # or access fields directly from the response object +# print(response.message.content) + + response: ChatResponse = chat(model='codestral:22b', messages=[ + { + 'role': 'user', + 'content': 'Generate a matrix multiplication in python', + }, + ]) + print(response['message']['content']) + # or access fields directly from the response object + print(response.message.content) - transformed_routine = Subroutine.from_source(fortran_code, preprocess=True) - return transformed_routine diff --git a/loki/transformations/genai/tests/__init__.py b/loki/transformations/genai/tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/loki/transformations/genai/tests/test_genai.py b/loki/transformations/genai/tests/test_genai.py new file mode 100644 index 000000000..63806c1cc --- /dev/null +++ b/loki/transformations/genai/tests/test_genai.py @@ -0,0 +1,47 @@ +from loki.backend.fgen import fgen +from loki.transformations.genai.fortran2python import Fortran2PythonTransformation +import pytest + +from loki import Subroutine, Module +from loki.ir import nodes as ir, FindNodes + +def test_fortran2python_transformation(): + + fortran_code = """ +subroutine convect_satmixratio(xalpw, xbetaw, xgamw, & + &xlvtt, xlstt, xcpv, xcpd, xci, xcl, & + &ppres, pt, peps, pew, plv, pls, pcph) + implicit none + ! + !* 0.1 declarations of dummy arguments : + ! + ! + real, intent(in) :: ppres ! pressure + real, intent(in) :: pt ! temperature + real, intent(in) :: peps ! xrd / xrv (ideally pre-computed in ) + ! + real, intent(out):: pew ! vapor saturation mixing ratio + real, intent(out):: plv ! latent heat l_v + real, intent(out):: pls ! latent heat l_s + real, intent(out):: pcph ! specific heat c_ph + + real :: zt ! temperature + + + zt = min( 400., max( pt, 10. ) ) ! overflow bound + pew = exp( xalpw - xbetaw / zt - xgamw * log( zt ) ) + pew = peps * pew / ( ppres - pew ) + plv = xlvtt + ( xcpv - xcl ) * ( zt - xtt ) ! compute l_v + pls = xlstt + ( xcpv - xci ) * ( zt - xtt ) ! compute l_i + pcph = xcpd + xcpv * pew +end subroutine convect_satmixratio + """ + + fsub = Subroutine.from_source(fortran_code, preprocess=True) + F2PyT = Fortran2PythonTransformation() + gen_python_code = F2PyT.transform_subroutine(fsub) + + print(gen_python_code) + + assert False + \ No newline at end of file From 40ecdf3dd43d495c58bc28413fb2a4059477da2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Maurin?= Date: Wed, 2 Apr 2025 11:56:18 +0000 Subject: [PATCH 3/7] experimental genai transformations --- loki/transformations/genai/fortran2acc.py | 49 +++++++++++ loki/transformations/genai/fortran2python.py | 12 +-- loki/transformations/genai/genai.py | 79 ----------------- loki/transformations/genai/python2dace.py | 44 ++++++++++ .../transformations/genai/tests/test_genai.py | 84 ++++++++++++++++++- 5 files changed, 183 insertions(+), 85 deletions(-) create mode 100644 loki/transformations/genai/fortran2acc.py delete mode 100644 loki/transformations/genai/genai.py create mode 100644 loki/transformations/genai/python2dace.py diff --git a/loki/transformations/genai/fortran2acc.py b/loki/transformations/genai/fortran2acc.py new file mode 100644 index 000000000..1e08cb761 --- /dev/null +++ b/loki/transformations/genai/fortran2acc.py @@ -0,0 +1,49 @@ +from loki.backend.fgen import fgen +from loki.subroutine import Subroutine +from loki.batch import Transformation +from functools import partial +import logging +from ollama import ResponseError, ChatResponse, chat + +class AccInsertionTransformation(Transformation): + def __init__(self): + self.insert_openacc_directives = insert_openacc_directives + + def transform_subroutine(self, routine, **kwargs): + return self.insert_openacc_directives(routine) + + +def insert_openacc_directives(routine: Subroutine): + """Generate openacc directives for a fortran subroutine + + Args: + routine (Subroutine): _description_ + + Returns: + _type_: _description_ + """ + + # Call API + try: + response: ChatResponse = chat(model='codestral:22b', messages=[ + { + 'role': 'user', + 'content': f'Add OpenACC directives to this routine {fgen(routine)}', + }, + ]) + except ResponseError as e: + logging.error(f"Error {e.error}") + + logging.info(f"Response content {response.message.content}") + print(response.message.content) + content = response.message.content + + # Cut response + if "```fortran" in content: + fortran_code = content.split("```fortran")[1].split("```")[0] + elif "```Fortran" in content: + fortran_code = content.split("```Fortran")[1].split("```")[0] + transformed_routine = Subroutine.from_source(fortran_code, preprocess=True) + + return transformed_routine + diff --git a/loki/transformations/genai/fortran2python.py b/loki/transformations/genai/fortran2python.py index f1be4ef23..c7c0b0bac 100644 --- a/loki/transformations/genai/fortran2python.py +++ b/loki/transformations/genai/fortran2python.py @@ -38,12 +38,14 @@ def fortran2python(routine: Subroutine) -> str: # Cut python code in response + logging.info(f"Response content : {response.message.content}") + print(response.message.content) - response_msg = response.message.content - logging.info(f"Response content : {response_msg}") - - - python_code = response_msg.split("```python")[1].split("```")[0] + if "```python" in response.message.content: + python_code = response.message.content.split("```python")[1].split("```")[0] + else: + python_code = response.message.content + rendered_code = format_source("python", python_code) return rendered_code diff --git a/loki/transformations/genai/genai.py b/loki/transformations/genai/genai.py deleted file mode 100644 index 217db3fae..000000000 --- a/loki/transformations/genai/genai.py +++ /dev/null @@ -1,79 +0,0 @@ -import requests -from ollama import chat, ChatResponse - -from loki.backend.fgen import fgen -from loki.subroutine import Subroutine -from loki.batch import Transformation - -class PromptedGenAITransformation(Transformation): - def __init__(self, command): - self.command = command - - def transform_subroutine(self, routine, **kwargs): - return generic_prompt(routine, self.command) - - -def query_llm(prompt: str, api_endpoint: str): - """Query llm listening on an api endpoint with a prompt - - Args: - prompt (str): prompt to provide - api_endpoint (str): api_endpoint of llm - - Returns: - _type_: _description_ - """ - - data = {'model': 'codestral', 'prompt': prompt, 'stream': False} - - response = requests.post(api_endpoint, json=data) - return response.json() - - -def test_api(): - return query_llm("Tell me a joke.") - -def generic_prompt(routine: Subroutine, command: str, api_endpoint: str): - """Builds a prompt based on a command + a routine - - Args: - routine (Subroutine): routine to transform - command (str): instruction to prompt - - Returns: - _type_: _description_ - """ - - prompt = f"{command} :" + fgen(routine) - - # Call API - response_data = query_llm(prompt, api_endpoint) - response_content = response_data["response"] - - # Cut response - raw_answer = response_content.split("```")[1] - - return raw_answer - -if __name__ == "__main__": - -# response: ChatResponse = chat(model='codestral:22b', messages=[ -# { -# 'role': 'user', -# 'content': 'Why is the sky blue?', -# }, -# ]) -# print(response['message']['content']) -# # or access fields directly from the response object -# print(response.message.content) - - response: ChatResponse = chat(model='codestral:22b', messages=[ - { - 'role': 'user', - 'content': 'Generate a matrix multiplication in python', - }, - ]) - print(response['message']['content']) - # or access fields directly from the response object - print(response.message.content) - diff --git a/loki/transformations/genai/python2dace.py b/loki/transformations/genai/python2dace.py new file mode 100644 index 000000000..25f5586c0 --- /dev/null +++ b/loki/transformations/genai/python2dace.py @@ -0,0 +1,44 @@ +from loki.batch import Transformation +from functools import partial +from ollama import chat, ChatResponse, ResponseError +from gt4py.eve.codegen import format_source +import logging + +class DaceOptimisationTransformation(Transformation): + def __init__(self): + self.python2dace = python2dace + + def transform_file(self, code_string: str): + return self.python2dace(code_string) + + +def python2dace(python_code: str): + """Generate dace code from a python code. + + Args: + python_code (str): _description_ + + Returns: + _type_: _description_ + """ + + # Call API + try: + response: ChatResponse = chat(model='codestral:22b', messages=[ + { + 'role': 'user', + 'content': f'Optimize this python function with dace : {python_code}', + }, + ]) + except ResponseError as e: + logging.error(f"Error {e.error}") + + + print("Dace Transformation output") + print(response.message.content) + + # Cut python code in response + dace_code = response.message.content.split("```python")[1].split("```")[0] + + return format_source("python", dace_code) + diff --git a/loki/transformations/genai/tests/test_genai.py b/loki/transformations/genai/tests/test_genai.py index 63806c1cc..91ea0e696 100644 --- a/loki/transformations/genai/tests/test_genai.py +++ b/loki/transformations/genai/tests/test_genai.py @@ -1,5 +1,7 @@ from loki.backend.fgen import fgen +from loki.transformations.genai.fortran2acc import AccInsertionTransformation from loki.transformations.genai.fortran2python import Fortran2PythonTransformation +from loki.transformations.genai.python2dace import DaceOptimisationTransformation import pytest from loki import Subroutine, Module @@ -44,4 +46,84 @@ def test_fortran2python_transformation(): print(gen_python_code) assert False - \ No newline at end of file + +def test_fortran2acc(): + + fortran_code = """ +subroutine convect_satmixratio(xalpw, xbetaw, xgamw, & + &xlvtt, xlstt, xcpv, xcpd, xci, xcl, & + &ppres, pt, peps, pew, plv, pls, pcph) + implicit none + ! + !* 0.1 declarations of dummy arguments : + ! + ! + real, intent(in) :: ppres ! pressure + real, intent(in) :: pt ! temperature + real, intent(in) :: peps ! xrd / xrv (ideally pre-computed in ) + ! + real, intent(out):: pew ! vapor saturation mixing ratio + real, intent(out):: plv ! latent heat l_v + real, intent(out):: pls ! latent heat l_s + real, intent(out):: pcph ! specific heat c_ph + + real :: zt ! temperature + + + zt = min( 400., max( pt, 10. ) ) ! overflow bound + pew = exp( xalpw - xbetaw / zt - xgamw * log( zt ) ) + pew = peps * pew / ( ppres - pew ) + plv = xlvtt + ( xcpv - xcl ) * ( zt - xtt ) ! compute l_v + pls = xlstt + ( xcpv - xci ) * ( zt - xtt ) ! compute l_i + pcph = xcpd + xcpv * pew +end subroutine convect_satmixratio + """ + + fsub = Subroutine.from_source(fortran_code, preprocess=True) + AccT = AccInsertionTransformation() + gen_fsub = AccT.transform_subroutine(fsub) + + print(gen_fsub) + + assert False + + +def test_daceoptimisation_transformation(): + + fortran_code = """ +subroutine convect_satmixratio(xalpw, xbetaw, xgamw, & + &xlvtt, xlstt, xcpv, xcpd, xci, xcl, & + &ppres, pt, peps, pew, plv, pls, pcph) + implicit none + ! + !* 0.1 declarations of dummy arguments : + ! + ! + real, intent(in) :: ppres ! pressure + real, intent(in) :: pt ! temperature + real, intent(in) :: peps ! xrd / xrv (ideally pre-computed in ) + ! + real, intent(out):: pew ! vapor saturation mixing ratio + real, intent(out):: plv ! latent heat l_v + real, intent(out):: pls ! latent heat l_s + real, intent(out):: pcph ! specific heat c_ph + + real :: zt ! temperature + + + zt = min( 400., max( pt, 10. ) ) ! overflow bound + pew = exp( xalpw - xbetaw / zt - xgamw * log( zt ) ) + pew = peps * pew / ( ppres - pew ) + plv = xlvtt + ( xcpv - xcl ) * ( zt - xtt ) ! compute l_v + pls = xlstt + ( xcpv - xci ) * ( zt - xtt ) ! compute l_i + pcph = xcpd + xcpv * pew +end subroutine convect_satmixratio + """ + + fsub = Subroutine.from_source(fortran_code, preprocess=True) + DaceOptT = DaceOptimisationTransformation() + gen_fsub = DaceOptT.transform_subroutine(fsub) + + print(gen_fsub) + + assert False \ No newline at end of file From 9af51ae6391b23b4fcff4bd1567a7269a2f6c52d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Maurin?= Date: Thu, 3 Apr 2025 09:11:40 +0000 Subject: [PATCH 4/7] genai output --- .../convect_closure_adjust_shal.F90 | 31 +++ genai_examples/convect_closure_adjust_shal.py | 23 +++ .../dace_convect_closure_adjust_shal.py | 31 +++ genai_examples/genai.md | 191 ++++++++++++++++++ ...rm_convect_closure_adjust_shal_answer.json | 1 + ...form_convect_closure_adjust_shal_answer.md | 1 + 6 files changed, 278 insertions(+) create mode 100644 genai_examples/convect_closure_adjust_shal.F90 create mode 100644 genai_examples/convect_closure_adjust_shal.py create mode 100644 genai_examples/dace_convect_closure_adjust_shal.py create mode 100644 genai_examples/genai.md create mode 100644 genai_examples/transform_convect_closure_adjust_shal_answer.json create mode 100644 genai_examples/transform_convect_closure_adjust_shal_answer.md diff --git a/genai_examples/convect_closure_adjust_shal.F90 b/genai_examples/convect_closure_adjust_shal.F90 new file mode 100644 index 000000000..ee542d6fa --- /dev/null +++ b/genai_examples/convect_closure_adjust_shal.F90 @@ -0,0 +1,31 @@ +SUBROUTINE CONVECT_CLOSURE_ADJUST_SHAL(KLON, KLEV, PADJ, PUMF, PZUMF, PUER, PZUER, PUDR, PZUDR) + USE PARKIND1, ONLY: JPRB + ! ... (other declarations and initializations) + + implicit none + + REAL, INTENT(INOUT), DIMENSION(KLON, KLEV) :: PUMF ! updraft mass flux (kg/s) + REAL, INTENT(INOUT), DIMENSION(KLON, KLEV) :: PZUMF ! initial value of " + REAL, INTENT(INOUT), DIMENSION(KLON, KLEV) :: PUER ! updraft entrainment (kg/s) + REAL, INTENT(INOUT), DIMENSION(KLON, KLEV) :: PZUER ! initial value of " + REAL, INTENT(INOUT), DIMENSION(KLON, KLEV) :: PUDR ! updraft detrainment (kg/s) + REAL, INTENT(INOUT), DIMENSION(KLON, KLEV) :: PZUDR ! initial value of " + ! + ! + !* 0.2 Declarations of local variables : + ! + INTEGER :: IKB, IKE ! vert. loop bounds + INTEGER :: JK ! vertical loop index + + !$acc parallel loop collapse(2) private(JK, i_PUMF_0) present(KLON, KLEV, PADJ, PZUMF, PZUER, PZUDR, PUMF, PUER, PUDR) + DO JK=1 + JCVEXB + 1, KLEV - JCVEXT + DO i_PUMF_0=1, KLON + !$acc loop vector + PUMF(i_PUMF_0, JK) = PZUMF(i_PUMF_0, JK)*PADJ(i_PUMF_0) + PUER(i_PUMF_0, JK) = PZUER(i_PUMF_0, JK)*PADJ(i_PUMF_0) + PUDR(i_PUMF_0, JK) = PZUDR(i_PUMF_0, JK)*PADJ(i_PUMF_0) + END DO + END DO + !$acc end parallel loop + + END SUBROUTINE CONVECT_CLOSURE_ADJUST_SHAL \ No newline at end of file diff --git a/genai_examples/convect_closure_adjust_shal.py b/genai_examples/convect_closure_adjust_shal.py new file mode 100644 index 000000000..4f5a8209e --- /dev/null +++ b/genai_examples/convect_closure_adjust_shal.py @@ -0,0 +1,23 @@ +from MODD_CONVPAREXT import JCVEXB, JCVEXT + +def convect_closure_adjust_shal(KLON, KLEV, PADJ, PUMF, PZUMF, PUER, PZUER, PUDR, PZUDR): + """ + This routine adjusts the mass flux using the factor PADJ computed in CONVECT_CLOSURE. + The computations are done at every model level starting from bottom. + + Args: + KLON (int): horizontal dimension + KLEV (int): vertical dimension + PADJ (numpy array): mass adjustment factor + PUMF (numpy array): updraft mass flux (kg/s) + PZUMF (numpy array): initial value of PUMF + PUER (numpy array): updraft entrainment (kg/s) + PZUER (numpy array): initial value of PUER + PUDR (numpy array): updraft detrainment (kg/s) + PZUDR (numpy array): initial value of PUDR + """ + + for JK in range(1 + JCVEXB, KLEV - JCVEXT): + PUMF[:, JK] = PZUMF[:, JK] * PADJ[:] + PUER[:, JK] = PZUER[:, JK] * PADJ[:] + PUDR[:, JK] = PZUDR[:, JK] * PADJ[:] diff --git a/genai_examples/dace_convect_closure_adjust_shal.py b/genai_examples/dace_convect_closure_adjust_shal.py new file mode 100644 index 000000000..87f71dcc3 --- /dev/null +++ b/genai_examples/dace_convect_closure_adjust_shal.py @@ -0,0 +1,31 @@ +import dace +from MODD_CONVPAREXT import JCVEXB, JCVEXT +import numpy as np + +@dace.program +def convect_closure_adjust_shal(KLON: int, KLEV: int, PADJ: np.ndarray, PUMF: np.ndarray, PZUMF: np.ndarray, PUER: np.ndarray, PZUER: np.ndarray, PUDR: np.ndarray, PZUDR: np.ndarray) -> None: + """ + This routine adjusts the mass flux using the factor PADJ computed in CONVECT_CLOSURE. + The computations are done at every model level starting from bottom. + + Args: + KLON (int): horizontal dimension + KLEV (int): vertical dimension + PADJ (numpy array): mass adjustment factor + PUMF (numpy array): updraft mass flux (kg/s) + PZUMF (numpy array): initial value of PUMF + PUER (numpy array): updraft entrainment (kg/s) + PZUER (numpy array): initial value of PUER + PUDR (numpy array): updraft detrainment (kg/s) + PZUDR (numpy array): initial value of PUDR + """ + for JK in dace.map[1 + JCVEXB: KLEV - JCVEXT]: + with dace.tasklet: + a = PADJ[:] + b, c, d = PZUMF[:, JK], PZUER[:, JK], PZUDR[:, JK] + """ + Adjusting mass flux, updraft entrainment and detrainment + """ + PUMF[::, JK] <<= b * a + PUER[::, JK] = c * a + PUDR[::, JK] = d * a \ No newline at end of file diff --git a/genai_examples/genai.md b/genai_examples/genai.md new file mode 100644 index 000000000..4060a4dc5 --- /dev/null +++ b/genai_examples/genai.md @@ -0,0 +1,191 @@ +# Using Codestral as a code assistant + +## Installation + +A local instance of [codestral:22b](https://mistral.ai/news/codestral) has been installed on an EWC instance. + +Codestral is a 22B parameters LLM (Large Language Model) from [Mistral](https://mistral.ai) trained for coding tasks. + +Here, Codestral is exposed through [ollama](ollama.ai) inference server for LLMs. Ollama exposes a CLI and a localhost API endpoint to query LLMs. + + ```bash +# query with CLI +ollama run codestral:22b "your-prompt" + ``` + +- VSCode integration : + +We've made codestral available in VSCode with [Continue.dev](https://docs.continue.dev/) plugin. Continue.dev provides a chat in VSCode + commands for autocompletion. It's used with a local config + +```json +{ + "models": [ + { + "title": "Codestral", + "provider": "ollama", + "model": "codestral:22b" + } + ], +} +``` + +- WIP -> API Endpoint : + +The local installation is only accessible vi ssh, especially vscode remote ssh server. It's intended to expose a secure API Endpoint. + + +## Loki integration + +3 loki transformations has been created. + +- PythonGenAITransformation : transforming fortran to python +- ACCGenAITransformation : inserting OpenACC directives in a python script +- DaceGenAITransfomration : generating a Dace script from a python script (intended to be chained with the python transformation). + +A generic transformation is also available : + +- PromptedGenAITransformation : it combines a command (ex : "Transform this routine to python" and a stringified fortran routine fgen(routine)) + +## Examples + +### Raw Fortran Subroutine + +```fortran +! ######spl + SUBROUTINE CONVECT_CLOSURE_ADJUST_SHAL( CVPEXT, D, PADJ, & + PUMF, PZUMF, PUER, PZUER, PUDR, PZUDR ) + USE YOMHOOK , ONLY : LHOOK, DR_HOOK, JPHOOK +! +USE MODD_CONVPAREXT, ONLY : CONVPAREXT +USE MODD_DIMPHYEX, ONLY: DIMPHYEX_T +! +IMPLICIT NONE +! +TYPE(CONVPAREXT), INTENT(IN) :: CVPEXT +TYPE(DIMPHYEX_T), INTENT(IN) :: D +REAL, DIMENSION(D%NIT), INTENT(IN) :: PADJ ! mass adjustment factor +! +! +REAL, DIMENSION(D%NIT,D%NKT), INTENT(INOUT) :: PUMF ! updraft mass flux (kg/s) +REAL, DIMENSION(D%NIT,D%NKT), INTENT(INOUT) :: PZUMF ! initial value of " +REAL, DIMENSION(D%NIT,D%NKT), INTENT(INOUT) :: PUER ! updraft entrainment (kg/s) +REAL, DIMENSION(D%NIT,D%NKT), INTENT(INOUT) :: PZUER ! initial value of " +REAL, DIMENSION(D%NIT,D%NKT), INTENT(INOUT) :: PUDR ! updraft detrainment (kg/s) +REAL, DIMENSION(D%NIT,D%NKT), INTENT(INOUT) :: PZUDR ! initial value of " +! +INTEGER :: IKB, IKE ! vert. loop bounds +INTEGER :: JK, JI ! vertical loop index +! +REAL(KIND=JPHOOK) :: ZHOOK_HANDLE +IF (LHOOK) CALL DR_HOOK('CONVECT_CLOSURE_ADJUST_SHAL',0,ZHOOK_HANDLE) +IKB = 1 + CVPEXT%JCVEXB +IKE = D%NKT - CVPEXT%JCVEXT +! +! +!* 1. Adjust mass flux by the factor PADJ to converge to +! specified degree of stabilization +! ---------------------------------------------------- +! +DO JK = IKB + 1, IKE + DO JI = D%NIB, D%NIE + PUMF(JI,JK) = PZUMF(JI,JK) * PADJ(JI) + PUER(JI,JK) = PZUER(JI,JK) * PADJ(JI) + PUDR(JI,JK) = PZUDR(JI,JK) * PADJ(JI) + ENDDO +END DO +! +END SUBROUTINE CONVECT_CLOSURE_ADJUST_SHAL +``` + +### Fortran to Python transformation + +- Prompt : "Translate this Fortran routine in python" + +```python +from MODD_CONVPAREXT import JCVEXB, JCVEXT + +def convect_closure_adjust_shal(KLON, KLEV, PADJ, PUMF, PZUMF, PUER, PZUER, PUDR, PZUDR): + """ + This routine adjusts the mass flux using the factor PADJ computed in CONVECT_CLOSURE. + The computations are done at every model level starting from bottom. + + Args: + KLON (int): horizontal dimension + KLEV (int): vertical dimension + PADJ (numpy array): mass adjustment factor + PUMF (numpy array): updraft mass flux (kg/s) + PZUMF (numpy array): initial value of PUMF + PUER (numpy array): updraft entrainment (kg/s) + PZUER (numpy array): initial value of PUER + PUDR (numpy array): updraft detrainment (kg/s) + PZUDR (numpy array): initial value of PUDR + """ + + for JK in range(1 + JCVEXB, KLEV - JCVEXT): + PUMF[:, JK] = PZUMF[:, JK] * PADJ[:] + PUER[:, JK] = PZUER[:, JK] * PADJ[:] + PUDR[:, JK] = PZUDR[:, JK] * PADJ[:] + +``` + +### Python -> Dace + +- Prompt : "Optimize this routine with dace" + routine python précédement générée. + +```python +import dace +from MODD_CONVPAREXT import JCVEXB, JCVEXT +import numpy as np + +@dace.program +def convect_closure_adjust_shal(KLON: int, KLEV: int, PADJ: np.ndarray, PUMF: np.ndarray, PZUMF: np.ndarray, PUER: np.ndarray, PZUER: np.ndarray, PUDR: np.ndarray, PZUDR: np.ndarray) -> None: + """ + This routine adjusts the mass flux using the factor PADJ computed in CONVECT_CLOSURE. + The computations are done at every model level starting from bottom. + + Args: + KLON (int): horizontal dimension + KLEV (int): vertical dimension + PADJ (numpy array): mass adjustment factor + PUMF (numpy array): updraft mass flux (kg/s) + PZUMF (numpy array): initial value of PUMF + PUER (numpy array): updraft entrainment (kg/s) + PZUER (numpy array): initial value of PUER + PUDR (numpy array): updraft detrainment (kg/s) + PZUDR (numpy array): initial value of PUDR + """ + for JK in dace.map[1 + JCVEXB: KLEV - JCVEXT]: + with dace.tasklet: + a = PADJ[:] + b, c, d = PZUMF[:, JK], PZUER[:, JK], PZUDR[:, JK] + """ + Adjusting mass flux, updraft entrainment and detrainment + """ + PUMF[::, JK] <<= b * a + PUER[::, JK] = c * a + PUDR[::, JK] = d * a +``` + +### Insertion de directives OpenACC + +- Prompt : "Add OpenACC directives to the previous routine" + +```fortran +SUBROUTINE CONVECT_CLOSURE_ADJUST_SHAL(KLON, KLEV, PADJ, PUMF, PZUMF, PUER, PZUER, PUDR, PZUDR) +USE PARKIND1, ONLY: JPRB +! ... (other declarations and initializations) + +!$acc parallel loop collapse(2) private(JK, i_PUMF_0) present(KLON, KLEV, PADJ, PZUMF, PZUER, PZUDR, PUMF, PUER, PUDR) +DO JK=1 + JCVEXB + 1, KLEV - JCVEXT + DO i_PUMF_0=1, KLON + !$acc loop vector + PUMF(i_PUMF_0, JK) = PZUMF(i_PUMF_0, JK)*PADJ(i_PUMF_0) + PUER(i_PUMF_0, JK) = PZUER(i_PUMF_0, JK)*PADJ(i_PUMF_0) + PUDR(i_PUMF_0, JK) = PZUDR(i_PUMF_0, JK)*PADJ(i_PUMF_0) + END DO +END DO +!$acc end parallel loop + +END SUBROUTINE CONVECT_CLOSURE_ADJUST_SHAL +``` + diff --git a/genai_examples/transform_convect_closure_adjust_shal_answer.json b/genai_examples/transform_convect_closure_adjust_shal_answer.json new file mode 100644 index 000000000..9b883a813 --- /dev/null +++ b/genai_examples/transform_convect_closure_adjust_shal_answer.json @@ -0,0 +1 @@ +{"model": "codestral", "created_at": "2025-03-21T16:12:17.815730344Z", "response": " Here is the Python version of your subroutine:\n\n```python\nfrom MODD_CONVPAREXT import JCVEXB, JCVEXT\n\ndef convect_closure_adjust_shal(KLON, KLEV, PADJ, PUMF, PZUMF, PUER, PZUER, PUDR, PZUDR):\n \"\"\"\n This routine adjusts the mass flux using the factor PADJ computed in CONVECT_CLOSURE.\n The computations are done at every model level starting from bottom.\n\n Args:\n KLON (int): horizontal dimension\n KLEV (int): vertical dimension\n PADJ (numpy array): mass adjustment factor\n PUMF (numpy array): updraft mass flux (kg/s)\n PZUMF (numpy array): initial value of PUMF\n PUER (numpy array): updraft entrainment (kg/s)\n PZUER (numpy array): initial value of PUER\n PUDR (numpy array): updraft detrainment (kg/s)\n PZUDR (numpy array): initial value of PUDR\n \"\"\"\n\n for JK in range(1 + JCVEXB, KLEV - JCVEXT):\n PUMF[:, JK] = PZUMF[:, JK] * PADJ[:]\n PUER[:, JK] = PZUER[:, JK] * PADJ[:]\n PUDR[:, JK] = PZUDR[:, JK] * PADJ[:]\n```\n\nPlease note that:\n- You will need to replace the numpy arrays in the function parameters with your actual data.\n- In this Python version, it is assumed that you have already defined `JCVEXB` and `JCVEXT` in a file named `MODD_CONVPAREXT.py`. If they are not defined there, you should define them directly in this script.\n- This script does not include the explicit declaration of local variables or any other additional functionality that may be present in your original Fortran code.", "done": true, "done_reason": "stop", "context": [3, 29473, 5103, 1442, 1224, 12703, 1065, 22734, 25571, 2362, 2533, 6240, 4960, 4496, 2154, 29498, 22900, 5479, 1664, 29498, 2609, 29566, 11848, 29498, 5579, 1854, 1093, 29564, 29526, 1600, 29493, 1292, 1948, 29558, 29493, 1135, 2609, 29566, 29493, 1135, 4939, 29533, 29493, 1135, 29596, 4939, 29533, 29493, 1135, 29547, 1493, 29493, 1135, 29596, 29547, 1493, 29493, 1135, 29547, 5000, 29493, 1135, 29596, 29547, 5000, 29499, 781, 29473, 14235, 1135, 17923, 7501, 29508, 29493, 10456, 10648, 29515, 1243, 5170, 29528, 781, 29473, 1686, 3055, 1542, 7436, 7436, 7436, 7436, 4358, 2768, 29539, 781, 29473, 1686, 781, 29473, 23227, 1333, 5315, 1042, 23514, 8160, 1234, 7767, 1066, 8160, 3810, 16178, 1072, 1066, 10007, 781, 29473, 23227, 1028, 28408, 5942, 13600, 29473, 1507, 5660, 29491, 1183, 4401, 1465, 1228, 781, 29473, 23227, 1028, 4452, 1066, 12703, 4960, 4496, 2154, 29498, 7082, 29511, 3433, 29498, 2609, 29566, 11848, 29491, 781, 29473, 23227, 781, 29473, 23227, 781, 29473, 23227, 3055, 13646, 781, 29473, 23227, 1028, 26470, 781, 29473, 23227, 1123, 1183, 6800, 1070, 1224, 12703, 1117, 1066, 8160, 1040, 3810, 16178, 2181, 1040, 781, 29473, 23227, 1123, 7767, 1135, 2609, 29566, 17628, 1065, 4960, 4496, 2154, 29498, 22900, 5479, 1664, 781, 29473, 23227, 781, 29473, 23227, 781, 29473, 23227, 1116, 29473, 1119, 21906, 3664, 781, 29473, 23227, 1028, 19465, 781, 29473, 23227, 1123, 14419, 1465, 1228, 2971, 1206, 1780, 2997, 2952, 6383, 1245, 6627, 29491, 781, 29473, 23227, 1123, 1183, 1706, 1070, 23492, 6744, 1066, 7765, 1632, 1040, 8218, 29241, 1093, 28406, 29241, 1377, 781, 29473, 23227, 781, 29473, 23227, 781, 29473, 23227, 3055, 4943, 27271, 1854, 781, 29473, 23227, 1028, 1477, 781, 29473, 23227, 1028, 20462, 19239, 29525, 29498, 3953, 19014, 7162, 25846, 781, 29473, 23227, 3368, 1243, 20435, 3103, 29528, 29493, 1243, 20435, 4804, 1028, 1686, 4978, 6925, 1124, 1040, 14287, 17592, 781, 29473, 23227, 781, 29473, 23227, 3055, 4403, 781, 29473, 23227, 781, 29473, 23227, 3055, 16115, 25065, 1921, 6876, 29545, 28054, 29503, 781, 29473, 23227, 1028, 1945, 1144, 781, 29473, 23227, 781, 29473, 23227, 3055, 4403, 781, 29473, 23227, 781, 29473, 23227, 3055, 5283, 20395, 16451, 781, 29473, 23227, 1028, 26403, 781, 29473, 23227, 781, 29473, 23227, 1123, 6505, 29508, 29493, 29518, 1070, 13673, 1093, 12703, 4960, 4496, 2154, 29498, 22900, 5479, 1664, 29498, 2609, 29566, 11848, 29499, 781, 29473, 23227, 781, 29473, 23227, 3055, 26038, 1785, 781, 29473, 23227, 1028, 19465, 781, 29473, 23227, 1123, 1135, 29491, 11136, 3073, 29506, 12788, 1196, 1166, 14928, 2595, 1304, 1049, 29510, 29509, 1031, 8619, 1166, 781, 29473, 23227, 781, 29473, 23227, 3055, 19239, 4834, 18157, 29503, 781, 29473, 23227, 1028, 23611, 781, 29473, 23227, 1123, 18513, 1028, 29518, 29552, 29516, 29502, 29538, 29516, 29542, 29552, 781, 29473, 23227, 1027, 8458, 12220, 1027, 29508, 29550, 29516, 29508, 29508, 29516, 29542, 29552, 781, 29473, 1686, 1945, 1945, 1945, 1945, 10530, 8163, 781, 29473, 1686, 781, 29473, 1686, 29504, 6158, 29502, 29491, 3055, 5330, 3868, 1855, 5634, 29503, 781, 29473, 1686, 2185, 10530, 781, 29473, 1686, 781, 29473, 14235, 19239, 29525, 29498, 3953, 19014, 7162, 25846, 29493, 10456, 10648, 29515, 1243, 20435, 3103, 29528, 29493, 1243, 20435, 4804, 781, 29473, 1686, 781, 29473, 16115, 25065, 1921, 1186, 7117, 781, 29473, 1686, 781, 29473, 1686, 29504, 6158, 29502, 29491, 29508, 1027, 19834, 1051, 1465, 1070, 24852, 7382, 1482, 781, 29473, 1686, 781, 29473, 1686, 781, 29473, 3461, 4160, 12600, 29493, 14057, 3199, 29500, 1543, 29499, 6978, 1292, 29526, 1600, 29473, 1686, 18884, 10479, 781, 29473, 3461, 4160, 12600, 29493, 14057, 3199, 29500, 1543, 29499, 6978, 1292, 1948, 29558, 29473, 1686, 14287, 10479, 781, 29473, 5283, 1854, 29493, 14057, 3199, 29500, 1543, 1325, 1152, 4787, 1788, 9207, 29500, 29564, 29526, 1600, 29499, 6978, 1135, 2609, 29566, 29473, 1686, 3810, 8160, 1234, 7767, 781, 29473, 1686, 781, 29473, 1686, 781, 29473, 5283, 1854, 29493, 14057, 3199, 29500, 1543, 7985, 1325, 1152, 4787, 1788, 9207, 29500, 29564, 29526, 1600, 29493, 1292, 1948, 29558, 29499, 6978, 1135, 4939, 29533, 29473, 1686, 1350, 28258, 3810, 16178, 1093, 8855, 29516, 29481, 29499, 781, 29473, 5283, 1854, 29493, 14057, 3199, 29500, 1543, 7985, 1325, 1152, 4787, 1788, 9207, 29500, 29564, 29526, 1600, 29493, 1292, 1948, 29558, 29499, 6978, 1135, 29596, 4939, 29533, 29473, 1686, 4510, 1960, 1070, 29473, 1113, 781, 29473, 5283, 1854, 29493, 14057, 3199, 29500, 1543, 7985, 1325, 1152, 4787, 1788, 9207, 29500, 29564, 29526, 1600, 29493, 1292, 1948, 29558, 29499, 6978, 1135, 29547, 1493, 29473, 1686, 1350, 28258, 7910, 1194, 1234, 1093, 8855, 29516, 29481, 29499, 781, 29473, 5283, 1854, 29493, 14057, 3199, 29500, 1543, 7985, 1325, 1152, 4787, 1788, 9207, 29500, 29564, 29526, 1600, 29493, 1292, 1948, 29558, 29499, 6978, 1135, 29596, 29547, 1493, 29473, 1686, 4510, 1960, 1070, 29473, 1113, 781, 29473, 5283, 1854, 29493, 14057, 3199, 29500, 1543, 7985, 1325, 1152, 4787, 1788, 9207, 29500, 29564, 29526, 1600, 29493, 1292, 1948, 29558, 29499, 6978, 1135, 29547, 5000, 29473, 1686, 1350, 28258, 2044, 29480, 1194, 1234, 1093, 8855, 29516, 29481, 29499, 781, 29473, 5283, 1854, 29493, 14057, 3199, 29500, 1543, 7985, 1325, 1152, 4787, 1788, 9207, 29500, 29564, 29526, 1600, 29493, 1292, 1948, 29558, 29499, 6978, 1135, 29596, 29547, 5000, 29473, 1686, 4510, 1960, 1070, 29473, 1113, 781, 29473, 1686, 781, 29473, 1686, 781, 29473, 1686, 29504, 6158, 29502, 29491, 29518, 1027, 19834, 1051, 1465, 1070, 2630, 9693, 1482, 781, 29473, 1686, 781, 29473, 3461, 4160, 12600, 6978, 1083, 29564, 29528, 29493, 1083, 5225, 29473, 1686, 7943, 29491, 8638, 15362, 781, 29473, 3461, 4160, 12600, 6978, 1243, 29564, 29473, 1686, 14287, 8638, 3759, 781, 29473, 1686, 781, 29473, 1686, 781, 29473, 1686, 1945, 1945, 1945, 1945, 10530, 8163, 781, 29473, 1686, 781, 29473, 1686, 29504, 6158, 29502, 29491, 29538, 1027, 1892, 8913, 8638, 15362, 781, 29473, 1686, 2185, 1945, 8163, 781, 29473, 1686, 781, 29473, 5283, 1854, 29500, 29564, 7501, 29514, 29566, 5170, 29528, 29499, 6978, 1822, 4872, 5671, 29498, 25060, 781, 29473, 3461, 4160, 12600, 6978, 1381, 29498, 8671, 1493, 29498, 29502, 781, 29473, 3461, 4160, 12600, 6978, 1381, 29498, 8671, 5000, 29498, 29502, 781, 29473, 3461, 4160, 12600, 6978, 1381, 29498, 29521, 4939, 29533, 29498, 29502, 781, 29473, 1686, 781, 29473, 1686, 781, 29473, 1686, 29504, 6158, 29508, 29491, 1028, 2732, 4790, 3810, 16178, 1254, 1040, 7767, 1135, 2609, 29566, 1066, 9873, 1258, 1066, 781, 29473, 1686, 2185, 6908, 6921, 1070, 17656, 2605, 781, 29473, 1686, 2185, 29473, 1945, 1945, 1945, 1270, 781, 29473, 1686, 781, 29473, 10085, 1243, 29564, 29514, 29508, 1416, 1243, 20435, 3103, 29528, 1416, 29473, 29508, 29493, 29564, 1948, 29558, 1155, 1243, 20435, 4804, 781, 3055, 1686, 1161, 24546, 8638, 29501, 29490, 4391, 2839, 29500, 1087, 29502, 1911, 781, 29576, 29544, 29482, 24546, 1053, 4204, 29501, 10142, 2839, 29500, 1087, 29502, 1911, 781, 3055, 10085, 1381, 29498, 29521, 4939, 29533, 29498, 29502, 29514, 29508, 29493, 29564, 29526, 1600, 781, 1123, 1686, 1161, 24546, 8638, 29501, 29490, 4391, 1155, 2955, 29473, 29502, 3607, 781, 1123, 1135, 4939, 29533, 29500, 29478, 29498, 29521, 4939, 29533, 29498, 29502, 29493, 1243, 29564, 29499, 1095, 1135, 29596, 4939, 29533, 29500, 29478, 29498, 29521, 4939, 29533, 29498, 29502, 29493, 1243, 29564, 5637, 29521, 2609, 29566, 29500, 29478, 29498, 29521, 4939, 29533, 29498, 29502, 29499, 781, 1123, 1686, 1161, 24546, 8638, 29501, 29490, 4391, 1155, 2955, 29473, 29502, 1716, 781, 1123, 1686, 1161, 24546, 8638, 29501, 29490, 4391, 1155, 2955, 29473, 29508, 3607, 781, 1123, 1135, 29547, 1493, 29500, 29478, 29498, 29521, 4939, 29533, 29498, 29502, 29493, 1243, 29564, 29499, 1095, 1135, 29596, 29547, 1493, 29500, 29478, 29498, 29521, 4939, 29533, 29498, 29502, 29493, 1243, 29564, 5637, 29521, 2609, 29566, 29500, 29478, 29498, 29521, 4939, 29533, 29498, 29502, 29499, 781, 1123, 1686, 1161, 24546, 8638, 29501, 29490, 4391, 1155, 2955, 29473, 29508, 1716, 781, 1123, 1686, 1161, 24546, 8638, 29501, 29490, 4391, 1155, 2955, 29473, 29518, 3607, 781, 1123, 1135, 29547, 5000, 29500, 29478, 29498, 29521, 4939, 29533, 29498, 29502, 29493, 1243, 29564, 29499, 1095, 1135, 29596, 29547, 5000, 29500, 29478, 29498, 29521, 4939, 29533, 29498, 29502, 29493, 1243, 29564, 5637, 29521, 2609, 29566, 29500, 29478, 29498, 29521, 4939, 29533, 29498, 29502, 29499, 781, 1123, 1686, 1161, 24546, 8638, 29501, 29490, 4391, 1155, 2955, 29473, 29518, 1716, 781, 3055, 22056, 10085, 781, 3055, 1686, 1161, 24546, 8638, 29501, 29490, 4391, 2839, 29500, 1087, 29502, 1911, 1155, 8638, 8231, 7902, 781, 3055, 1686, 1161, 24546, 8638, 29501, 29490, 4391, 2839, 29500, 1087, 29502, 1911, 1155, 8638, 8231, 7902, 781, 29473, 22056, 10085, 781, 29473, 1686, 781, 5768, 25571, 2362, 2533, 6240, 4960, 4496, 2154, 29498, 22900, 5479, 1664, 29498, 2609, 29566, 11848, 29498, 5579, 1854, 4, 1027, 4771, 1117, 1040, 22134, 3519, 1070, 1342, 1851, 29480, 23226, 29515, 781, 781, 14708, 29600, 18435, 781, 3979, 19239, 29525, 29498, 3953, 19014, 7162, 25846, 1494, 1243, 20435, 3103, 29528, 29493, 1243, 20435, 4804, 781, 781, 2038, 19069, 1078, 29498, 15542, 29498, 23330, 29498, 10774, 29500, 29564, 29526, 1600, 29493, 1292, 1948, 29558, 29493, 1135, 2609, 29566, 29493, 1135, 4939, 29533, 29493, 1135, 29596, 4939, 29533, 29493, 1135, 29547, 1493, 29493, 1135, 29596, 29547, 1493, 29493, 1135, 29547, 5000, 29493, 1135, 29596, 29547, 5000, 2097, 781, 3055, 4272, 781, 3055, 1619, 12703, 8160, 29481, 1040, 3810, 16178, 2181, 1040, 7767, 1135, 2609, 29566, 17628, 1065, 4960, 4496, 2154, 29498, 22900, 5479, 1664, 29491, 781, 3055, 1183, 4401, 1465, 1228, 2971, 1206, 1780, 2997, 2952, 6383, 1245, 6627, 29491, 781, 781, 3055, 25765, 29515, 781, 6158, 1292, 29526, 1600, 1093, 1269, 2097, 18884, 10479, 781, 6158, 1292, 1948, 29558, 1093, 1269, 2097, 14287, 10479, 781, 6158, 1135, 2609, 29566, 1093, 29479, 14964, 3061, 2097, 3810, 8160, 1234, 7767, 781, 6158, 1135, 4939, 29533, 1093, 29479, 14964, 3061, 2097, 1350, 28258, 3810, 16178, 1093, 8855, 29516, 29481, 29499, 781, 6158, 1135, 29596, 4939, 29533, 1093, 29479, 14964, 3061, 2097, 4510, 1960, 1070, 1135, 4939, 29533, 781, 6158, 1135, 29547, 1493, 1093, 29479, 14964, 3061, 2097, 1350, 28258, 7910, 1194, 1234, 1093, 8855, 29516, 29481, 29499, 781, 6158, 1135, 29596, 29547, 1493, 1093, 29479, 14964, 3061, 2097, 4510, 1960, 1070, 1135, 29547, 1493, 781, 6158, 1135, 29547, 5000, 1093, 29479, 14964, 3061, 2097, 1350, 28258, 2044, 29480, 1194, 1234, 1093, 8855, 29516, 29481, 29499, 781, 6158, 1135, 29596, 29547, 5000, 1093, 29479, 14964, 3061, 2097, 4510, 1960, 1070, 1135, 29547, 5000, 781, 3055, 4272, 781, 781, 3055, 1122, 1243, 29564, 1065, 3587, 29500, 29508, 1416, 1243, 20435, 3103, 29528, 29493, 1292, 1948, 29558, 1155, 1243, 20435, 4804, 2097, 781, 6158, 1135, 4939, 29533, 29200, 1243, 29564, 29561, 1095, 1135, 29596, 4939, 29533, 29200, 1243, 29564, 29561, 1166, 1135, 2609, 29566, 8488, 29561, 781, 6158, 1135, 29547, 1493, 29200, 1243, 29564, 29561, 1095, 1135, 29596, 29547, 1493, 29200, 1243, 29564, 29561, 1166, 1135, 2609, 29566, 8488, 29561, 781, 6158, 1135, 29547, 5000, 29200, 1243, 29564, 29561, 1095, 1135, 29596, 29547, 5000, 29200, 1243, 29564, 29561, 1166, 1135, 2609, 29566, 8488, 29561, 781, 14708, 29600, 781, 781, 12837, 5807, 1137, 29515, 781, 29501, 1763, 1390, 1695, 1066, 9781, 1040, 26405, 26300, 1065, 1040, 1676, 6055, 1163, 1342, 5463, 1946, 29491, 781, 29501, 1328, 1224, 22134, 3519, 29493, 1146, 1117, 11780, 1137, 1136, 1274, 2909, 4825, 2320, 29566, 20435, 3103, 29528, 29600, 1072, 2320, 29566, 20435, 4804, 29600, 1065, 1032, 2497, 5928, 2320, 8836, 29525, 29498, 3953, 19014, 7162, 25846, 29491, 3602, 10197, 1815, 1358, 1228, 1227, 4825, 1504, 29493, 1136, 1791, 7368, 1474, 5858, 1065, 1224, 7535, 29491, 781, 29501, 1619, 7535, 2003, 1227, 3792, 1040, 10397, 20595, 1070, 2630, 9693, 1210, 1475, 1567, 5638, 21057, 1137, 1761, 1115, 2937, 1065, 1342, 4261, 7731, 9145, 3464, 29491], "total_duration": 100486655438, "load_duration": 9040428, "prompt_eval_count": 1408, "prompt_eval_duration": 8636000000, "eval_count": 493, "eval_duration": 91840000000} \ No newline at end of file diff --git a/genai_examples/transform_convect_closure_adjust_shal_answer.md b/genai_examples/transform_convect_closure_adjust_shal_answer.md new file mode 100644 index 000000000..b064a6546 --- /dev/null +++ b/genai_examples/transform_convect_closure_adjust_shal_answer.md @@ -0,0 +1 @@ +{"model": "codestral", "created_at": "2025-03-21T16:05:52.690550167Z", "response": " Here is the equivalent Python code for the given Fortran subroutine:\n\n```python\nfrom modd_convparext import JCVEXB, JCVEXT\n\ndef convect_closure_adjust_shal(klon, klev, padj, pumf, pzumf, puer, pzer, pudr, pzudr):\n for jk in range(JCVEXB + 1, klev - JCVEXT):\n for i in range(klon):\n pumf[i, jk] = pzumf[i, jk]*padj[i]\n puer[i, jk] = pzer[i, jk]*padj[i]\n pudr[i, jk] = pzudr[i, jk]*padj[i]\n```\n\nPlease note that the variable `JPRB`, which was used for precision in Fortran code is not defined and so it has been omitted from Python code. Also, there is no equivalent of `USE` statement in Python. For that reason, we've assumed that module `MODD_CONVPAREXT` is imported with its content directly accessible to our function. If `JPRB` or other variables/functions are required for your use case, you may need to define them accordingly.", "done": true, "done_reason": "stop", "context": [3, 29473, 5103, 1442, 1224, 12703, 1065, 22734, 25571, 2362, 2533, 6240, 4960, 4496, 2154, 29498, 22900, 5479, 1664, 29498, 2609, 29566, 11848, 29498, 5579, 1854, 1093, 29564, 29526, 1600, 29493, 1292, 1948, 29558, 29493, 1135, 2609, 29566, 29493, 1135, 4939, 29533, 29493, 1135, 29596, 4939, 29533, 29493, 1135, 29547, 1493, 29493, 1135, 29596, 29547, 1493, 29493, 1135, 29547, 5000, 29493, 1135, 29596, 29547, 5000, 29499, 781, 29473, 14235, 1135, 17923, 7501, 29508, 29493, 10456, 10648, 29515, 1243, 5170, 29528, 781, 29473, 1686, 3055, 1542, 7436, 7436, 7436, 7436, 4358, 2768, 29539, 781, 29473, 1686, 781, 29473, 23227, 1333, 5315, 1042, 23514, 8160, 1234, 7767, 1066, 8160, 3810, 16178, 1072, 1066, 10007, 781, 29473, 23227, 1028, 28408, 5942, 13600, 29473, 1507, 5660, 29491, 1183, 4401, 1465, 1228, 781, 29473, 23227, 1028, 4452, 1066, 12703, 4960, 4496, 2154, 29498, 7082, 29511, 3433, 29498, 2609, 29566, 11848, 29491, 781, 29473, 23227, 781, 29473, 23227, 781, 29473, 23227, 3055, 13646, 781, 29473, 23227, 1028, 26470, 781, 29473, 23227, 1123, 1183, 6800, 1070, 1224, 12703, 1117, 1066, 8160, 1040, 3810, 16178, 2181, 1040, 781, 29473, 23227, 1123, 7767, 1135, 2609, 29566, 17628, 1065, 4960, 4496, 2154, 29498, 22900, 5479, 1664, 781, 29473, 23227, 781, 29473, 23227, 781, 29473, 23227, 1116, 29473, 1119, 21906, 3664, 781, 29473, 23227, 1028, 19465, 781, 29473, 23227, 1123, 14419, 1465, 1228, 2971, 1206, 1780, 2997, 2952, 6383, 1245, 6627, 29491, 781, 29473, 23227, 1123, 1183, 1706, 1070, 23492, 6744, 1066, 7765, 1632, 1040, 8218, 29241, 1093, 28406, 29241, 1377, 781, 29473, 23227, 781, 29473, 23227, 781, 29473, 23227, 3055, 4943, 27271, 1854, 781, 29473, 23227, 1028, 1477, 781, 29473, 23227, 1028, 20462, 19239, 29525, 29498, 3953, 19014, 7162, 25846, 781, 29473, 23227, 3368, 1243, 20435, 3103, 29528, 29493, 1243, 20435, 4804, 1028, 1686, 4978, 6925, 1124, 1040, 14287, 17592, 781, 29473, 23227, 781, 29473, 23227, 3055, 4403, 781, 29473, 23227, 781, 29473, 23227, 3055, 16115, 25065, 1921, 6876, 29545, 28054, 29503, 781, 29473, 23227, 1028, 1945, 1144, 781, 29473, 23227, 781, 29473, 23227, 3055, 4403, 781, 29473, 23227, 781, 29473, 23227, 3055, 5283, 20395, 16451, 781, 29473, 23227, 1028, 26403, 781, 29473, 23227, 781, 29473, 23227, 1123, 6505, 29508, 29493, 29518, 1070, 13673, 1093, 12703, 4960, 4496, 2154, 29498, 22900, 5479, 1664, 29498, 2609, 29566, 11848, 29499, 781, 29473, 23227, 781, 29473, 23227, 3055, 26038, 1785, 781, 29473, 23227, 1028, 19465, 781, 29473, 23227, 1123, 1135, 29491, 11136, 3073, 29506, 12788, 1196, 1166, 14928, 2595, 1304, 1049, 29510, 29509, 1031, 8619, 1166, 781, 29473, 23227, 781, 29473, 23227, 3055, 19239, 4834, 18157, 29503, 781, 29473, 23227, 1028, 23611, 781, 29473, 23227, 1123, 18513, 1028, 29518, 29552, 29516, 29502, 29538, 29516, 29542, 29552, 781, 29473, 23227, 1027, 8458, 12220, 1027, 29508, 29550, 29516, 29508, 29508, 29516, 29542, 29552, 781, 29473, 1686, 1945, 1945, 1945, 1945, 10530, 8163, 781, 29473, 1686, 781, 29473, 1686, 29504, 6158, 29502, 29491, 3055, 5330, 3868, 1855, 5634, 29503, 781, 29473, 1686, 2185, 10530, 781, 29473, 1686, 781, 29473, 14235, 19239, 29525, 29498, 3953, 19014, 7162, 25846, 29493, 10456, 10648, 29515, 1243, 20435, 3103, 29528, 29493, 1243, 20435, 4804, 781, 29473, 1686, 781, 29473, 16115, 25065, 1921, 1186, 7117, 781, 29473, 1686, 781, 29473, 1686, 29504, 6158, 29502, 29491, 29508, 1027, 19834, 1051, 1465, 1070, 24852, 7382, 1482, 781, 29473, 1686, 781, 29473, 1686, 781, 29473, 3461, 4160, 12600, 29493, 14057, 3199, 29500, 1543, 29499, 6978, 1292, 29526, 1600, 29473, 1686, 18884, 10479, 781, 29473, 3461, 4160, 12600, 29493, 14057, 3199, 29500, 1543, 29499, 6978, 1292, 1948, 29558, 29473, 1686, 14287, 10479, 781, 29473, 5283, 1854, 29493, 14057, 3199, 29500, 1543, 1325, 1152, 4787, 1788, 9207, 29500, 29564, 29526, 1600, 29499, 6978, 1135, 2609, 29566, 29473, 1686, 3810, 8160, 1234, 7767, 781, 29473, 1686, 781, 29473, 1686, 781, 29473, 5283, 1854, 29493, 14057, 3199, 29500, 1543, 7985, 1325, 1152, 4787, 1788, 9207, 29500, 29564, 29526, 1600, 29493, 1292, 1948, 29558, 29499, 6978, 1135, 4939, 29533, 29473, 1686, 1350, 28258, 3810, 16178, 1093, 8855, 29516, 29481, 29499, 781, 29473, 5283, 1854, 29493, 14057, 3199, 29500, 1543, 7985, 1325, 1152, 4787, 1788, 9207, 29500, 29564, 29526, 1600, 29493, 1292, 1948, 29558, 29499, 6978, 1135, 29596, 4939, 29533, 29473, 1686, 4510, 1960, 1070, 29473, 1113, 781, 29473, 5283, 1854, 29493, 14057, 3199, 29500, 1543, 7985, 1325, 1152, 4787, 1788, 9207, 29500, 29564, 29526, 1600, 29493, 1292, 1948, 29558, 29499, 6978, 1135, 29547, 1493, 29473, 1686, 1350, 28258, 7910, 1194, 1234, 1093, 8855, 29516, 29481, 29499, 781, 29473, 5283, 1854, 29493, 14057, 3199, 29500, 1543, 7985, 1325, 1152, 4787, 1788, 9207, 29500, 29564, 29526, 1600, 29493, 1292, 1948, 29558, 29499, 6978, 1135, 29596, 29547, 1493, 29473, 1686, 4510, 1960, 1070, 29473, 1113, 781, 29473, 5283, 1854, 29493, 14057, 3199, 29500, 1543, 7985, 1325, 1152, 4787, 1788, 9207, 29500, 29564, 29526, 1600, 29493, 1292, 1948, 29558, 29499, 6978, 1135, 29547, 5000, 29473, 1686, 1350, 28258, 2044, 29480, 1194, 1234, 1093, 8855, 29516, 29481, 29499, 781, 29473, 5283, 1854, 29493, 14057, 3199, 29500, 1543, 7985, 1325, 1152, 4787, 1788, 9207, 29500, 29564, 29526, 1600, 29493, 1292, 1948, 29558, 29499, 6978, 1135, 29596, 29547, 5000, 29473, 1686, 4510, 1960, 1070, 29473, 1113, 781, 29473, 1686, 781, 29473, 1686, 781, 29473, 1686, 29504, 6158, 29502, 29491, 29518, 1027, 19834, 1051, 1465, 1070, 2630, 9693, 1482, 781, 29473, 1686, 781, 29473, 3461, 4160, 12600, 6978, 1083, 29564, 29528, 29493, 1083, 5225, 29473, 1686, 7943, 29491, 8638, 15362, 781, 29473, 3461, 4160, 12600, 6978, 1243, 29564, 29473, 1686, 14287, 8638, 3759, 781, 29473, 1686, 781, 29473, 1686, 781, 29473, 1686, 1945, 1945, 1945, 1945, 10530, 8163, 781, 29473, 1686, 781, 29473, 1686, 29504, 6158, 29502, 29491, 29538, 1027, 1892, 8913, 8638, 15362, 781, 29473, 1686, 2185, 1945, 8163, 781, 29473, 1686, 781, 29473, 5283, 1854, 29500, 29564, 7501, 29514, 29566, 5170, 29528, 29499, 6978, 1822, 4872, 5671, 29498, 25060, 781, 29473, 3461, 4160, 12600, 6978, 1381, 29498, 8671, 1493, 29498, 29502, 781, 29473, 3461, 4160, 12600, 6978, 1381, 29498, 8671, 5000, 29498, 29502, 781, 29473, 3461, 4160, 12600, 6978, 1381, 29498, 29521, 4939, 29533, 29498, 29502, 781, 29473, 1686, 781, 29473, 1686, 781, 29473, 1686, 29504, 6158, 29508, 29491, 1028, 2732, 4790, 3810, 16178, 1254, 1040, 7767, 1135, 2609, 29566, 1066, 9873, 1258, 1066, 781, 29473, 1686, 2185, 6908, 6921, 1070, 17656, 2605, 781, 29473, 1686, 2185, 29473, 1945, 1945, 1945, 1270, 781, 29473, 1686, 781, 29473, 10085, 1243, 29564, 29514, 29508, 1416, 1243, 20435, 3103, 29528, 1416, 29473, 29508, 29493, 29564, 1948, 29558, 1155, 1243, 20435, 4804, 781, 3055, 1686, 1161, 24546, 8638, 29501, 29490, 4391, 2839, 29500, 1087, 29502, 1911, 781, 29576, 29544, 29482, 24546, 1053, 4204, 29501, 10142, 2839, 29500, 1087, 29502, 1911, 781, 3055, 10085, 1381, 29498, 29521, 4939, 29533, 29498, 29502, 29514, 29508, 29493, 29564, 29526, 1600, 781, 1123, 1686, 1161, 24546, 8638, 29501, 29490, 4391, 1155, 2955, 29473, 29502, 3607, 781, 1123, 1135, 4939, 29533, 29500, 29478, 29498, 29521, 4939, 29533, 29498, 29502, 29493, 1243, 29564, 29499, 1095, 1135, 29596, 4939, 29533, 29500, 29478, 29498, 29521, 4939, 29533, 29498, 29502, 29493, 1243, 29564, 5637, 29521, 2609, 29566, 29500, 29478, 29498, 29521, 4939, 29533, 29498, 29502, 29499, 781, 1123, 1686, 1161, 24546, 8638, 29501, 29490, 4391, 1155, 2955, 29473, 29502, 1716, 781, 1123, 1686, 1161, 24546, 8638, 29501, 29490, 4391, 1155, 2955, 29473, 29508, 3607, 781, 1123, 1135, 29547, 1493, 29500, 29478, 29498, 29521, 4939, 29533, 29498, 29502, 29493, 1243, 29564, 29499, 1095, 1135, 29596, 29547, 1493, 29500, 29478, 29498, 29521, 4939, 29533, 29498, 29502, 29493, 1243, 29564, 5637, 29521, 2609, 29566, 29500, 29478, 29498, 29521, 4939, 29533, 29498, 29502, 29499, 781, 1123, 1686, 1161, 24546, 8638, 29501, 29490, 4391, 1155, 2955, 29473, 29508, 1716, 781, 1123, 1686, 1161, 24546, 8638, 29501, 29490, 4391, 1155, 2955, 29473, 29518, 3607, 781, 1123, 1135, 29547, 5000, 29500, 29478, 29498, 29521, 4939, 29533, 29498, 29502, 29493, 1243, 29564, 29499, 1095, 1135, 29596, 29547, 5000, 29500, 29478, 29498, 29521, 4939, 29533, 29498, 29502, 29493, 1243, 29564, 5637, 29521, 2609, 29566, 29500, 29478, 29498, 29521, 4939, 29533, 29498, 29502, 29499, 781, 1123, 1686, 1161, 24546, 8638, 29501, 29490, 4391, 1155, 2955, 29473, 29518, 1716, 781, 3055, 22056, 10085, 781, 3055, 1686, 1161, 24546, 8638, 29501, 29490, 4391, 2839, 29500, 1087, 29502, 1911, 1155, 8638, 8231, 7902, 781, 3055, 1686, 1161, 24546, 8638, 29501, 29490, 4391, 2839, 29500, 1087, 29502, 1911, 1155, 8638, 8231, 7902, 781, 29473, 22056, 10085, 781, 29473, 1686, 781, 5768, 25571, 2362, 2533, 6240, 4960, 4496, 2154, 29498, 22900, 5479, 1664, 29498, 2609, 29566, 11848, 29498, 5579, 1854, 4, 1027, 4771, 1117, 1040, 10612, 22134, 3464, 1122, 1040, 2846, 7731, 9145, 1851, 29480, 23226, 29515, 781, 781, 14708, 29600, 18435, 781, 3979, 1736, 29483, 29498, 14106, 11118, 1278, 1494, 1243, 20435, 3103, 29528, 29493, 1243, 20435, 4804, 781, 781, 2038, 19069, 1078, 29498, 15542, 29498, 23330, 29498, 10774, 29500, 5552, 1034, 29493, 1214, 3071, 29493, 9778, 29536, 29493, 1052, 1151, 29490, 29493, 1052, 29532, 1151, 29490, 29493, 1052, 4575, 29493, 1052, 4274, 29493, 1052, 1322, 29480, 29493, 1052, 29532, 1322, 29480, 2097, 781, 3055, 1122, 1229, 29497, 1065, 3587, 29500, 29566, 20435, 3103, 29528, 1416, 29473, 29508, 29493, 1214, 3071, 1155, 1243, 20435, 4804, 2097, 781, 6158, 1122, 1381, 1065, 3587, 29500, 5552, 1034, 2097, 781, 18190, 1052, 1151, 29490, 29560, 29478, 29493, 1229, 29497, 29561, 1095, 1052, 29532, 1151, 29490, 29560, 29478, 29493, 1229, 29497, 16837, 10613, 29536, 29560, 29478, 29561, 781, 18190, 1052, 4575, 29560, 29478, 29493, 1229, 29497, 29561, 1095, 1052, 4274, 29560, 29478, 29493, 1229, 29497, 16837, 10613, 29536, 29560, 29478, 29561, 781, 18190, 1052, 1322, 29480, 29560, 29478, 29493, 1229, 29497, 29561, 1095, 1052, 29532, 1322, 29480, 29560, 29478, 29493, 1229, 29497, 16837, 10613, 29536, 29560, 29478, 29561, 781, 14708, 29600, 781, 781, 12837, 5807, 1137, 1040, 8628, 2320, 29566, 5170, 29528, 7619, 1458, 1171, 2075, 1122, 16789, 1065, 7731, 9145, 3464, 1117, 1227, 4825, 1072, 1347, 1146, 1427, 1518, 4190, 4077, 1245, 22134, 3464, 29491, 5608, 29493, 1504, 1117, 1476, 10612, 1070, 2320, 8711, 29600, 7019, 1065, 22134, 29491, 2031, 1137, 3379, 29493, 1246, 29510, 1101, 11780, 1137, 5365, 2320, 8836, 29525, 29498, 3953, 19014, 7162, 25846, 29600, 1117, 27427, 1163, 1639, 3804, 5858, 15262, 1066, 1581, 1676, 29491, 1815, 2320, 29566, 5170, 29528, 29600, 1210, 1567, 9693, 29516, 20427, 1228, 3798, 1122, 1342, 1706, 1990, 29493, 1136, 1761, 1695, 1066, 7368, 1474, 26253, 29491], "total_duration": 64820849363, "load_duration": 5902887, "prompt_eval_count": 1408, "prompt_eval_duration": 8511000000, "eval_count": 302, "eval_duration": 56302000000} \ No newline at end of file From c30cbe21c582bca108fb40cd2faff4f966bc689b Mon Sep 17 00:00:00 2001 From: Loic Maurin Date: Thu, 20 Nov 2025 16:54:03 +0100 Subject: [PATCH 5/7] ollama python api is a new dependency --- pyproject.toml | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 2924b7c59..f423ca8d2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,22 +17,22 @@ requires-python = ">=3.8" license = {text = "Apache-2.0"} dynamic = ["version", "readme"] dependencies = [ - "numpy >= 2.0", # essential for tests, loop transformations and other dependencies - "pymbolic==2022.2", # essential for expression tree - "PyYAML", # essential for loki-lint - "pcpp", # essential for preprocessing - "more-itertools", # essential for SCC transformation - "click", # essential for CLI scripts - "click-option-group", # essential for CLI scripts - "tomli ; python_version < '3.11'", # essential for scheduler configuration - "networkx", # essential for scheduler and build utilities - "fparser>=0.0.15", # (almost) essential as frontend - "graphviz", # optional for scheduler callgraph - "tqdm", # optional for build utilities - "coloredlogs", # optional for loki-build utility - "junit_xml", # optional for JunitXML output in loki-lint - "codetiming", # essential for scheduler and sourcefile timings - "pydantic>=2.0,<2.10.0", # type checking for IR nodes + "numpy >= 2.0", # essential for tests, loop transformations and other dependencies + "pymbolic==2022.2", # essential for expression tree + "PyYAML", # essential for loki-lint + "pcpp", # essential for preprocessing + "more-itertools", # essential for SCC transformation + "click", # essential for CLI scripts + "toml", # essential for scheduler configuration + "networkx", # essential for scheduler and build utilities + "fparser>=0.0.15", # (almost) essential as frontend + "graphviz", # optional for scheduler callgraph + "tqdm", # optional for build utilities + "coloredlogs", # optional for loki-build utility + "junit_xml", # optional for JunitXML output in loki-lint + "codetiming", # essential for scheduler and sourcefile timings + "pydantic>=2.0,<2.10.0", # type checking for IR nodes + "ollama", ] [project.optional-dependencies] From 0b1f9789c83081d29f8effce9f33691bf23e7591 Mon Sep 17 00:00:00 2001 From: Loic Maurin Date: Thu, 20 Nov 2025 16:55:51 +0100 Subject: [PATCH 6/7] ollama removed --- pyproject.toml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index f423ca8d2..362d2013c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,8 +31,7 @@ dependencies = [ "coloredlogs", # optional for loki-build utility "junit_xml", # optional for JunitXML output in loki-lint "codetiming", # essential for scheduler and sourcefile timings - "pydantic>=2.0,<2.10.0", # type checking for IR nodes - "ollama", + "pydantic>=2.0,<2.10.0", ] [project.optional-dependencies] From ebbe8bc2776c0c57ecdf079baa33d13585be1b29 Mon Sep 17 00:00:00 2001 From: Loic Maurin Date: Thu, 20 Nov 2025 16:58:19 +0100 Subject: [PATCH 7/7] ollama added as a ai-agent dependency --- pyproject.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 362d2013c..ef4883819 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -96,3 +96,6 @@ namespaces = false dev = [ "ruff", ] +ai-agent = [ + "ollama", +]