Undefined local variable or method when trying to hide elements with checkbox

A sort of follow-up to this:

I have a check box hiding elements currently implemented in my form.yml:

m_exclusive:
    widget: "check_box"
    label: "Use entire node"
    html_options:
      data:
        hide-m-cpus-when-checked: true
        hide-m-mem-when-checked: true
        hide-m-gpus-when-checked: true
        data-set-m-cpus: "--exclusive"
        data-set-m-mem: ""
        data-set-m-gpus: ""

My submit.yml looks like the following:

native:
    - "-J"
    - "<%= m_name %>"
    - "-N"
    - "1"
    - "--mem"
    - "<%= m_mem %>G"
    - "-c"
    - "<%= m_cpus %>"
    - "-G"
    - "<%= m_gpus %>"

How do I make it so that if a user selects the m_exclusive checkbox that it will only send --exclusive?

I don’t think checkboxes have support for data-set directives yet.

I think you need to handle this in the submit.yml.erb. Something like this should do.

<%-
  args = ["-J", m_name, "-N", "1", "--mem", "#{m_mem}G", "-c", m_cpus, "-G", m_gpus]

  args.concat(["--exclusive"]) if m_exclusive == 1
-%>

script:
  native:
  <%- args.each do |arg| %>
    - "<%= arg %>"
  <%- end %>

Though note that I don’t exactly recall how checkboxes are passed - i.e., as 1 and 0 or true and false and so on. I’m pulling that from memory without checking how it actually works.

There’s something odd going on with the --mem portion as after adding the the args script, sbatch keeps giving the following in OOD:

sbatch: error: Invalid --mem specification

The job_script_options.json file from the refused job shows the following when the m_exclusive checkbox is checked:

"native": [
    "-J",
    "worker",
    "-N",
    "1",
    "--mem",
    "G",
    "-c",
    "",
    "-G",
    ""

It looks like it’s still passing through the hidden options?

:man_facepalming: yes it seems like you need extra logic there if m_exclusive == 1

I wrote out the following:

script:
  native:
    - "-J"
    - "<%= m_name %>"
    - "-N"
    - "1"
    <%- if m_exclusive == true %>
    - "--exclusive"
    <%- else %>
    - "--mem"
    - "<%= m_mem %>G"
    - "-G"
    - <%= m_gpus %>
    - "-c"
    - <%= m_cpus %>
    <%- end %>

Used your script as inspiration and it seems to be working fine!

EDIT: I swapped it for the following and it seems to work better, although still not very cleanly:

script:
  native:
    - "-J"
    - "<%= m_name %>"
    - "-N"
    - "1"
  <%- if m_exclusive = 1 %>
    - "--exclusive"
  <%- end %>
  <%- if m_exclusive = 0 %>
    - "--mem"
    - "<%= m_mem %>G"
    - "-G"
    - <%= m_gpus %>
    - "-c"
    - <%= m_cpus %>
  <%- end %>

@jeff.ohrstrom Turns out the above doesn’t actually work. If you previously clicked the m_exclusive button, it still keeps the --exclusive in the job script options.

Example:

"native": [
    "-J",
    "worker",
    "-N",
    "1",
    "--exclusive",
    "--mem",
    "160G",
    "-G",
    1,
    "-c",
    32
  ]

It should be removing the --exclusive if unchecked, right?

One single = is the assignment operator. You’re assigning m_exclusive to 0 then evaluating that result as a boolean.

You need the equality operator ==.

1 Like