What is the best way to pass an object to a FireTask and return

Hi AJ,

I am new to the FireWorks. I try to write a customized FireTask – InsLogTask and pass an object (options) through fw_spec. The FireTask class is:

from fireworks.core.firework import FireTaskBase, FWAction
from fireworks.utilities.fw_utilities import explicit_serialize
import re

@explicit_serialize
class InsLogTask(FireTaskBase):
    _fw_name = "InsLogTask"

    def run_task(self, fw_spec):
        options=fw_spec['opts']
        scrDir = options.scrDir
        logFile = scrDir + '/' + options.insaneLog

        memRe=re.compile("NDX Membrane")
        solRe=re.compile("NDX Solvent")

        with open(logFile, 'r') as f:
            for line in f:
                if(re.search(memRe, line)):
                    strs=line.split()
                    options.NDX_Mem_Beg=int(strs[3])
                    options.NDX_Mem_End=int(strs[4])

                if (re.search(solRe, line)):
                    strs = line.split()
                    options.NDX_Sol_Beg = int(strs[3])
                    options.NDX_Sol_End = int(strs[4])

        print options.NDX_Mem_Beg, options.NDX_Mem_End, options.NDX_Sol_Beg, options.NDX_Sol_End
        return FWAction()

The Options class is:

class Options(yaml.YAMLObject):
    yaml_tag = u'!Options'
    def __init__(self, cDir, log, gfile, sfile):
        self.curDir=None
        self.scrDir=None
        self.appDir=None
        self.NDX_Mem_Beg=None
        self.NDX_Mem_End=None
        self.NDX_Sol_Beg=None
        self.NDX_Sol_End=None

And it is called in the main function as:

fh=open(args.iFile)
options=yaml.load(fh)

fw = Firework(InsLogTask(), spec={'opts': options})

The error message:

···

=====================
2016-05-27 10:48:49,607 INFO RUNNING fw_id: 1 in directory: /Users/zhang30/workspace/PycharmProjects/fireworks/ras_wf/launcher_2016-05-27-17-48-49-513553
2016-05-27 10:48:49,610 INFO Task started: {{fireworks.user_objects.ras_objects.insLogExTask.InsLogTask}}.
Traceback (most recent call last):
File “/Users/zhang30/workspace/PycharmProjects/fireworks/fireworks/core/rocket.py”, line 213, in run
m_action = t.run_task(my_spec)
File “/Users/zhang30/workspace/PycharmProjects/fireworks/fireworks/user_objects/ras_objects/insLogExTask.py”, line 11, in run_task
scrDir = options.scrDir
AttributeError: ‘unicode’ object has no attribute ‘scrDir’
2016-05-27 10:48:49,699 INFO Rocket finished

Process finished with exit code 0

=====================

Do you how I can fix it? I try to pass the options into Fire task, update the options, and eventually return the updated options. Can you tell me how to do it?

Thank you!

Xiaohua Zhang

Hi Xiaohua

What is the type() of the options variable before you put it in the fw?

i.e. tell me what is type(options) and also options.class before you are putting it in the fw spec.

Best,

Anubhav

···

On Fri, May 27, 2016 at 11:09 AM, Xiaohua Zhang [email protected] wrote:

Hi AJ,

I am new to the FireWorks. I try to write a customized FireTask – InsLogTask and pass an object (options) through fw_spec. The FireTask class is:

from fireworks.core.firework import FireTaskBase, FWAction
from fireworks.utilities.fw_utilities import explicit_serialize
import re

@explicit_serialize
class InsLogTask(FireTaskBase):
    _fw_name = "InsLogTask"

    def run_task(self, fw_spec):
        options=fw_spec['opts']
        scrDir = options.scrDir
        logFile = scrDir + '/' + options.insaneLog

        memRe=re.compile("NDX Membrane")
        solRe=re.compile("NDX Solvent")

        with open(logFile, 'r') as f:
            for line in f:
                if(re.search(memRe, line)):
                    strs=line.split()
                    options.NDX_Mem_Beg=int(strs[3])
                    options.NDX_Mem_End=int(strs[4])

                if (re.search(solRe, line)):
                    strs = line.split()
                    options.NDX_Sol_Beg = int(strs[3])
                    options.NDX_Sol_End = int(strs[4])

        print options.NDX_Mem_Beg, options.NDX_Mem_End, options.NDX_Sol_Beg, options.NDX_Sol_End
        return FWAction()

The Options class is:

class Options(yaml.YAMLObject):
    yaml_tag = u'!Options'
    def __init__(self, cDir, log, gfile, sfile):
        self.curDir=None
        self.scrDir=None
        self.appDir=None
        self.NDX_Mem_Beg=None
        self.NDX_Mem_End=None
        self.NDX_Sol_Beg=None
        self.NDX_Sol_End=None

And it is called in the main function as:

fh=open(args.iFile)
options=yaml.load(fh)

fw = Firework(InsLogTask(), spec={'opts': options})

The error message:

2016-05-27 10:48:49,607 INFO RUNNING fw_id: 1 in directory: /Users/zhang30/workspace/PycharmProjects/fireworks/ras_wf/launcher_2016-05-27-17-48-49-513553
2016-05-27 10:48:49,610 INFO Task started: {{fireworks.user_objects.ras_objects.insLogExTask.InsLogTask}}.
Traceback (most recent call last):
File “/Users/zhang30/workspace/PycharmProjects/fireworks/fireworks/core/rocket.py”, line 213, in run
m_action = t.run_task(my_spec)
File “/Users/zhang30/workspace/PycharmProjects/fireworks/fireworks/user_objects/ras_objects/insLogExTask.py”, line 11, in run_task
scrDir = options.scrDir
AttributeError: ‘unicode’ object has no attribute ‘scrDir’
2016-05-27 10:48:49,699 INFO Rocket finished

Process finished with exit code 0

=====================

Do you how I can fix it? I try to pass the options into Fire task, update the options, and eventually return the updated options. Can you tell me how to do it?

Thank you!

Xiaohua Zhang

You received this message because you are subscribed to the Google Groups “fireworkflows” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

Visit this group at https://groups.google.com/group/fireworkflows.

To view this discussion on the web visit https://groups.google.com/d/msgid/fireworkflows/ddac304e-e3d0-4d0b-8261-6ae172639874%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Hi AJ,

Thank you for your prompt reply!

print type(options)
print options.__class__

yield the following output:

<class ‘main.Options’>
<class ‘main.Options’>

The Options class is a subclass derived from yaml.YAMLObject

Best,

Xiaohua Zhang

···

On Friday, May 27, 2016 at 11:50:40 AM UTC-7, ajain wrote:

Hi Xiaohua

What is the type() of the options variable before you put it in the fw?

i.e. tell me what is type(options) and also options.class before you are putting it in the fw spec.

Best,

Anubhav

On Fri, May 27, 2016 at 11:09 AM, Xiaohua Zhang [email protected] wrote:

Hi AJ,

I am new to the FireWorks. I try to write a customized FireTask – InsLogTask and pass an object (options) through fw_spec. The FireTask class is:

from fireworks.core.firework import FireTaskBase, FWAction
from fireworks.utilities.fw_utilities import explicit_serialize
import re

@explicit_serialize
class InsLogTask(FireTaskBase):
    _fw_name = "InsLogTask"

    def run_task(self, fw_spec):
        options=fw_spec['opts']
        scrDir = options.scrDir
        logFile = scrDir + '/' + options.insaneLog

        memRe=re.compile("NDX Membrane")
        solRe=re.compile("NDX Solvent")

        with open(logFile, 'r') as f:
            for line in f:
                if(re.search(memRe, line)):
                    strs=line.split()
                    options.NDX_Mem_Beg=int(strs[3])
                    options.NDX_Mem_End=int(strs[4])

                if (re.search(solRe, line)):
                    strs = line.split()
                    options.NDX_Sol_Beg = int(strs[3])
                    options.NDX_Sol_End = int(strs[4])

        print options.NDX_Mem_Beg, options.NDX_Mem_End, options.NDX_Sol_Beg, options.NDX_Sol_End
        return FWAction()

The Options class is:

class Options(yaml.YAMLObject):
    yaml_tag = u'!Options'
    def __init__(self, cDir, log, gfile, sfile):
        self.curDir=None
        self.scrDir=None
        self.appDir=None
        self.NDX_Mem_Beg=None
        self.NDX_Mem_End=None
        self.NDX_Sol_Beg=None
        self.NDX_Sol_End=None

And it is called in the main function as:

fh=open(args.iFile)
options=yaml.load(fh)

fw = Firework(InsLogTask(), spec={'opts': options})

The error message:

2016-05-27 10:48:49,607 INFO RUNNING fw_id: 1 in directory: /Users/zhang30/workspace/PycharmProjects/fireworks/ras_wf/launcher_2016-05-27-17-48-49-513553
2016-05-27 10:48:49,610 INFO Task started: {{fireworks.user_objects.ras_objects.insLogExTask.InsLogTask}}.
Traceback (most recent call last):
File “/Users/zhang30/workspace/PycharmProjects/fireworks/fireworks/core/rocket.py”, line 213, in run
m_action = t.run_task(my_spec)
File “/Users/zhang30/workspace/PycharmProjects/fireworks/fireworks/user_objects/ras_objects/insLogExTask.py”, line 11, in run_task
scrDir = options.scrDir
AttributeError: ‘unicode’ object has no attribute ‘scrDir’
2016-05-27 10:48:49,699 INFO Rocket finished

Process finished with exit code 0

=====================

Do you how I can fix it? I try to pass the options into Fire task, update the options, and eventually return the updated options. Can you tell me how to do it?

Thank you!

Xiaohua Zhang

You received this message because you are subscribed to the Google Groups “fireworkflows” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

Visit this group at https://groups.google.com/group/fireworkflows.

To view this discussion on the web visit https://groups.google.com/d/msgid/fireworkflows/ddac304e-e3d0-4d0b-8261-6ae172639874%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.