Skip to content

Restriction lambda containing captured variables do not work #348

@stijnh

Description

@stijnh

It seems that the following restriction:

n = 1024 * 1024 * 64
restrictions = [
    lambda p: n % calculate_chunk(p["vecsize"], p["nthreads"]) == 0,
]

tune_kernel("vector_add", kernel_string, size, args, tune_params, answer=answer, restrictions=restrictions)

Gives the following error:

  File "constraint/problem.py", line 249, in constraint.problem.Problem.getSolutionsAsListDict
  File "constraint/problem.py", line 239, in constraint.problem.Problem.getSolutionsOrderedList
  File "constraint/problem.py", line 214, in constraint.problem.Problem.getSolutions
  File "constraint/solvers.py", line 404, in constraint.solvers.OptimizedBacktrackingSolver.getSolutions
  File "constraint/solvers.py", line 392, in constraint.solvers.OptimizedBacktrackingSolver.getSolutionsList
  File "constraint/constraints.py", line 188, in constraint.constraints.FunctionConstraint.__call__
  File "<string>", line 1, in r
NameError: name 'n' is not defined

Additionally, the following restriction:

restrictions = [
    lambda p: n % calculate_chunk(p) == 0
]

Results in the following error:

  File "constraint/problem.py", line 249, in constraint.problem.Problem.getSolutionsAsListDict
  File "constraint/problem.py", line 239, in constraint.problem.Problem.getSolutionsOrderedList
  File "constraint/problem.py", line 214, in constraint.problem.Problem.getSolutions
  File "constraint/solvers.py", line 404, in constraint.solvers.OptimizedBacktrackingSolver.getSolutions
  File "constraint/solvers.py", line 392, in constraint.solvers.OptimizedBacktrackingSolver.getSolutionsList
  File "constraint/constraints.py", line 188, in constraint.constraints.FunctionConstraint.__call__
TypeError: r() takes 0 positional arguments but 2 were given

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions