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

Convert all 0/1 flags to True, False in the python interface #1942

Closed
jonaslandsgesell opened this issue Apr 5, 2018 · 3 comments · Fixed by #2927
Closed

Convert all 0/1 flags to True, False in the python interface #1942

jonaslandsgesell opened this issue Apr 5, 2018 · 3 comments · Fixed by #2927
Milestone

Comments

@jonaslandsgesell
Copy link
Member

jonaslandsgesell commented Apr 5, 2018

E.g. (and at all the other occations - which one would need to find)

system.constraints.add(particle_type=0, penetrable=0, only_positive=0, shape=floor)

should read:

system.constraints.add(particle_type=0, penetrable=False, only_positive=False, shape=floor)

this can be easily achieved e.g. in the interface. It would be a task for a Hiwi.

@hmenke
Copy link
Member

hmenke commented Apr 5, 2018

That is probably a remnant from the TCL interface. On the other hand, the integers are implicitly convertible to boolean, so the “wrong” syntax will remain valid. Furthermore I believe that particle_type should not be a boolean.

Relevant lines:

int &only_positive() { return m_only_positive; }
int &penetrable() { return m_penetrable; }

int m_penetrable;
int m_only_positive;

All the rest is done by type inference in the AutoParameters magic.

@fweik
Copy link
Contributor

fweik commented Apr 5, 2018

The only implicit type conversions in the script interface are int -> float, this is on purpose because implicit conversions are evil. For the constraints class you can just change the core variable to bool, the rest is automatic, as Henri pointed out.

@jonaslandsgesell
Copy link
Member Author

jonaslandsgesell commented Apr 5, 2018

I want this to be replaced everywhere, shape based constraints are not the only occasion. Another arbitrary occasion is create_polymer(...,constraints=0) etc. I guess there are so many occasions that a student assistent could look for all these occasions and remove them.
Another arbitrary example is system.periodicity=[0,1,0], which coule more intuitively be [False, True, False]

@fweik fweik added this to the Espresso 4.1 milestone Jul 13, 2018
bors bot added a commit that referenced this issue Jun 25, 2019
2915: Checkpointing: lbboundaries, constraints, auto_update_accumulators +test r=fweik a=RudolfWeeber



2927: Conversion of int-flags to bool in python interface r=fweik a=reinaual

Fixes #1942 
also changed flags in ELC/MMM2D code

2932: Improve maintainability of build_cmake.sh r=fweik a=jngrad

The number of pitfalls in a shell script can be reduced if Google's [Shell Style Guide](https://google.github.io/styleguide/shell.xml#Variable_expansion) is followed:
- no more cryptic `if [ ! -z "${var+x}" ]` to test if a variable is undeclared (also, the conditional was used incorrectly and caused the error message `line 94: curl: command not found` in Travis-CI without triggering the trap)
- use CMake-like boolean values and test explicitly if a variable is equal to  `true` or `false` (we had a mix of `true`, `yes` and empty strings)
- every variable is brace-quoted
- every string variable is quoted (no more `build_dir="build maxset"; cd ${build_dir}` causing `bash: cd: too many arguments`)

Co-authored-by: Rudolf Weeber <weeber@icp.uni-stuttgart.de>
Co-authored-by: Jean-Noël Grad <jgrad@icp.uni-stuttgart.de>
Co-authored-by: Alexander Reinauer <st144434@stud.uni-stuttgart.de>
@bors bors bot closed this as completed in #2927 Jun 25, 2019
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 a pull request may close this issue.

3 participants