def env_parser(): parser = CTParser() parser.add_argument("--save_path", dest="save_path") parser.add_argument("--data_path", "--data_path", dest="data_path") parser.add_argument("--device", dest="device", default="cuda:0") parser.add_argument("--n_jobs", dest="n_jobs", default=1, type=int) _ = Cytomine._add_cytomine_cli_args(parser.parser) return parser
def env_parser(): parser = CTParser() parser.add_argument("--device", dest="device", default="cuda:0") parser.add_argument("--n_jobs", dest="n_jobs", default=1, type=int) return parser
# We add the `n` parameter with a default value of 0. def run(self, result, x, z, w, y=2, n=0, **parameters): import time from random import randint, normalvariate result["multiply"] = x * y # Simulate the effect of the new parameter: in this case we add # some gaussian noise to the computation of the sum result["sum"] = z + w + normalvariate(0, n) time.sleep(randint(1, 10)) if __name__ == "__main__": set_stdout_logging() parser = CTParser() environment, _ = parser.parse() param_set = ParameterSet() param_set.add_parameters(x=[1, 2, 3], z=4, w=[5, 6]) # Add the separator, the default value for what was computed previously and # the new parameter values # -- Separator (compare this to `004_adding_parameter_values.py`) param_set.add_separator(n=0) # Notice we pass the default value # -- new parameter values param_set.add_parameters(n=[0.01, 0.001]) experiment = Experiment("BasicUsage", param_set, MyComputation) environment.run(experiment)
""" Inherit from `Computation` and redefine the `run` method as you which """ def run(self, result, x, z, w, y=2, **parameters): import time from random import randint result["multiply"] = x * y result["sum"] = z + w time.sleep(randint(1, 10)) if __name__ == "__main__": set_stdout_logging() parser = CTParser() # Add custom argument to parser parser.add_argument("y", help="The value of the `y` parameter", type=int) environment, namespace = parser.parse() param_set = ParameterSet() # add `y` given in command line to parameter set param_set.add_parameters(x=[1, 2, 3], z=4, w=[5, 6], y=namespace.y) # Change the name of the computation according to the value of `y` # Note that this is mandatory. Otherwise, Clustertools cannot distinguish # between the two "sub" experiment exp_name = "BasicUsage_{}".format(namespace.y) print("This is experiment", exp_name)