I am using vertex ai's python SDK and it's built on top of Kubeflow pipelines. In it, you supposedly can do this:
train_op = (sklearn_classification_train(
train_data = data_op.outputs['train_out']
).
set_cpu_limit(training_cpu_limit).
set_memory_limit(training_memory_limit).
add_node_selector_constraint(training_node_selector).
set_gpu_limit(training_gpu_limit)
)
where you can add these functions (set_cpu_limit, set_memory_limit, add_node_selector, and set_gpu_limit) onto your component. I've haven't used this syntax before.
How I can optionally use each 'sub function' only if the variables are specified each function?
For example, if training_gpu_limit isn't set, I don't want to execute set_gpu_limit on the component.
These functions are not appended to the function, but to the component.
In your code, if you do print(type(train_op)) it will be an object type component. So there is no way to add parameters to the function which will influence behavior of the component.
You can do it in pipeline function by changing code to:
train_op = sklearn_classification_train(train_data = data_op.outputs['train_out'])
if training_cpu_limit:
train_op.set_cpu_limit(training_cpu_limit)
# etc
Related
Context: I'm implementing a Jenkins Pipeline. For this, in order to define the pipeline's parameters I implemented the DSL file.
In the DSL file, I have a parameter of ActiveChoiceParam type, called ORDERS. This parameter will allow me to choose one or more orders numbers at the same time.
Problem: What I want to do is to set the values that gets rendered for ORDERS parameter from a custom library. Basically I have a directory my_libraries with a file, orders.groovy. In this file, there is an order class, with a references list property that contains my values.
The code in the DSL file is as follows:
def order = new my_libraries.order()
pipelineJob("111_name_of_pipeline") {
description("pipeline_description")
keepDependencies(false)
parameters {
stringParam("BRANCH", "master", "The branch")
activeChoiceParam("ORDERS") {
description("orders references")
choiceType('CHECKBOX')
groovyScript{
script("return order.references")
fallbackScript("return ['error']")
}
}
}
}
Also, is good to mention that my custom library works well. For example, if I choose to use a ChoiceParam as below, it works, but of course, is not the behaviour I want. I want to select multiple choices.
choiceParam("ORDERS", order.references, "Orders references list but single-choice")
How can I make order.references available in the script part of groovyScript?
I've tried using global instance of order class, instantiate the class directly in the groovyScript, but no positive result.
I want to use point picker to pick (get) coordinates of my points in a point cloud. That is why I want to set QPickingSettings to PointPicking but it seems that cannot be done. Events sent to method mouse_event are of type QPickEvent and NOT QPickPointEvent. What am I doing wrong?
self.picker = Qt3DRender.QObjectPicker(self)
picking_settings = Qt3DRender.QPickingSettings(self.picker)
picking_settings.setFaceOrientationPickingMode(
Qt3DRender.QPickingSettings.FrontAndBackFace)
# set QObjectPicker to PointPicking:
picking_settings.setPickMethod(
Qt3DRender.QPickingSettings.PointPicking)
picking_settings.setPickResultMode(
Qt3DRender.QPickingSettings.NearestPick)
picking_settings.setWorldSpaceTolerance(.5)
self.picker.setHoverEnabled(True)
self.picker.setDragEnabled(True)
def mouse_event(e):
# do something
# e should be QPickPointEvent type
pass
self.picker.moved.connect(mouse_event)
self.picker.pressed.connect(mouse_event)
self.picker.clicked.connect(mouse_event)
self.picker.released.connect(mouse_event)
self.addComponent(self.picker)
I'm not familiar with the python API, but you should not create your own instance of QPickingSettings but use the one that exists as a property of the instance of QRenderSettings (that is a singleton).
If you're using the Qt3DWindow from Qt3DExtras, it will provide an accessor to the QRenderSettings instance.
Otherwise, you'll need to create an instance of QRenderSettings and add it as a component of an entity. By convention we tend to use the root of the scene graph.
I have a custom function which I want to call using builder object
def generate_action(target, source, env):
print "TRIDIP:::::::I am in"
return None
Now I created a builder
env['BUILDERS']['generateAction'] = Builder(action = generate_action)
action = env.generateAction()
As you see, I have not pass any arugument and I don't want to pass any argument for which my custom function generate_action() is not called. I want to call the function without any argument.
You have to call the Builder, specifying the result file you depend on as source. You can't leave the "target=" and "source=" parameters out at the same time, because SCons has to know where in the total build graph this step fits in. Your SConscript should look something like (untested, and from the top of my head):
# env = Environment()
env['BUILDERS']['generateAction'] = Builder(action = generate_action)
# creates your other result file
myResult = env.someOtherBuilder('out.foo', 'in.txt')
# calls your generate_action method
action = env.generateAction('dummy.txt', myResult)
Note, how this will always call your "generateAction" Builder, because the "dummy.txt" is never created, so the target is never up-to-date.
Finally, my guess is that this answer won't really help and lead you into more trouble. When people try to call custom methods at build time they're usually using SCons in a wrong way...most of the time because they don't have the correct mental model to understand how SCons works. You might want to read up on some basics in the UserGuide ( http://scons.org/doc/production/HTML/scons-user.html ) or ask your further questions on our User mailing list at scons-users#scons.org (see also http://scons.org/lists.php ).
I write module which will define new types. Inside newproperty definition I want to use custom function (also provided in this module) which will munge passed value:
Function
#lib/puppet/parser/functions/my_custom_function.rb
module Puppet::Parser::Functions
newfunction(:my_custom_function, :type => :rvalue) do |args|
...
end
end
Type
#lib/puppet/type/new_type.rb
Puppet::Type.newtype(:new_type) do
newparam(:name) do
munge do |value|
my_custom_function(value)
end
end
end
but I get undefined local variable or method when try use function in type like above.
I also don't have access to stdlib functions inside custom type, but these functions are available in manifest file.
Does someone can provide example how to execute custom function inside type definition especially in munge block?
Custom functions are parser functions, for use in your manifests only.
The type code is used by the agent only, which will not load parser functions while initializing resources.
You will have to duplicate your munging code. If this is not feasible, you may have to implement it in a custom Ruby library, and use that from both within your custom function and your type. The library will need to be installed on both masters and agents in this case.
You need to extract the code from your custom function into a separate location and then call that shared code from both your custom function and from your type/provider. You do not need to pull the code into a separate gem to do this, it is fairly easy to keep the code local to your module.
Put your own Ruby classes in the directory lib/puppet/util/ of your module. You should then be able to require 'puppet/util/my_class' from both your custom function and your type/provider. You can see an example of how I've done this in my module jboss-puppet_admin.
I have two sequence item class a_packet and its extended class called bad_packet.
By default, a_packet type is used.
Trying to override a_packet instance with bad_packet, I am able to do it successfully by using set_inst_override_by_name in my uvm test,
factory.set_inst_override_by_name("a_packet","bad_packet", "*");
Now my question is: what if I don't want to use "*", how to know the full hierarchical path of the sequence item instance?
I was trying to utilise get_full_name() from inside the sequence item, right after it is received by the driver, to know the exact hierarchical path. It displayed:
uvm_test_top.env.a_agt.a_seqr.a_sequence.a_packet
But when I replaced the * with above path, the overriding is not happening.
factory.set_inst_override_by_name("a_packet","bad_packet","uvm_test_top.env.a_agt.a_seqr.a_sequence.a_packet");
Did I do something wrong?
Where you create your packet, you'll need to to specify the full path to the corresponding call to create(..):
packet = a_packet::type_id::create("packet", , get_full_name());
If you were using the uvm_do macro, you'll have to change to using the explicit sequence API:
packet = a_packet::type_id::create("packet", , get_full_name());
start_item(packet);
// ... randomize ...
finish_item(packet);
Idea is from this DVCon Paper, section IV.A.