Hi,
I’m trying to customize DupeFinder, but it doesn’t work.
I wrote the following script.
my_fw_for_test.py
from fireworks import explicit_serialize, FiretaskBase, FWAction, Firework
from fireworks.features.dupefinder import DupeFinderBase
path = ["/home/taka/test_duplicate_check"] # directory where script exists
@explicit_serialize
class DoNothingTask(FiretaskBase):
required_params = [“name”]
def run_task(self, fw_spec):
return FWAction()
class ValueDupeFinder(DupeFinderBase):
_fw_name = ‘ValueDupeFinder’
def verify(self, spec1, spec2):
"""
Method that checks whether two specs are identical enough to be considered duplicates.
Return true if duplicated.
Args:
spec1 (dict)
spec2 (dict)
Returns:
bool
"""
return abs(spec1["value"] - spec2["value"]) < 10
def query(self, spec):
"""
Given a spec, returns a database query that gives potential candidates for duplicated Fireworks.
Args:
spec (dict): spec to check for duplicates
"""
return {"$and": [{"launches": {"$ne": []}}, {"spec": spec}]}
class DupTestFW(Firework):
_fw_name = “FirstFW”
def init(self, value, parents=None):
self._task = [DoNothingTask(name="nothing")]
super().__init__(self._task, parents=parents, name=self._fw_name,
spec={"_dupefinder": ValueDupeFinder(),
"value": value})
``
main.py
from future import division, unicode_literals, print_function
``
import sys
from fireworks import LaunchPad, Workflow
from my_fw_for_test import DupTestFW
lpad = LaunchPad.auto_load()
def add_wf(name):
first = DupTestFW(value=float(sys.argv[1]))
wf = Workflow([first], name=name)
lpad.add_wf(wf)
if name == “main”:
add_wf(“test_duplicate_check”)
I executed command as following:
lpad reset
python main.py 0 && rlaunch singleshot
python main.py 5 && rlaunch singleshot
python main.py 100 && rlaunch singleshot
``
I expect that my ValueDupeFinder regard only the second FW as duplicated FW.
However, actually neither the second nor third FW are regarded as duplicated FW by ValueDupeFinder.
I also try rewrite ValueDupeFinder.query as
return {"$and": [{“launches”: {"$ne": []}}]}
``
, then both of the second and third FW are regarded as duplicated FW by ValueDupeFinder. (I did “lpad reset” at the first.)
I read the code of _steal_launches method of fireworks.core.launchpad.py.
It seems that DupeFinder.verify is not called, then I think all matched FW by “query” will be regarded as duplicated.
Or, did I do something wrong?
I will appreciate any advice and help.
Thanks,
Akira Takahashi