Implement text_field widget in applications

Greetings –

I’ve implemented Jupyter and RStudio apps, setting some custom attributes in the form, and implementing those through native fields in the submit script, submit.yml.erb.

We use slurm resource manager. I’m having trouble implementing a ‘text_field’ widget, so as to pass a nodelist value to slurm. Here’s what I’ve done (in context):

[from form.yml]
custom_queue:
label: “Node Type: batch, gpu for research; class - specific course groups only)”
widget: select
options:
- [ “batch”, “batch” ]
- [ “onboarding”, “onboarding” ]
- [ “class”, “class” ]
- [ “gpu”, “gpu” ]
nodelist:
label: “enter name of specific node”
widget: “text_field”
required: false
form:

  • modules
  • extra_jupyter_args
  • bc_account
  • custom_queue
  • nodelist

[from submit.yml.erb]
script:
queue_name: <%= custom_queue %>
native: # … array of command line arguments …
- “-c <%= num_cores.blank? ? 1 : num_cores.to_i %>”
- “–mem=<%= job_mem.blank? ? 4 : job_mem.to_i %>gb”
- “–time=0-<%= bc_num_hours.blank? ? 1 : bc_num_hours.to_i %>”
- “–nodelist=<%= nodelist %>”

This results in:

(): did not find expected key while parsing a block mapping at line 9 column 1

– I did also think to try placing ‘value:’ in the form, and assuming it would be assigned, but passing nodelist.value in the submit.yml.erb just resulted in undefined method error.

Searching the ood_documentation at osc.github.io and github.io/OSC has not provided examples to implement text_field widgets. I’m not complaining, just trying to show that I’ve attempted to find guidance in the docs before pestering the list.

I figure this is a borderline newbie question, but I’m not even sure how to find general documentation about the widgets as implemented in OnDemand.

Thanks!

This isn’t really batch connect or text_field issue as your form is invalid yaml. I can’t tell from what you’ve given as it’s formatting got messed up in text, but the error is saying line 9 which looks like nodelist or the label below it? (also, I don’t see an attributes on 0th index which you’ll need - but that’s not this issue specifically)

In any case, your issue is something to do with your yaml formatting/indenting. You can try to use an online yaml validator to see if it’s valid yaml or not.

Or you can post back here with encapsulating it, like so.
```yaml
my_yaml: block
```

The nodelist.value in the form.yml will only mean it’s initial value. In the submit.yml.erb you can just refer to it as nodelist (it’s a string).

That said, I think you’re likely right there’s not a lot of recipes for batch connect apps or common troubleshooting issues like this.

Hi, Jeff – Let me see if I can clarify.

I have a working form.yml and submit.yml.erb, for both my Jupyter and RStudio apps.

I want to implement a method to pass a field from form, to submit, that may be used to as the argument in submit.yml.erb for the slurm native ‘–nodelist=’

I’ve attempted to implement via a widget that appears in OOD docs: text_field.

My new code in form.yml, is indented under attributes:


nodelist:
    label: "enter name of specific node"
    widget: "text_field"
    required: false

Eric helped me some time ago to implement the custom_queue, appearing also in the original post. I thought that might provide useful context.

The edit to submit.yml.erb is just the single line including nodelist. I included the broader ‘script:’ section of code for context.

From the statement that ‘nodelist’ is just a string, I had thought I could complete the assignment similar to the use of custom_queue:

script:
queue_name: <%= custom_queue %>
native: # … array of command line arguments …
- “-c <%= num_cores.blank? ? 1 : num_cores.to_i %>”
- “–mem=<%= job_mem.blank? ? 4 : job_mem.to_i %>gb”
- “–time=0-<%= bc_num_hours.blank? ? 1 : bc_num_hours.to_i %>”
- “–nodelist=<%= nodelist %>”

I’d also like to implement other slurm natives in this way, such as features, which can be included in a ‘select’ widget; however, I’m liking the flexibility of a generic text field for my admin/debugging purposes. If you can help me to documentation about OOD implementation of the text_field widget, that would be great.

Thanks,

~ Em

Emily, I’m sorry if there’s confusion. Looks like the only documenation on the subject is here which you’ve likely seen (and is rather sparse).

What you’ve given in your last (or first) post should work given correct indentation. I’d only mentioned indentation initially because the error message you’d given - did not find expected key while parsing a block mapping at line 9 column 1 - is a yaml error you get while parsing.

Your form.yml should look something like this.

attributes:
  custom_queue:
    label: "Node Type: batch, gpu for research; class - specific course groups only)"
    widget: select
    options:
      - [ "batch", "batch" ]
      - [ "onboarding", "onboarding" ]
      - [ "class", "class" ]
      - [ "gpu", "gpu" ]
  # same indentation as custom_queue
  nodelist:
    label: "enter name of specific node"
    widget: "text_field"
    required: false
form:
  - modules
  - extra_jupyter_args
  - bc_account
  - custom_queue
  - nodelist

And your submit yml looks to be just fine.

script:
  queue_name: <%= custom_queue %>
  native: # … array of command line arguments …
    - "-c <%= num_cores.blank? ? 1 : num_cores.to_i %>"
    - "--mem=<%= job_mem.blank? ? 4 : job_mem.to_i %>gb"
    - "--time=0-<%= bc_num_hours.blank? ? 1 : bc_num_hours.to_i %>"
    - "--nodelist=<%= nodelist %>"

Or you could try this if SLURM doesn’t like empty nodelists like --nodelist="".
- "<%- unless nodelist.empty? -%>--nodelist=<%= nodelist %><%- end -%>"

Hope that helps!

Thanks, Jeff – Sounds as though I’m on the right track.

I’ll sort it out, and also learn a bit more about yaml…thanks again!

~ Em

Hey, I take it you implemented a text_field? In any case, I’m solving this, but feel free to reply or open a new ticket if you’re still having issues.

Thanks for following up, Jeff. We did implement selections like this, not ultimately using --nodelist, but by applying the same technique to implement via --constraint. And while a text field was initially implemented, I did ultimately revert to using a ‘select’ widget, similar to the ‘custom_queue’ approach (renamed for our local usage):

type_queue:
label: “Rider Node Type (partition): batch or gpu”
widget: select
options:

  • [ “batch”, “batch” ]

  • [ “gpu”, “gpu” ]
    type_constraint:
    label: “CPU or GPU Node Type”
    widget: select
    options:

  • [ “next available batch node”, “icosa192gb|dodeca96gb|octa64gb” ]

  • [ “batch - icosa192gb”, “icosa192gb” ]

  • [ “batch - dodeca96gb”, “dodeca96gb” ]

  • [ “batch - octa64gb”, “octa64gb” ]

  • [ “next gpu k40 or p100 node”, “gpuk40|gpup100” ]

  • [ “gpu - gpuk40”, “gpuk40”

  • [ “gpu - gpup100”, “gpup100” ]

The submit.yml.erb then has:
script:
queue_name: <%= type_queue %>
native: # … array of command line arguments …

  • “–gres=gpu:<%= num_gpu.blank? ? 1 : num_gpu.to_i %>”
  • "–constraint=<%= type_constraint %>

I also appreciate the tip on handling the empty string for actual text fields.

I’ve become a little less convinced that supporting “free text” flag definition is valuable. To clarify, I mean to supply both of the “key,value” pair for slurm arguments. So rather than having the key statically defined in submit.yml.erb, and passing the value through a text field, pass both the key and value using a text field (or two text fields). So I do remain technically interested, but again, I’m less convinced of the benefit of providing such an interface.

Thanks again.

Very cool. We too have a non-homogeneous cluster and use constraints if folks want to use specific hardware. Here’s our juptyer app where node_type translates into us adding constraints in case else is interested.

Thanks for your example too!