Examples: query, "exact match", wildcard*, wild?ard, wild*rd
Fuzzy search: cake~ (finds cakes, bake)
Term boost: "red velvet"^4, chocolate^2
Field grouping: tags:(+work -"fun-stuff")
Escaping: Escape characters +-&|!(){}[]^"~*?:\ with \, e.g. \+
Range search: properties.timestamp:[1587729413488 TO *] (inclusive), properties.title:{A TO Z}(excluding A and Z)
Combinations: chocolate AND vanilla, chocolate OR vanilla, (chocolate OR vanilla) NOT "vanilla pudding"
Field search: properties.title:"The Title" AND text
Answered
Hi There

Hi there 🙂
Task.get_parameters() returns an empty dict from within a trains-agent task being executed. When I execute it outside, it works properly. Is it intended? How can I retrieve the parameters from within the trains-agent task?

  
  
Posted 4 years ago
Votes Newest

Answers 30


Also, for a single parameter you can use:
cloned_task.set_parameter(name="Args/artifact_name", value="test-artifact", description="my help text that will appear in the UI next to the value")This way, you are not overwriting the other parameters, you are adding to them.
(Similar to update_parameters , only for a single parameter)

  
  
Posted 4 years ago

Thanks !!!

  
  
Posted 4 years ago

Also, we added Task.update_task, a nicer way to change the script section 🙂

  
  
Posted 4 years ago

More context:
trains, trains-agent and trains-server all 0.16 Session.api_version -> 2.9 (both when executed in trains-agent and in local script)

  
  
Posted 4 years ago

basically:
` from trains import Task

task = Task.init("test", "test", "controller")
task.upload_artifact("test-artifact", dict(foo="bar"))
cloned_task = Task.clone(task, name="test", parent=task.task_id)
cloned_task.data.script.entry_point = "test_task_b.py"
cloned_task._update_script(cloned_task.data.script)
cloned_task.set_parameters(**{"artifact_name": "test-artifact"})
Task.enqueue(cloned_task, queue_name="default") `

  
  
Posted 4 years ago

AgitatedDove14 I cannot confirm at 100%, the context is different (see previous messages) but it could be the same bug behind the scene...

  
  
Posted 4 years ago

Okay, I think I understand, but missing something. It seems you call get_parameters from old API , is your code actually calling get_parameters ? The trains-agent runs the code externally, whatever happens inside the agent should have now effect on the code. So who exactly is calling the task.get_parameters, and well, why ? :)

  
  
Posted 4 years ago

I just read, I do have the trains version 0.16 and the experiment is created with that version

  
  
Posted 4 years ago

when you clone the Task, it might be before it is done syncying git / packages.
Also, since you are using 0.16 you have to have a section name (Args or General etc.)
How will task b use the parameters ? (argparser / connect dict?)

  
  
Posted 4 years ago

btw task._get_task_property('hyperparams') also gives me ValueError: Task has no hyperparams section defined

  
  
Posted 4 years ago

Thanks for your inputs, I will try that! For completion, here is how I retrieve the parameters:
` from trains import Task

task = Task.init("test", "test")
parent_task = Task.get_task(task.parent)
task.get_logger().report_text(task.get_parameters())
artifact_name = task.get_parameter("General/artifact_name")
artifact = parent_task.artifacts[artifact_name].get() `

  
  
Posted 4 years ago

Hmmm that is odd... based on the reply "'Task' object has no attribute 'hyperparams'", I would assume API version is lower then 2.9. But you specifically said you see Session.api_version == 2.9 is that correct?

  
  
Posted 4 years ago

Yes this is correct. I am trying to create a minimal reproducable example

  
  
Posted 4 years ago

JitteryCoyote63 do you have an idea on how I can reproduce it?

  
  
Posted 4 years ago

Please wait a few mins - This example is not valid, I will share a new one soon

  
  
Posted 4 years ago

😞

  
  
Posted 4 years ago

Yes, in the Task being executed in the agents, I have:
from trains import Task task = Task.init(...) task.get_logger().report_text(str(task.get_parameters()))

  
  
Posted 4 years ago

set a parameter in that task and enqueue it

how do you do that?

  
  
Posted 4 years ago

What is weird is:
Executing the task from an agent: task.get_parameters() returns an empty dict Calling task.get_parameters() from a local standalone script returns the correct properties, as shown in web UI, even if I updated them in UI.So I guess the problem comes from trains-agent?

  
  
Posted 4 years ago

So in my minimal reproducable example, it does work 🤣 very frustrating, I will continue searching for that nasty bug

  
  
Posted 4 years ago

Here is the minimal reproducable example.
Run test_task_a.py - It will register a dummy artifact, create a new task, set a parameter in that task and enqueue it test_task_b will try to retrieve parameter from parent task and fail

  
  
Posted 4 years ago

or "General/artifact_name" (if you are connecting it to a dict)

  
  
Posted 4 years ago

As to why: This is part of the piping that I described in a previous message: Task B requires an artifact from task A, so I pass the name of the artifact as a parameter of task B, so that B knows what artifact from A it should retrieve

  
  
Posted 4 years ago

JitteryCoyote63 is it the same issue?

  
  
Posted 4 years ago

Also tried task.get_logger().report_text(str(task.data.hyperparams))
-> AttributeError: 'Task' object has no attribute 'hyperparams'

  
  
Posted 4 years ago

I think I know what the prob is

  
  
Posted 4 years ago

JitteryCoyote63 try to add the prefix to the parameter name, e.g. instead of "artifact_name" use "Args/artifact_name"

  
  
Posted 4 years ago

task._wait_for_repo_detection()You can use the above, to wait until repository & packages are detected
(If this is something users need, we should probably make it a "public function" )

  
  
Posted 4 years ago