1/22/2024 0 Comments Instal the new for mac FiretaskWhen executing run_task(), the AdditionTask we defined first reads the input_array parameter of the Firework’s spec. It can take in a Firework specification ( spec) in order to modify its behavior. The run_task() method is a special method name that gets called when the task is run. If we did not set this ourselves, the default would have been fireworks:AdditionTask (the root module name plus the class name separated by a colon). This parameter sets what this Firetask will be called by the outside world and is used to bootstrap the object, as described in the previous section. In the class definition, we are extending FiretaskBase to tell FireWorks that this is a Firetask.Ī special parameter named _fw_name is set to Addition Task. When the Firetask is done executing, it returns a FWAction object that can modify the workflow (or continue as usual) and pass information to downstream FireWorks.Ĭlass AdditionTask ( FiretaskBase ): _fw_name = "Addition Task" def run_task ( self, fw_spec ): input_array = fw_spec m_sum = sum ( input_array ) print ( f "The sum of ])Ī few notes about what’s going on (things will be clearer after the next step): FireWorks passes in the entire spec to the run_task method the run_task method can therefore modify its behavior based on any input data present in the spec, or by detecting previous or future tasks in the spec. Specifically, we execute the run_task method which must be implemented for every Firetask. In the third step, we execute the code of the Firetask we loaded. You will just need to define what Python packages to search for your custom Firetasks, or use a special format that allows for direct loading of classes. If you want to place your Firetasks in a package outside of FireWorks, please read the FireWorks configuration tutorial. You can write code for custom Firetasks anywhere in the user_packages directory of FireWorks, and it will automatically be discovered. The ScriptTask is just one type of Firetask that’s built into FireWorks to help you run scripts easily. When we set a _fw_name of ScriptTask in the previous examples, FireWorks was loading a Python object with a _fw_name class variable set to ScriptTask (and passing the script parameter to its constructor). It does this by searching a list of Python packages for Python objects that have a value of _fw_name that match your setting. In the second step, FireWorks dynamically loads Python objects based on your specified _tasks. So far, we haven’t seen an example of this the only information we gave in the spec in the previous examples was within the _tasks section. The spec also allows you to define arbitrary JSON data (labeled input in the diagram) to pass into your Firetasks as input. There is a section that contains your Firetasks (one or many), as we saw in the previous examples. The first step of the image just shows how the spec section of the Firework is structured. We’ll be creating a custom Firetask that adds one or more numbers using Python’s sum() function, and later building workflows using this (and similar) Firetasks.īefore diving into an example of custom Firetask, it is worth understanding how FireWorks is bootstrapping jobs based on your specification. A custom Firetask gives you more control over your jobs, clarifies the usage of your code, and guards against unintended behavior by restricting the commands that can be executed.Įven if you plan to only use the built-in tasks, we suggest that you still read through the next portion before continuing with the tutorial. However, if you are comfortable with some basic Python, you can define your own custom Firetasks for the codes you run. ScriptTask also has many additional features that are covered in the ScriptTask tutorial. In fact, they might be all you need! In particular, because the ScriptTask can run arbitrary shell scripts, it can in theory run any type of computation and is an ‘all-encompassing’ Firetask. The TemplateWriterTask, ScriptTask, FileTransferTask are built-into FireWorks and can be used to perform useful operations.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |