From 2459e4090babfab7721cf6e0f6f604b5c37cc56e Mon Sep 17 00:00:00 2001 From: Frank-Duffy Date: Fri, 24 Feb 2023 10:25:54 -0500 Subject: [PATCH 1/6] Create loop_logspace_interface.py --- .../tasks/logic/loop_logspace_interface.py | 102 ++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 exopy/tasks/tasks/logic/loop_logspace_interface.py diff --git a/exopy/tasks/tasks/logic/loop_logspace_interface.py b/exopy/tasks/tasks/logic/loop_logspace_interface.py new file mode 100644 index 00000000..11d94961 --- /dev/null +++ b/exopy/tasks/tasks/logic/loop_logspace_interface.py @@ -0,0 +1,102 @@ +# -*- coding: utf-8 -*- +# ----------------------------------------------------------------------------- +# Copyright 2015-2018-2018 by Exopy Authors, see AUTHORS for more details. +# +# Distributed under the terms of the BSD license. +# +# The full license is in the file LICENCE, distributed with this software. +# ----------------------------------------------------------------------------- +"""Interface allowing to use a linspace in a LoopTask + +""" +import numbers +from decimal import Decimal + +import numpy as np +from atom.api import Str + +from ..task_interface import TaskInterface +from ..validators import Feval + + +class LinspaceLoopInterface(TaskInterface): + """ Common logic for all loop tasks. + + """ + #: Value at which to start the loop. + start = Str('0.0').tag(pref=True, feval=Feval(types=numbers.Real)) + + #: Value at which to stop the loop (included) + stop = Str('1.0').tag(pref=True, feval=Feval(types=numbers.Real)) + + #: Step between loop values. + step = Str('0.1').tag(pref=True, feval=Feval(types=numbers.Real)) + + def check(self, *args, **kwargs): + """Check evaluation of all loop parameters. + + """ + task = self.task + err_path = task.path + '/' + task.name + test, traceback = super(LinspaceLoopInterface, + self).check(*args, **kwargs) + + if not test: + return test, traceback + + start = task.format_and_eval_string(self.start) + stop = task.format_and_eval_string(self.stop) + step = task.format_and_eval_string(self.step) + if 'value' in task.database_entries: + task.write_in_database('value', start) + + try: + num = int(abs((stop - start)/step)) + 1 + task.write_in_database('point_number', num) + except Exception as e: + test = False + mess = 'Loop task did not succeed to compute the point number: {}' + traceback[err_path + '-points'] = mess.format(e) + return test, traceback + + try: + np.arange(start, stop, step) + except Exception as e: + test = False + mess = 'Loop task did not succeed to create an arange: {}' + traceback[err_path + '-arange'] = mess.format(e) + + return test, traceback + + def perform(self): + """Build the arange and pass it to the LoopTask. + + """ + task = self.task + start = task.format_and_eval_string(self.start) + stop = task.format_and_eval_string(self.stop) + step = task.format_and_eval_string(self.step) + + # Make sure the sign of the step makes sense. + step = -abs(step) if start > stop else abs(step) + + # Compute the number of steps we need. + num = int(round(abs(((stop - start)/step)))) + 1 + + # Update stop to make sure that the generated step is close to the user + # specified one. + stop_digit = abs(Decimal(str(stop)).as_tuple().exponent) + start_digit = abs(Decimal(str(start)).as_tuple().exponent) + step_digit = abs(Decimal(str(step)).as_tuple().exponent) + digit = max((start_digit, step_digit, stop_digit)) + stop = round(start + (num-1)*step, digit) + + # Round values to the maximal number of digit used in start, stop and + # step so that we never get issues with floating point rounding issues. + # The max is used to allow from 1.01 to 2.01 by 0.1 + raw_values = np.linspace(start, stop, num) + iterable = np.fromiter((round(value, digit) + for value in raw_values), + np.float64, len(raw_values)) + task.write_in_database('loop_values', np.array(iterable)) + task.perform_loop(iterable) From eb4e415c7aec899b3acb8870effbab547c4c0ab6 Mon Sep 17 00:00:00 2001 From: Frank-Duffy Date: Fri, 24 Feb 2023 10:33:51 -0500 Subject: [PATCH 2/6] Update loop_logspace_interface.py --- exopy/tasks/tasks/logic/loop_logspace_interface.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/exopy/tasks/tasks/logic/loop_logspace_interface.py b/exopy/tasks/tasks/logic/loop_logspace_interface.py index 11d94961..3b396eb4 100644 --- a/exopy/tasks/tasks/logic/loop_logspace_interface.py +++ b/exopy/tasks/tasks/logic/loop_logspace_interface.py @@ -6,7 +6,7 @@ # # The full license is in the file LICENCE, distributed with this software. # ----------------------------------------------------------------------------- -"""Interface allowing to use a linspace in a LoopTask +"""Interface allowing to use a logspace in a LoopTask """ import numbers @@ -19,7 +19,7 @@ from ..validators import Feval -class LinspaceLoopInterface(TaskInterface): +class LogspaceLoopInterface(TaskInterface): """ Common logic for all loop tasks. """ @@ -38,7 +38,7 @@ def check(self, *args, **kwargs): """ task = self.task err_path = task.path + '/' + task.name - test, traceback = super(LinspaceLoopInterface, + test, traceback = super(LogspaceLoopInterface, self).check(*args, **kwargs) if not test: @@ -94,7 +94,7 @@ def perform(self): # Round values to the maximal number of digit used in start, stop and # step so that we never get issues with floating point rounding issues. # The max is used to allow from 1.01 to 2.01 by 0.1 - raw_values = np.linspace(start, stop, num) + raw_values = np.logspace(start, stop, num) iterable = np.fromiter((round(value, digit) for value in raw_values), np.float64, len(raw_values)) From ac51a34e92a4d4f1be4fc259a4d4b4406270fe53 Mon Sep 17 00:00:00 2001 From: Frank-Duffy Date: Fri, 24 Feb 2023 13:16:51 -0500 Subject: [PATCH 3/6] added loop_logspace_interface to declarations --- .gitignore | 4 +++- exopy/tasks/tasks/logic/declarations.enaml | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 943351be..aff23183 100644 --- a/.gitignore +++ b/.gitignore @@ -53,4 +53,6 @@ docs/build .spyderworkspace .spyproject .mypy_cache/ -.vscode/ \ No newline at end of file +.vscode/ +*.log +*.ini diff --git a/exopy/tasks/tasks/logic/declarations.enaml b/exopy/tasks/tasks/logic/declarations.enaml index 171107f6..ad6180bf 100644 --- a/exopy/tasks/tasks/logic/declarations.enaml +++ b/exopy/tasks/tasks/logic/declarations.enaml @@ -45,4 +45,8 @@ enamldef LogicTasks(Tasks): Interface: interface = 'loop_linspace_interface:LinspaceLoopInterface' + views = ['views.loop_linspace_view:LinspaceLoopView'] + + Interface: + interface = 'loop_logspace_interface:LogspaceLoopInterface' views = ['views.loop_linspace_view:LinspaceLoopView'] \ No newline at end of file From 4969e46587c66d5bea4528a02868985b37d1ecc5 Mon Sep 17 00:00:00 2001 From: Frank-Duffy Date: Mon, 27 Feb 2023 18:10:49 -0500 Subject: [PATCH 4/6] updated annotations --- exopy/tasks/tasks/logic/loop_logspace_interface.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/exopy/tasks/tasks/logic/loop_logspace_interface.py b/exopy/tasks/tasks/logic/loop_logspace_interface.py index 3b396eb4..9a7d596d 100644 --- a/exopy/tasks/tasks/logic/loop_logspace_interface.py +++ b/exopy/tasks/tasks/logic/loop_logspace_interface.py @@ -23,13 +23,13 @@ class LogspaceLoopInterface(TaskInterface): """ Common logic for all loop tasks. """ - #: Value at which to start the loop. + #: Value of exponent at which to start the loop. start = Str('0.0').tag(pref=True, feval=Feval(types=numbers.Real)) - #: Value at which to stop the loop (included) + #: Value of exponent at which to stop the loop (included) stop = Str('1.0').tag(pref=True, feval=Feval(types=numbers.Real)) - #: Step between loop values. + #: Step size between exponent values. step = Str('0.1').tag(pref=True, feval=Feval(types=numbers.Real)) def check(self, *args, **kwargs): From 34bdb0183691c8fd01481f9f12e25d650861429b Mon Sep 17 00:00:00 2001 From: Frank-Duffy Date: Mon, 27 Feb 2023 18:20:21 -0500 Subject: [PATCH 5/6] added base attribute to logspace loop interface --- exopy/tasks/tasks/logic/declarations.enaml | 2 +- .../tasks/logic/loop_logspace_interface.py | 6 +- .../logic/views/loop_logspace_view.enaml | 70 +++++++++++++++++++ 3 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 exopy/tasks/tasks/logic/views/loop_logspace_view.enaml diff --git a/exopy/tasks/tasks/logic/declarations.enaml b/exopy/tasks/tasks/logic/declarations.enaml index ad6180bf..5ed3157b 100644 --- a/exopy/tasks/tasks/logic/declarations.enaml +++ b/exopy/tasks/tasks/logic/declarations.enaml @@ -49,4 +49,4 @@ enamldef LogicTasks(Tasks): Interface: interface = 'loop_logspace_interface:LogspaceLoopInterface' - views = ['views.loop_linspace_view:LinspaceLoopView'] \ No newline at end of file + views = ['views.loop_logspace_view:LogspaceLoopView'] \ No newline at end of file diff --git a/exopy/tasks/tasks/logic/loop_logspace_interface.py b/exopy/tasks/tasks/logic/loop_logspace_interface.py index 9a7d596d..70e69fdb 100644 --- a/exopy/tasks/tasks/logic/loop_logspace_interface.py +++ b/exopy/tasks/tasks/logic/loop_logspace_interface.py @@ -32,6 +32,9 @@ class LogspaceLoopInterface(TaskInterface): #: Step size between exponent values. step = Str('0.1').tag(pref=True, feval=Feval(types=numbers.Real)) + #: Base value. + base = Str().tag(pref=True, feval=Feval(types=numbers.Real)) + def check(self, *args, **kwargs): """Check evaluation of all loop parameters. @@ -76,6 +79,7 @@ def perform(self): start = task.format_and_eval_string(self.start) stop = task.format_and_eval_string(self.stop) step = task.format_and_eval_string(self.step) + base = task.format_and_eval_string(self.base) # Make sure the sign of the step makes sense. step = -abs(step) if start > stop else abs(step) @@ -94,7 +98,7 @@ def perform(self): # Round values to the maximal number of digit used in start, stop and # step so that we never get issues with floating point rounding issues. # The max is used to allow from 1.01 to 2.01 by 0.1 - raw_values = np.logspace(start, stop, num) + raw_values = np.logspace(start=start, stop=stop, num=num, base=base) iterable = np.fromiter((round(value, digit) for value in raw_values), np.float64, len(raw_values)) diff --git a/exopy/tasks/tasks/logic/views/loop_logspace_view.enaml b/exopy/tasks/tasks/logic/views/loop_logspace_view.enaml new file mode 100644 index 00000000..a282ca81 --- /dev/null +++ b/exopy/tasks/tasks/logic/views/loop_logspace_view.enaml @@ -0,0 +1,70 @@ +# -*- coding: utf-8 -*- +# ----------------------------------------------------------------------------- +# Copyright 2015-2018 by Exopy Authors, see AUTHORS for more details. +# +# Distributed under the terms of the BSD license. +# +# The full license is in the file LICENCE, distributed with this software. +# ----------------------------------------------------------------------------- +"""View for the LinspaceLoopInterface. + +""" +from enaml.widgets.api import (Container, Label, Splitter, SplitItem) + +from .....utils.widgets.qt_completers import QtLineCompleter +from ...string_evaluation import EVALUATER_TOOLTIP + + +enamldef LogspaceLoopView(Splitter): view: + """View for the LogspaceLoopInterface. + + """ + #: Reference to the interface to which this view is linked. + attr interface + + #: Reference to the root view. + attr root + + SplitItem: + Container: + padding = 0 + Label: lab_start: + text = 'Start' + QtLineCompleter: val_start: + text := interface.start + entries_updater << \ + interface.task.list_accessible_database_entries + tool_tip = "Exponent of first value in logspace list" + + SplitItem: + Container: + padding = 0 + Label: lab_stop: + text = 'Stop' + QtLineCompleter: val_stop: + text := interface.stop + entries_updater << \ + interface.task.list_accessible_database_entries + tool_tip = "Exponent of last value in logspace list" + + SplitItem: + Container: + padding = 0 + Label: lab_step: + text = 'Step' + QtLineCompleter: val_step: + text := interface.step + entries_updater << \ + interface.task.list_accessible_database_entries + tool_tip = "Step size of exponent" + SplitItem: + Container: + padding = 0 + Label: lab_base: + text = 'Base' + QtLineCompleter: val_base: + text := interface.base + entries_updater << \ + interface.task.list_accessible_database_entries + tool_tip = "Base value" + From a4da9b1f6d4a3a7faba2482e8dcad7c4202fee3a Mon Sep 17 00:00:00 2001 From: Frank-Duffy Date: Wed, 1 Mar 2023 14:11:41 -0500 Subject: [PATCH 6/6] updated copyright dates --- exopy/tasks/tasks/logic/declarations.enaml | 2 +- exopy/tasks/tasks/logic/loop_logspace_interface.py | 2 +- exopy/tasks/tasks/logic/views/loop_logspace_view.enaml | 2 +- exopy/tasks/tasks/logic/views/loop_view.enaml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/exopy/tasks/tasks/logic/declarations.enaml b/exopy/tasks/tasks/logic/declarations.enaml index 5ed3157b..9a2148f8 100644 --- a/exopy/tasks/tasks/logic/declarations.enaml +++ b/exopy/tasks/tasks/logic/declarations.enaml @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # ----------------------------------------------------------------------------- -# Copyright 2015-2018 by Exopy Authors, see AUTHORS for more details. +# Copyright 2015-2023 by Exopy Authors, see AUTHORS for more details. # # Distributed under the terms of the BSD license. # diff --git a/exopy/tasks/tasks/logic/loop_logspace_interface.py b/exopy/tasks/tasks/logic/loop_logspace_interface.py index 70e69fdb..174bea87 100644 --- a/exopy/tasks/tasks/logic/loop_logspace_interface.py +++ b/exopy/tasks/tasks/logic/loop_logspace_interface.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # ----------------------------------------------------------------------------- -# Copyright 2015-2018-2018 by Exopy Authors, see AUTHORS for more details. +# Copyright 2015-2023 by Exopy Authors, see AUTHORS for more details. # # Distributed under the terms of the BSD license. # diff --git a/exopy/tasks/tasks/logic/views/loop_logspace_view.enaml b/exopy/tasks/tasks/logic/views/loop_logspace_view.enaml index a282ca81..19ce5682 100644 --- a/exopy/tasks/tasks/logic/views/loop_logspace_view.enaml +++ b/exopy/tasks/tasks/logic/views/loop_logspace_view.enaml @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # ----------------------------------------------------------------------------- -# Copyright 2015-2018 by Exopy Authors, see AUTHORS for more details. +# Copyright 2015-2023 by Exopy Authors, see AUTHORS for more details. # # Distributed under the terms of the BSD license. # diff --git a/exopy/tasks/tasks/logic/views/loop_view.enaml b/exopy/tasks/tasks/logic/views/loop_view.enaml index 136cbe1a..eaeb7f5b 100644 --- a/exopy/tasks/tasks/logic/views/loop_view.enaml +++ b/exopy/tasks/tasks/logic/views/loop_view.enaml @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # ----------------------------------------------------------------------------- -# Copyright 2015-2018 by Exopy Authors, see AUTHORS for more details. +# Copyright 2015-2023 by Exopy Authors, see AUTHORS for more details. # # Distributed under the terms of the BSD license. #