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

Add option to use more complex python code as parameter value #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

JanVogelsang
Copy link

Currently, JUBE only allows parameters with the mode set to python to be simple expressions, which is quite restrictive.
This PR adds the possibility for any arbitrary python code to be passed as a parameter value, which will then use the code's return value as parameter value.

@thobreuer
Copy link
Collaborator

Can you share a few parameter examples that use this extension?

@JanVogelsang
Copy link
Author

JanVogelsang commented Feb 15, 2024

I just have a single concrete example where I use this functionality in my benchmarks (manually generating a cpu-bind-mask to prevent the cpu pinning bug on the JSC systems to affect our results):

- name: cpu_bind_mask
        type: string
        separator: ;
        mode: python
        "_": |
           exec("cpu_bind_masks = list()\nbits_per_task = $threads_per_task\ncurrent_block = 0\nnum_blocks = 0\ncurrent_block_free = 4\nfor _ in range($tasks_per_node):\n    bits_left = bits_per_task\n    cpu_bind_masks.append('0x')\n    while bits_left >= current_block_free:\n        mask = '1'*current_block_free\n        cpu_bind_masks[-1] += hex(int(mask, 2))[2:].upper()\n        bits_left -= current_block_free\n        current_block_free = 4\n        num_blocks += 1\n    if bits_left > 0:\n        mask = '1'*bits_left + '0'*(4-bits_left)\n        cpu_bind_masks[-1] += hex(int(mask, 2))[2:].upper()\n        current_block_free -= bits_left\n    cpu_bind_masks[-1] += '0'*current_block\n    current_block += num_blocks");return ",".join(cpu_bind_masks)

However, this is equivalent to any parameter that can't be written in a single line, e.g.:

- {name: scale, type: int, mode: python, "_": "import math; math.sqrt($num_nodes)"

Ideally, if one could just define custom functions that one could then call inside parameter value definitions (i.e., eval calls), there would be no need for exec anymore. Using exec is just a simple workaround that I could implement myself without digging too deep into the Jube code.

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

Successfully merging this pull request may close these issues.

None yet

2 participants