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

Python error in dynamic resource allocation #1

Open
nathanhaigh opened this issue Feb 13, 2019 · 0 comments
Open

Python error in dynamic resource allocation #1

nathanhaigh opened this issue Feb 13, 2019 · 0 comments

Comments

@nathanhaigh
Copy link
Owner

The lambda function shown to provide a dynamic allocation of resources (time/mem) using the input file sizes may not work as documented.

The corresponding bit of the code is things line for f in input['index'] in the lambda function specified in the resource keyword sections. This is because Python expects this to be a list/array of 1 or more values. However, if the index file specified in the input of the rule is a single quoted string this will fail.

For example, this will fail:

rule myrule :
	input: index = "some_index_file",
	output:    ...
	resources:
		mem_mb = lambda wildcards, input, attempt: math.ceil( sum(os.path.getsize(f) for f in input['index'] if os.path.isfile(f)) / 1024**2*(1+(attempt-1)/10)),
	shell:     ...

Either of the following two solutions will work:

  1. Making the index in the input an array
rule myrule :
	input: index = [ "some_index_file" ],
	output:    ...
	resources:
		mem_mb = lambda wildcards, input, attempt: math.ceil( sum(os.path.getsize(f) for f in input['index'] if os.path.isfile(f)) / 1024**2*(1+(attempt-1)/10)),
	shell:     ...
  1. Coerce the object in the lambda function into an array
rule myrule :
	input: index = "some_index_file",
	output:    ...
	resources:
		mem_mb = lambda wildcards, input, attempt: math.ceil( sum(os.path.getsize(f) for f in [input['index']] if os.path.isfile(f)) / 1024**2*(1+(attempt-1)/10)),
	shell:     ...
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

No branches or pull requests

1 participant