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

Option in bpls to show the expression string for derived variables #4145

Merged
merged 2 commits into from
Apr 18, 2024

Conversation

anagainaru
Copy link
Contributor

@anagainaru anagainaru commented Apr 18, 2024

Added the option --show-derived in bpls to print the expression string for derived variables.

$ ./bin/bpls expAdd.bp --show-derived -l
  float    derived/addU  2*{10, 3, 6} = 2.98842 / 28.085
    Derived variable with expression: x =sim1/Ux  y =sim1/Uy  z =sim1/Uz  x+y+z
  float    sim1/Ux       2*{10, 3, 6} = 0.000224775 / 9.94031
  float    sim1/Uy       2*{10, 3, 6} = 0.0201616 / 9.83318
  float    sim1/Uz       2*{10, 3, 6} = 0.0031 / 9.95085

@anagainaru anagainaru requested a review from eisenhauer April 18, 2024 13:02
Copy link
Member

@eisenhauer eisenhauer left a comment

Choose a reason for hiding this comment

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

My only thought here was whether or not we should be returning std::string rather than char* if we're passing outside the Engine class. Inside BP5, or between engine and serializer, we've stuck more closely to C than C++ memory management (for good reason, given the nature of BP5 metadata management and the pain points in BP4 Dims handling). But this would be the first unmanaged pointer returned out of Engine.h. This particular use case isn't a worry at all, and maybe there wouldn't be any other uses, but it's maybe something to think about as we add interfaces.

@anagainaru
Copy link
Contributor Author

@eisenhauer I like the idea of returning the value in a std::string more than an internal pointer. I'll change it tonight.

Small question: why are we testing the output of bpls -h?

@eisenhauer
Copy link
Member

Small question: why are we testing the output of bpls -h?

Completeness? (Really, I have no idea...)

@pnorbert
Copy link
Contributor

@eisenhauer I like the idea of returning the value in a std::string more than an internal pointer. I'll change it tonight.

Small question: why are we testing the output of bpls -h?

Can't remember anymore. I think was completeness but probably overkill.

@pnorbert
Copy link
Contributor

Would you be able to indent the expression lines under the variable? I.e. 4 spaces for each line

@pnorbert
Copy link
Contributor

My only thought here was whether or not we should be returning std::string rather than char* if we're passing outside the Engine class. Inside BP5, or between engine and serializer, we've stuck more closely to C than C++ memory management (for good reason, given the nature of BP5 metadata management and the pain points in BP4 Dims handling). But this would be the first unmanaged pointer returned out of Engine.h. This particular use case isn't a worry at all, and maybe there wouldn't be any other uses, but it's maybe something to think about as we add interfaces.

We could return a const char const * in the core, to avoid modifications but not necessary to have a copy at this point. If this goes up to the bindings, there a copy must be made to return to users.

@pnorbert
Copy link
Contributor

but then again, if it was already returning a string, I would not complain about wasting memory by this copy

@eisenhauer
Copy link
Member

@pnorbert That's a fair point... This is not bindings, so we're responsible for making sure things are handled safely internally. const or not, the string pointed to by the char* is valid as long as the variable is valid, which on the read size in BP5 is at least from BeginStep to EndStep in streaming mode (longer for RRA) and that's all we need for bpls. So, I'll retract my criticism...

eisenhauer
eisenhauer previously approved these changes Apr 18, 2024
@anagainaru
Copy link
Contributor Author

Fair points, I will return a const char * and will add 4 spaces.

When the derived variable spans on multiple lines the spaces will only be applied to the first line. @lizdulac is working on having the compressed version of the expression encoded on the writer side so it looks nicer when we plot it.

eisenhauer
eisenhauer previously approved these changes Apr 18, 2024
@anagainaru
Copy link
Contributor Author

Aaaah, I corrected the text shown in bpls -h but I forgot to update the useless test, sorry @eisenhauer you'll have to approve again

@eisenhauer
Copy link
Member

No worries!

@anagainaru anagainaru merged commit 0ee43a4 into ornladios:master Apr 18, 2024
39 checks passed
@anagainaru anagainaru deleted the bpls-derived branch April 18, 2024 22:05
@anagainaru anagainaru added this to the v2.10.1 milestone May 28, 2024
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.

3 participants