Creating job with cryosparc-tools fails

I’m trying to use cryosparc-tools to create and queue a new job, but it’s not working.

This is what I run:

cs = CryoSPARC(
            license=csparc_license,
            email=csparc_email,
            password=csparc_password,
            host=host,
            base_port=base_port)

project =  cs.find_project(config['project_options']['project_uid'])
workspace = project.create_workspace(config['project_options']['workspace_name'])

import_job = workspace.create_job(
            type="import_movies",
            params=config['preprocessing']['import_movies'] )

config is a simple dictionary containing the job parameters. Regardless of whether I set the job parameters or not, I get the following error:

Traceback (most recent call last):
  File "/home/ubuntu/repos/cryo_flows/basic_workflow.py", line 67, in <module>
    main(parser.parse_args())
  File "/home/ubuntu/repos/cryo_flows/basic_workflow.py", line 56, in main
    preprocessing(cs, config)
  File "/home/ubuntu/repos/cryo_flows/basic_workflow.py", line 41, in preprocessing
    import_job = workspace.create_job(
  File "/opt/conda/envs/pyem/lib/python3.9/site-packages/cryosparc/workspace.py", line 89, in create_job
    return self.cs.create_job(
  File "/opt/conda/envs/pyem/lib/python3.9/site-packages/cryosparc/tools.py", line 344, in create_job
    job_uid: str = self.cli.create_new_job(  # type: ignore
  File "/opt/conda/envs/pyem/lib/python3.9/site-packages/cryosparc/command.py", line 112, in func
    assert "error" not in res, f'Error for "{key}" with params {params}:\n' + format_server_error(res["error"])
AssertionError: Error for "create_new_job" with params {'job_type': 'import_movies', 'project_uid': 'P3', 'workspace_uid': 'W16', 'title': None, 'desc': None}:
ServerError: create_new_job() missing 1 required positional argument: 'created_by_user_id'
Traceback (most recent call last):
  File "/home/ubuntu/cryosparc/cryosparc_master/cryosparc_command/commandcommon.py", line 200, in wrapper
    res = func(*args, **kwargs)
  File "/home/ubuntu/cryosparc/cryosparc_master/cryosparc_command/commandcommon.py", line 266, in wrapper
    return func(*args, **kwargs)
TypeError: create_new_job() missing 1 required positional argument: 'created_by_user_id'

It does correctly find the project and generate a workspace that I can interact with in the web interface, but the job is obviously not created. I also get a very similar error if I try to create other jobs: I tried the homo_abinit job as listed in the cryosparc-tools documentation. I am running cryosparc v4.1.1.

Is this a bug?

Extra sleuthing here makes me think this is a bug in cryosparc-tools:

The create_new_job function at line 5589 in /home/ubuntu/cryosparc/cryosparc_master/cryosparc_command/command_core/__init__.py requires the parameter created_by_user_id:

@extern
@validate(['job_type', 'project_uid'], instance_locked=True, stop_if_read_only=True)
def create_new_job(job_type, project_uid, workspace_uid,
                  created_by_user_id,
                  created_by_job_uid=None,
                  title=None,
                  desc=None,
                  do_layout=True,
                  dry_run=False,
                  enable_bench=False,
                  priority=None):

However, for some reason the create_new_job function in cryosparc-tools does not include created_by_user_id (cryosparc-tools/tools.py at develop · cryoem-uoft/cryosparc-tools · GitHub, line 356) when it calls the cli:

 job_uid: str = self.cli.create_new_job(  # type: ignore
            job_type=type, project_uid=project_uid, workspace_uid=workspace_uid, title=title, desc=desc
        )

In contrast, the cryosparc-tools function for creating a workspace DOES provide the created_by_job_uid parameter, which would explain why I’m able to make new workspaces.

workspace_uid: str = self.cli.create_empty_workspace(  # type: ignore
            project_uid=project_uid, created_by_user_id=self.user_id, title=title, desc=desc
        )

Temporary solution:
I modified this line in the cryosparc/tools.py file to:

job_uid: str = self.cli.create_new_job(  # type: ignore
            job_type=type, project_uid=project_uid,
            workspace_uid=workspace_uid, created_by_user_id=self.user_id, title=title, desc=desc
        )

and now I can submit jobs just fine. It’d be great to get this fixed in the repo.

Hi @epalovcak, thanks for reporting this, yes this is a bug and it has now been fixed in the latest version of cryosparc-tools. Please update with the following command

pip install -U cryosparc-tools

Thanks and let me know if you run into any more trouble.

This is fixed now! Thank you!!