Ticket #9153 (assigned)

Opened 7 years ago

Last modified 5 years ago

Review Algorithm Property Defaults

Reported by: Peter Parker Owned by: Nick Draper
Priority: minor Milestone: Release 3.5
Component: Framework Keywords:
Cc: Blocked By:
Blocking: Tester:

Description

The "Properties" tables generated by WikiMaker expose the fact that for some algorithms we are using rather user-unfriendly conventions to denote various default values.

Examples:

  • There are 78 algorithms that use -1. Presumably, there will be some fraction of these where -1 is an acceptable value that can be used by the algorithm, but in most cases they are associated with a "must-be-positive" validator. Andrei has suggested that using -DBL_MAX in such cases might be a viable alternative.
  • -1.0 is used by an algorithm to denote an unspecified, default stop time.
  • There are 5 algorithms that use -0 as a default.

This problem has become more visible since #2480, which populates algorithm dialogs with default values.

A solution to this problem would make documentation a lot clearer, and would hopefully make algorithms easier to understand and use.

Change History

comment:1 Changed 7 years ago by Peter Parker

I offer up the following script to the eventual owner of this ticket, as a quick way to see which algorithms use which default values:

def get_all_prop_defaults():
        """Get prop default information in a form we can use."""
        prop_defaults = {}
        for alg_name in AlgorithmFactory.getRegisteredAlgorithms(True).keys():
                alg = AlgorithmManager.create(alg_name)
                for prop_name in alg.orderedProperties():
                        prop = alg.getProperty(prop_name)
                        if prop.getDefault in prop_defaults:
                                prop_defaults[prop.getDefault][0] += 1
                                prop_defaults[prop.getDefault][1].append(str(alg))
                        else:
                                prop_defaults[prop.getDefault] = [1, [str(alg)], prop_name]
        return prop_defaults

def print_default_usage_table():
        """Prints a table of all default values, how many times they are used, and an example algorithm
        that uses it."""
        table = [["#", "Default", "Example Algorithm"]]
        
        prop_defaults = get_all_prop_defaults()
        for prop_default in sorted(prop_defaults.keys()):
                table.append([
                        prop_defaults[prop_default][0],
                        prop_default,
                        prop_defaults[prop_default][1]])
        
        row_format ="{:>5} | {:<35} | {:<50}"
        for row in table:
                print row_format.format(*row)

def print_all_algs_that_use_default_value(default_str):
        """For a given default value, print the names of all the algorithms that have
        properties that use it."""
        prop_defaults = get_all_prop_defaults()
        
        try:
                algs = prop_defaults[default_str][1]
        except:
                print "No properties exist with a default value of %s." % default_str
        else:
                print "The following algorithms contain a property with default value of %s:" % default_str
                for alg in algs:
                        print alg
                print

# Uncomment to use:
# print_all_algs_that_use_default_value("#")
# print_default_usage_table()

Last edited 7 years ago by Peter Parker (previous) (diff)

comment:2 Changed 7 years ago by Nick Draper

  • Status changed from new to assigned
  • Owner set to Nick Draper
  • Milestone changed from Backlog to Release 3.2

comment:3 Changed 6 years ago by Nick Draper

  • Milestone changed from Release 3.2 to Release 3.3

comment:4 Changed 6 years ago by Nick Draper

  • Milestone changed from Release 3.3 to Release 3.4

comment:5 Changed 5 years ago by Nick Draper

  • Milestone changed from Release 3.4 to Release 3.5

Moved to R3.5 at the R3.4 code freeze

comment:6 Changed 5 years ago by Stuart Campbell

This ticket has been transferred to github issue 9996

Note: See TracTickets for help on using tickets.