Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate configuration from algorithms #200

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

BUYT-1
Copy link
Collaborator

@BUYT-1 BUYT-1 commented Apr 3, 2023

Splits configuration-related things into a separate Configuration class, tests included.
TypoMiner's methods are reorganized in accordance with this class's structure.
Solves the problem with PliBasedFDAlgorithm's code repetition.
Better behavior in Python. More info about the options is provided to Python.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

python_bindings/get_py_type.h Outdated Show resolved Hide resolved
python_bindings/py_algorithm.h Outdated Show resolved Hide resolved
python_bindings/py_ar_algorithm.h Outdated Show resolved Hide resolved
python_bindings/py_to_any.h Outdated Show resolved Hide resolved
src/algorithms/options/configuration.h Outdated Show resolved Hide resolved
src/algorithms/options/option.h Outdated Show resolved Hide resolved
src/algorithms/options/option.h Outdated Show resolved Hide resolved
src/algorithms/options/option.h Outdated Show resolved Hide resolved
src/algorithms/options/option.h Outdated Show resolved Hide resolved
src/algorithms/options/option.h Outdated Show resolved Hide resolved
@BUYT-1 BUYT-1 force-pushed the separate-config branch 3 times, most recently from 53dae04 to b21c6a5 Compare April 6, 2023 08:34
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

src/algorithms/options/configuration.h Outdated Show resolved Hide resolved
@BUYT-1 BUYT-1 force-pushed the separate-config branch 2 times, most recently from ec37a4b to 2e29f49 Compare April 6, 2023 08:45
@BUYT-1 BUYT-1 mentioned this pull request Apr 6, 2023
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

src/algorithms/options/configuration.h Outdated Show resolved Hide resolved
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

src/algorithms/options/configuration.h Outdated Show resolved Hide resolved
@BUYT-1 BUYT-1 force-pushed the separate-config branch 4 times, most recently from 62b33e1 to 030e869 Compare April 10, 2023 08:18
@BUYT-1 BUYT-1 force-pushed the separate-config branch 5 times, most recently from edf3df4 to 6de65f6 Compare April 20, 2023 07:37
@BUYT-1 BUYT-1 force-pushed the separate-config branch 2 times, most recently from 08b8905 to 1237dd0 Compare April 29, 2023 10:34
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

python_bindings/dataframe_reader.h Outdated Show resolved Hide resolved
@BUYT-1 BUYT-1 force-pushed the separate-config branch 2 times, most recently from bdc91f4 to 20c5069 Compare June 14, 2023 21:21
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

python_bindings/create_dataframe_reader.h Outdated Show resolved Hide resolved
src/algorithms/cfd/cfd_discovery.cpp Outdated Show resolved Hide resolved
src/algorithms/cfd/cfd_discovery.cpp Outdated Show resolved Hide resolved
src/algorithms/cfd/fd_first_algorithm.cpp Outdated Show resolved Hide resolved
src/algorithms/cfd/fd_first_algorithm.cpp Outdated Show resolved Hide resolved
src/algorithms/typo_miner.cpp Outdated Show resolved Hide resolved
src/algorithms/ucc/hyucc/hyucc.cpp Outdated Show resolved Hide resolved
src/algorithms/ucc/hyucc/hyucc.cpp Outdated Show resolved Hide resolved
src/algorithms/ucc/ucc_algorithm.cpp Outdated Show resolved Hide resolved
src/algorithms/ucc/ucc_algorithm.cpp Outdated Show resolved Hide resolved
@BUYT-1 BUYT-1 force-pushed the separate-config branch from 20c5069 to 78e7147 Compare June 14, 2023 22:02
@BUYT-1
Copy link
Collaborator Author

BUYT-1 commented Jun 14, 2023

Проба пера. Получилось очень много бойлерплейта, но когда за макросом спрятал, стало терпимо.

С IOptionRegistry замысел в том, чтобы можно было вызвать шаблонную функцию, которая показывала бы, какие опции добавляет алгоритм. И от этого интерфейса отнаследовать другой класс специально для этих целей. Вторым параметром в эти статические методы должен передаваться nullptr по этому замыслу.

@BUYT-1 BUYT-1 force-pushed the separate-config branch from 78e7147 to 0279169 Compare June 16, 2023 11:39
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

tests/test_configuration.cpp Outdated Show resolved Hide resolved
tests/test_configuration.cpp Outdated Show resolved Hide resolved
tests/test_configuration.cpp Outdated Show resolved Hide resolved
tests/test_configuration.cpp Show resolved Hide resolved
tests/test_configuration.cpp Show resolved Hide resolved
tests/test_configuration.cpp Outdated Show resolved Hide resolved
tests/test_configuration.cpp Show resolved Hide resolved
tests/test_configuration.cpp Show resolved Hide resolved
tests/test_configuration.cpp Show resolved Hide resolved
tests/test_configuration.cpp Show resolved Hide resolved
@BUYT-1 BUYT-1 force-pushed the separate-config branch 5 times, most recently from 827bc8f to 656f217 Compare July 10, 2023 15:00
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

src/algorithms/typo_miner.cpp Show resolved Hide resolved
@BUYT-1 BUYT-1 force-pushed the separate-config branch 2 times, most recently from 8d10b21 to 2c4bd78 Compare July 10, 2023 15:35
@BUYT-1 BUYT-1 marked this pull request as ready for review July 10, 2023 15:38
@BUYT-1 BUYT-1 force-pushed the separate-config branch from 2c4bd78 to cdbc8f0 Compare July 10, 2023 16:15
@BUYT-1 BUYT-1 force-pushed the separate-config branch from cdbc8f0 to 978f63d Compare July 11, 2023 18:25
@BUYT-1
Copy link
Collaborator Author

BUYT-1 commented Jul 12, 2023

Здесь как будто много кода по типу

auto Method(...) {
    return configuration.Method(...);
}

в алгоритме

Copy link
Collaborator

@polyntsov polyntsov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Очень большой пр, логически отдельные части закидывай в будущем пожалуйста разными прами (форматирование pyro тут ни к чему, как минимум) :)
Не очень понимаю логику с передачей объектов опций как rvalue ref везде.
Хорошие тесты, кстати

src/core/parameters.h Show resolved Hide resolved
Comment on lines +67 to 71
Option &&SetValueCheck(ValueCheckFunc value_check) {
assert(!value_check_);
value_check_ = std::move(value_check);
return *this;
return std::move(*this);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а зачем?

Comment on lines +63 to +65
std::unique_ptr<IOption> MoveToHeap() override {
return std::make_unique<Option>(std::move(*this));
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не очень ясно зачем и как этот метод помогает. Как будто вызывающий код сам может сделать std::make_unique<Option>(opt), если нужном

Comment on lines +11 to +13
load_data = 0,
load_prepared_data,
execute
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kLoadData, kLoadPreparedData, kExecute

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Разве? Это же enum, а не кучка констант. В остальных enumах такие имена.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ну enum это по сути и есть кучка констант с конкретными типом :)
В некоторых enumах имена такие только потому что мы хотим строки преобразовывать в значения енама и эти строки получаем от пользователя. Стайлгайд просит их именовать как константы

namespace util::config {

// clang-format off
BETTER_ENUM(ConfigurationStage, size_t,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а зачем size_t?

// Options with the same names must have certain semantics. The
// situation where both algorithms have options with the same name but
// one throws an exception for the pair of values while the other does
// not is undefined behaviour. The situation where both algorithms may
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Опять же, предлагаю не использовать "undefined behavior" в коде, кототрый мы контролируем :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Так ведь оно сейчас так же работает. Просто здесь это явно написано. "Программистская ошибка", может быть, точнее будет

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Так ведь оно сейчас так же работает.

Не очень понял, что так же работает (и как, так же?).
Я просто предлагаю избегать ситуаций в коде, которые нарушают какие-либо инварианты и это никак не отлавливается, а вместо этого говорится, что это "undefined behavior" и разбирайтесь сами. Нам же потом это и дебажить ведь. Стоит как минимум писать ассерты, проверяющие нужные инварианты. Тут такой ассерт уже есть насколько я вижу, поэтому просто предлагаю убрать "undefined behavior", а написать, что это просто ожидания этого кода.

@@ -28,16 +24,21 @@ std::unique_ptr<AlgorithmBase> CreateAlgorithmInstance(AlgorithmType algorithm)
static_cast<size_t>(algorithm), create);
}

template <typename AlgorithmBase>
std::vector<AlgorithmType> GetAllDerived() {
template <typename DerivedFrom>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

по-моему Base лучше, чем DerivedFrom, такой нейминг путает

Comment on lines +46 to +48
if (option_name == kPliRelation) {
throw std::logic_error("You do not manage this option.");
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

довольно плохо выглядит, но решения лучше я придумать не могу


TEST_F(ConfigurationTesting, BasicConfiguration) {
int var1;
const int var1val = 4;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: constexpr

Comment on lines +12 to +20
using FuncTuple = Configuration::FuncTuple;
using OptionNameSet = Configuration::OptionNameSet;
using AddExternalOptFunc = Configuration::AddExternalOptFunc;
using SetExternalOptFunc = Configuration::SetExternalOptFunc;
using UnsetExternalOptFunc = Configuration::UnsetExternalOptFunc;
using GetExternalTypeIndexFunc = Configuration::GetExternalTypeIndexFunc;
using ResetExternalAlgoConfigFunc = Configuration::ResetExternalAlgoConfigFunc;

class ConfigurationTesting : public ::testing::Test {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: anonymous namespace

@BUYT-1 BUYT-1 marked this pull request as draft July 29, 2023 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Performance upgrade or technical debt
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants