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

Avoid exception in Options when parsing string to Field #2457

Merged
merged 5 commits into from
Oct 28, 2021
Merged

Conversation

dschwoerer
Copy link
Contributor

Mostly annoying with debugging, if an expected exception is thrown.

Mostly annoying with debugging, if an expected exception is thrown.
Copy link
Contributor

@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/sys/options.cxx Outdated Show resolved Hide resolved
return FieldFactory::get()->create3D(bout::utils::get<std::string>(value), this,
similar_to.getMesh(), similar_to.getLocation());
} else if (bout::utils::holds_alternative<Tensor<BoutReal>>(value)) {
auto localmesh = similar_to.getMesh();
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: auto localmesh can be declared as auto *localmesh [readability-qualified-auto]

auto localmesh = similar_to.getMesh();
    ^
note: this fix will not be applied because it overlaps with another fix

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am wondering about this one - wouldn't it increase readability even more if this would be Mesh* rather than auto*?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, you're probably right -- this bit isn't generic, the type isn't already repeated on the left, and we're unlikely to change the type, so Mesh* is probably good

similar_to.getMesh(), similar_to.getLocation());
} else if (bout::utils::holds_alternative<Tensor<BoutReal>>(value)) {
auto localmesh = similar_to.getMesh();
if (!localmesh) {
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: implicit conversion Mesh * -> bool [readability-implicit-bool-conversion]

if (!localmesh) {
         ^
note: this fix will not be applied because it overlaps with another fix

@ZedThree
Copy link
Member

While you're touching this, please could you do the same for as<Field2D> and as<FieldPerp>? 🙂

Copy link
Contributor

@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

similar_to.getMesh(), similar_to.getLocation());
}
if (bout::utils::holds_alternative<Tensor<BoutReal>>(value)) {
auto* localmesh = similar_to.getMesh();
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: auto localmesh can be declared as auto *localmesh [readability-qualified-auto]

auto localmesh = similar_to.getMesh();
^~~~~
auto *

}
if (bout::utils::holds_alternative<Tensor<BoutReal>>(value)) {
auto* localmesh = similar_to.getMesh();
if (localmesh != nullptr) {
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: implicit conversion Mesh * -> bool [readability-implicit-bool-conversion]

if (!localmesh) {
    ~^
               == nullptr

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (localmesh != nullptr) {
if (localmesh == nullptr) {

similar_to.getMesh(), similar_to.getLocation());
}
if (bout::utils::holds_alternative<Matrix<BoutReal>>(value)) {
auto* localmesh = similar_to.getMesh();
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: auto localmesh can be declared as auto *localmesh [readability-qualified-auto]

auto localmesh = similar_to.getMesh();
^~~~~
auto *

}
if (bout::utils::holds_alternative<Matrix<BoutReal>>(value)) {
auto* localmesh = similar_to.getMesh();
if (localmesh != nullptr) {
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: implicit conversion Mesh * -> bool [readability-implicit-bool-conversion]

if (!localmesh) {
    ~^
               == nullptr

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (localmesh != nullptr) {
if (localmesh == nullptr) {

similar_to.getMesh(), location);
}
if (bout::utils::holds_alternative<Matrix<BoutReal>>(value)) {
auto* localmesh = similar_to.getMesh();
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: auto localmesh can be declared as auto *localmesh [readability-qualified-auto]

auto localmesh = similar_to.getMesh();
^~~~~
auto *

}
if (bout::utils::holds_alternative<Matrix<BoutReal>>(value)) {
auto* localmesh = similar_to.getMesh();
if (localmesh != nullptr) {
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: implicit conversion Mesh * -> bool [readability-implicit-bool-conversion]

if (!localmesh) {
    ~^
               == nullptr

Copy link
Member

Choose a reason for hiding this comment

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

I thought the huge long comment from clang-tidy below was noise, but it actually caught the typo here!

Suggested change
if (localmesh != nullptr) {
if (localmesh == nullptr) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, I thought the analysis was invalid as I thought the last two steps would contradict each other - but you are right 👍

Copy link
Contributor

@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/sys/options.cxx Show resolved Hide resolved
src/sys/options.cxx Show resolved Hide resolved
src/sys/options.cxx Show resolved Hide resolved
@github-actions
Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@ZedThree
Copy link
Member

Tests are failing because we also need to handle the case where the variant holds an int. We probably want:

  if (bout::utils::holds_alternative<BoutReal>(value) or bout::utils::holds_alternative<int>(value)) {
    BoutReal scalar_value = bout::utils::variantStaticCastOrThrow<ValueType, BoutReal>(value);

    // Get metadata from similar_to, fill field with scalar_value
    return filledFrom(similar_to, scalar_value);
  }

or alternatively:

  if (bout::utils::holds_alternative<BoutReal>(value)) {
    BoutReal scalar_value = bout::utils::get<BoutReal>(value);

    // Get metadata from similar_to, fill field with scalar_value
    return filledFrom(similar_to, scalar_value);
  }
  if (bout::utils::holds_alternative<int>(value)) {
    BoutReal scalar_value = bout::utils::get<int>(value);

    // Get metadata from similar_to, fill field with scalar_value
    return filledFrom(similar_to, scalar_value);
  }

shorter version:

  if (bout::utils::holds_alternative<BoutReal>(value)) {
    // Get metadata from similar_to, fill field with scalar_value
    return filledFrom(similar_to, bout::utils::get<BoutReal>(value));
  }
  if (bout::utils::holds_alternative<int>(value)) {
    // Get metadata from similar_to, fill field with scalar_value
    return filledFrom(similar_to, bout::utils::get<int>(value));
  }

@ZedThree
Copy link
Member

Something seems to be making the Optimised, shared, Python (pull_request) build hang -- but not the (push) version. Currently running for 57 minutes. I'm guessing it'll get killed soon and then maybe we'll be able to see the logs

@dschwoerer
Copy link
Contributor Author

Unfortunately the logs do not reveal anything. Unless you have a better idea, I would just restart to see whether it is reproducible ...

@ZedThree
Copy link
Member

Looking at the timings in the logs, it looks like most things just took 10 minutes longer than in the push build for some reason. Everything ran fine though. Unfortunately, it's not possible to restart just one job, it will need to restart all of the (pull_request) jobs.

I'm going to use admin powers to merge this, the tests will get run again on the merge anyway.

@ZedThree ZedThree changed the title Avoid exception in options Avoid exception in Options when parsing string to Field Oct 28, 2021
@ZedThree ZedThree merged commit 024111e into next Oct 28, 2021
@ZedThree ZedThree deleted the clean-init branch October 28, 2021 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants