Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion tada/perf_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
current_experiment_name = configuration.get_experiment_name(
tada_configuration_dict, chosen_size
)
doubling_strategy = configuration.get_doubling_strategy(tada_configuration_dict)
# set the name of the experiment for perf
runner.metadata[constants.DESCRIPTION_METANAME] = current_experiment_name
# read the chosen types
Expand Down Expand Up @@ -69,7 +70,7 @@
position = configuration.get_position(tada_configuration_dict)
# generate data
data = generate.generate_data(
func_type, chosen_size, level, position, path, gen_func
func_type, chosen_size, level, position, path, gen_func, doubling_strategy
)
# run benchmark
if configuration.get_sortinput(tada_configuration_dict):
Expand Down
3 changes: 2 additions & 1 deletion tada/tada_a_bigoh.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,10 @@ def tada(tada_arguments): # noqa: C901
meanlastround = mean
current_runningtime = time.time() - start_time
if current_runningtime > tada_arguments.runningtime:
runtime_str = str(current_runningtime)
dis.output_message(
"\nQuit due to exceeding the max time limit: "
+ current_runningtime,
+ runtime_str,
to_print,
)
constants.QUIT_BY_MAX_RUNTIME = 1
Expand Down
7 changes: 7 additions & 0 deletions tada/util/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@ def parse(args: List[str]) -> Namespace:
default=False,
help="Show log/debug/diagnostic output",
)
parser.add_argument(
"--twovar",
required=False,
action="store_true",
default=False,
help="Double both variables in doubling experiments",
)
parser.add_argument(
"--md",
required=False,
Expand Down
6 changes: 6 additions & 0 deletions tada/util/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
LEVEL = "level"
SORTED = "sorted"
POSITION = "position"
DOUBLES = "twovar"


def save(configuration_filename: str, tada_configuration: Dict[str, Any]) -> None:
Expand Down Expand Up @@ -90,6 +91,11 @@ def get_types(current_dictionary):
return current_dictionary[TYPES]


def get_doubling_strategy(current_dictionary):
"""Return the doubling strategy argument from the provided dictionary"""
return current_dictionary[DOUBLES]


def get_schema_path(current_dictionary):
"""Return the schema path argument from the provided dictionary"""
return current_dictionary[SCHEMA]
Expand Down
20 changes: 12 additions & 8 deletions tada/util/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@


# pylint: disable=W0102
def store_data_to_global(path, chosen_size, level=1, position=[0]):
def store_data_to_global(path, chosen_size, level=1, position=[0], doubling_strategy=False):
"""Generate data through global variable"""

def store_global(a):
Expand All @@ -42,7 +42,7 @@ def store_global(a):
global_data = global_data + (a,)

strategies = generate_experiment_strategy(
path, chosen_size, level, position
path, chosen_size, level, position, doubling_strategy
)
# store data based on the amount of parameters
for st in strategies:
Expand All @@ -52,7 +52,7 @@ def store_global(a):


def generate_experiment_strategy(
path, size, level=1, position=[0]
path, size, level=1, position=[0], doubling_strategy=False
): # pylint: disable=W0102
"""generate strategies from a schema path and current input size"""
json_schema = read.read_schema(path)
Expand All @@ -75,8 +75,12 @@ def detect_level_and_position(
subschema, level - 1, position, index_position + 1
)

js = detect_level_and_position(json_schema, level, position)
double_experiment_size(js, size)
if doubling_strategy is True:
for js in json_schema:
double_experiment_size(js, size)
else:
js = detect_level_and_position(json_schema, level, position)
double_experiment_size(js, size)
strategy = []
for j in json_schema:
strategy.append(from_schema(j))
Expand Down Expand Up @@ -133,9 +137,9 @@ def generate_func_from_single_st(function, strategy):
return function


# pylint: disable=W0102, R0913
# pylint: disable=W0102, R0913, line-too-long
def generate_data(
chosen_types, chosen_size, level=1, position=[0], path=None, gen_func=None
chosen_types, chosen_size, level=1, position=[0], path=None, gen_func=None, doubling_strategy=False
):
"""Generate a list of data values"""
generated_values = ()
Expand All @@ -149,7 +153,7 @@ def generate_data(
generated_values = generated_values + (generated_value,)
elif chosen_types[0] == "hypothesis":
generated_values = store_data_to_global(
path, chosen_size, level, position
path, chosen_size, level, position, doubling_strategy
)
elif chosen_types[0] == "custom":
generated_values = gen_func(chosen_size)
Expand Down
17 changes: 17 additions & 0 deletions tests/test_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,23 @@ def test_generate_data_with_hypothesis(tmpdir):
assert generated_data is not None


# pylint: disable=W0102, R0913
def test_generate_data_with_hypothesis_doubling_both(tmpdir):
"""Checks that requesting a generated hypothesis data returns one"""
path = tmpdir.mkdir("sub").join("hello.txt")
path.write('[{"type": "array", "items": {"type": "integer"}}]')
# assume the doubling experiment is at 100
current_size = 100
level = 1
position = [0]
requested_types = ["hypothesis"]
requested_oath = str(path)
generated_data = generate.generate_data(
requested_types, current_size, level, position, requested_oath, True
)
assert generated_data is not None


# pylint: disable=W0621
def test_generate_data_with_gen_func(generate_int_test):
"""Checks that requesting a generated hypothesis data returns one"""
Expand Down