luigi学习6--parameters详解
parameter就好比是一个task的构造方法。luigi要求你在类的scope上定义parameter。
如下面就是一个定义parameter的例子:
class DailyReport(luigi.contrib.hadoop.JobTask):
date = luigi.DateParameter(default=datetime.date.today())
# ...
对于上述的parameter你可以使用这样的方式来初始化:
DailyReport(datetime.date(2012,5,10))或者仅仅使用DailyReport(),如果不提供参数,那么parameter的值就是默认值。
luigi也提供了一个命令行转换器,你调用这个job的时候,可以通过--date 2012-15-10的方式来初始化parameter
一、Instance caching
task被他们的class和参数的值所区分。实际上,在一个worker中,两个task如果class相同,并且parameter的值也相同,那么这两个task不但equal,并且就是same instance:
>>> import luigi
>>> import datetime
>>> class DateTask(luigi.Task):
... date = luigi.DateParameter()
...
>>> a = datetime.date(2014, 1, 21)
>>> b = datetime.date(2014, 1, 21)
>>> a is b
False
>>> c = DateTask(date=a)
>>> d = DateTask(date=b)
>>> c
DateTask(date=2014-01-21)
>>> d
DateTask(date=2014-01-21)
>>> c is d
True
二、无关要紧的参数
不明白这种参数用在什么地方,这是官网的叙述:
If a parameter is created with significant=False, it is ignored as far as the Task signature is concerned. Tasks created with only insignificant parameters differing have the same signature but are not the same instance:
>>> class DateTask2(DateTask):
... other = luigi.Parameter(significant=False)
...
>>> c = DateTask2(date=a, other="foo")
>>> d = DateTask2(date=b, other="bar")
>>> c
DateTask2(date=2014-01-21)
>>> d
DateTask2(date=2014-01-21)
>>> c.other
'foo'
>>> d.other
'bar'
>>> c is d
False
>>> hash(c) == hash(d)
True
三、parameter的类型
在上面的例子中,用的都是Parameter的子类,这些子类包括DateParameter,DateIntervalParameter,IntParameter,FloatParameter等等。
python不是一个静态类型的语言,你不需要指定参数的类型,你可以直接使用基类Parameter
你使用DateParameter的原因只是因为luigi需要把命令行转化Wie正确的类型而已。
四、为其他的classes设置parameter的值
所有的parameter都被暴漏在类级别上了,你可以通过命令行来赋值,假如你有class TaskA和TaskB:
class TaskA(luigi.Task):
x = luigi.Parameter() class TaskB(luigi.Task):
y = luigi.Parameter()
你可以运行taskB在命令行上通过:luigi TaskB --y 42
但是你也可以同时设置TaskA的参数:luigi TaskB --y 42 --TaskA-x 43
当然还有一种方式是写在配置文件中,你可以这么写:
[TaskA]
x:
五、parameter的设置优先级
从上往下优先级降低,高优先级的可以覆盖低优先级的值:
1.通过构造方法设置值的,或者是在命令行上设置值的(task级别的)。
2.命令行设置值(类级别)
3.配置文件中设置值
4.默认值
luigi学习6--parameters详解的更多相关文章
- 跟我学机器视觉-HALCON学习例程中文详解-测量圆环脚宽间距
跟我学机器视觉-HALCON学习例程中文详解-测量圆环脚宽间距 This example program demonstrates the basic usage of a circular meas ...
- 跟我学机器视觉-HALCON学习例程中文详解-IC引脚测量
跟我学机器视觉-HALCON学习例程中文详解-IC引脚测量 Lead Measurement: Example for the application of the measure object in ...
- iOS学习之UINavigationController详解与使用(一)添加UIBarButtonItem
http://blog.csdn.net/totogo2010/article/details/7681879 1.UINavigationController导航控制器如何使用 UINavigati ...
- [转]iOS学习之UINavigationController详解与使用(三)ToolBar
转载地址:http://blog.csdn.net/totogo2010/article/details/7682641 iOS学习之UINavigationController详解与使用(二)页面切 ...
- [转]iOS学习之UINavigationController详解与使用(二)页面切换和segmentedController
转载地址:http://blog.csdn.net/totogo2010/article/details/7682433 iOS学习之UINavigationController详解与使用(一)添加U ...
- 各大公司广泛使用的在线学习算法FTRL详解
各大公司广泛使用的在线学习算法FTRL详解 现在做在线学习和CTR常常会用到逻辑回归( Logistic Regression),而传统的批量(batch)算法无法有效地处理超大规模的数据集和在线数据 ...
- 跟我学机器视觉-HALCON学习例程中文详解-FUZZY检测用于开关引脚测量
跟我学机器视觉-HALCON学习例程中文详解-FUZZY检测用于开关引脚测量 * This example program demonstrates the basic usage of a fuzz ...
- 跟我学机器视觉-HALCON学习例程中文详解-开关引脚测量
跟我学机器视觉-HALCON学习例程中文详解-开关引脚测量 This example program demonstrates the basic usage of a measure object. ...
- 跟我学机器视觉-HALCON学习例程中文详解-QQ摄像头读取条码
跟我学机器视觉-HALCON学习例程中文详解-QQ摄像头读取条码 第一步:插入QQ摄像头,安装好驱动(有的可能免驱动) 第二步:打开HDevelop,点击助手-打开新的Image Acquisitio ...
- 从51跳cortex-m0学习2——程序详解
跳cortex-m0——思想转变>之后又一入门级文章,在此不敢请老鸟们过目.不过要是老鸟们低头瞅了一眼,发现错误,还请教育之,那更是感激不尽.与Cortex在某些操作方式上的异同,让自己对Cor ...
随机推荐
- python 装饰器和 functools 模块
转自:http://blog.jkey.lu/2013/03/15/python-decorator-and-functools-module/ 什么是装饰器? 在 python 语言里第一次看到装饰 ...
- Mingyang.net:如何获取所有的请求参数?
第一种方法:用@RequestParam. @RequestMapping(params="m=update", method=RequestMethod.POST) public ...
- g++/gcc 链接头文件 库 PATH
转自http://blog.csdn.net/kankan231/article/details/24243871 在Linux下编译链接或运行c/c++程序时可能会遇到找不到头文件,找不到库文件的错 ...
- 软件测试—— junit 单元测试
Tasks: Install Junit(4.12), Hamcrest(1.3) with Eclipse Install Eclemma with Eclipse Write a java pro ...
- 【caffe-windows】 caffe-master 之 classfication_demo.m 超详细分析
classification_demo.m 是个很好的学习资料,了解这个代码之后,就能在matlab里用训练好的model对输入图像进行分类了,而且我在里边还学到了oversample的实例,终于了解 ...
- [AFUI]App Framework Plugins
---------------------------------------------------------------------------------------------------- ...
- 【LeetCode】15. 3Sum 三个数和为0
题目: Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find al ...
- php 数组转json格式
1.php若为关系数组:转化为由花括号包围的对象: 输入:$test = array("1"=>1,"2"=>2,"3"=> ...
- jar包程序 读取properties文件
String proFilePath = System.getProperty("user.dir") + "\\Mysettings.properties"; ...
- CLRS:Insert sort in in c
#include<stdio.h>#include<string.h>#include<stdlib.h>#include<time.h>#define ...