Error running `cryosparcm cluster validate` with custom variables

Current cryoSPARC version: v4.3.0+230816

We have a cluster template script that contains a custom ram_gb_multiplier variable as suggested here. This appears to cause the cryosparcm cluster validate command to fail:

$ cryosparcm cluster validate hpc --projects_dir /path/to/test
Validating cluster configuration for hpc
Using projects_dir /path/to/test
Submitting test script to cluster...
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/path/to/cryosparc_master/cryosparc_compute/cluster.py", line 72, in validate
    res = submit_cluster_script(target, cluster_script, template_args)
  File "/path/to//cryosparc_master/cryosparc_compute/cluster.py", line 150, in submit_cluster_script
    script = Template(cluster_script).render(template_args)
  File "/path/to/cryosparc_master/deps/anaconda/envs/cryosparc_master_env/lib/python3.8/site-packages/jinja2/environment.py", line 1090, in render
    self.environment.handle_exception()
  File "/path/to/cryosparc_master/deps/anaconda/envs/cryosparc_master_env/lib/python3.8/site-packages/jinja2/environment.py", line 832, in handle_exception
    reraise(*rewrite_traceback_stack(source=source))
  File "/path/to/cryosparc_master/deps/anaconda/envs/cryosparc_master_env/lib/python3.8/site-packages/jinja2/_compat.py", line 28, in reraise
    raise value.with_traceback(tb)
  File "<template>", line 48, in top-level template code
  File "/path/to/cryosparc_master/deps/anaconda/envs/cryosparc_master_env/lib/python3.8/site-packages/jinja2/filters.py", line 794, in do_float
    return float(value)
jinja2.exceptions.UndefinedError: 'ram_gb_multiplier' is undefined

Welcome to the forum @rgildea. This is a bug, which we will fix in a future release. Thanks for reporting.

[Update:] As a workaround, you can assign a default value for the case that a custom variable is undefined. For example, you can replace occurrences of
{{ ram_gb_multiplier }} with
{{ ram_gb_multiplier | default(1) }}
(details).
[Update 2023-08-23:] We plan to update the documentation with the need to define a custom variable’s default for compatibility with cluster validation.

1 Like

Thanks, I just came to a similar conclusion myself:

{%- set ram_gb_multiplier = ram_gb_multiplier|default(1) -%}

On a related note, it would be nice if there was a way to programatically set the default instance-level custom variables without having to define them via the UI admin panel, such that the cluster configuration was self-contained via cryosparcm cluster connect.

You can define instance-wide cluster custom variables with a (currently undocumented) cli function like so:

cryosparcm cli "set_cluster_configuration_custom_vars({'ram_gb_multiplier': 1, 'instance_test_var': 'instance_test_value'})"

Note that this command would overwrite all previously defined instance-wide cluster custom variables.
Similarly, a specific job’s custom variables can be overwritten after the job’s creation with a command like

cryosparcm cli "set_cluster_job_custom_vars('P1234', 'J56', {'ram_gb_multiplier': 1, 'instance_test_var': 'instance_test_value'})"
1 Like