-
Notifications
You must be signed in to change notification settings - Fork 246
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
Replace rapidjson to nlohmann json #58
Conversation
…ot yet to be merged
…ot yet to be merged
…om/KratosMultiphysics/Kratos into replace-rapidjson-to-nlohmann-json
the branch is almost ready for being merged, however an issue with the printing of doubles still remains. Waiting for feedback from the nlohmann library author, who acknowledged the bug
…nto replace-rapidjson-to-nlohmann-json
…into replace-rapidjson-to-nlohmann-json
Just one thing, if JSON is faster as IO there is any plan in the future to switch the mdpa in plain text to mdpa.json? @RiccardoRossi @pooyan-dadvand |
Hi,
first of all i would like to tell that the use we make of json for
Parameters has a lot of error checking which makes it slower than native
json.
In particular i do like the option of reading directly from json, however
this is a very large change and can not be done lightly. Around one year
ago i did put a proposal on how this could be done, but it didn't prosper.
Eventually we could retake it sometimes
cheers
Riccardo
<http://www.cimne.com/>
|
I will check it in windows. But would be tomorrow. |
I think two important things must be solved before replacing the json library: 1.- In this library, are list iterators available? And can them be exported to python to avoid asking for the size of the json lists and to avoid loops with range ? 2.- Does it allows to ask for the json keys ? We need this functionality to read the variables in the new materials processes in json. Regards |
In principle it provides the same capabilities and limitations of the old
one.
In particular the iterators are behaving exactly identical as they did, and
you can take a look to the test_kratos_parameters.py for their usage.
Am i missing smthg?
…On Wed, Feb 22, 2017 at 9:37 PM, Josep Maria ***@***.***> wrote:
I think two important things must be solved before replacing the json
library:
1.- In this library, are list iterators available? And can them be
exported to python to avoid asking for the size of the json lists and to
avoid loops with range ?
2.- Does it allows to ask for the json *keys* ? We need this
functionality to read the variables in the new materials processes in json.
Regards
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#58 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AHr7EUOxpkYRDu2MoiS5onu4orvrZy3iks5rfJyMgaJpZM4MHMnJ>
.
--
*Riccardo Rossi*
PhD, Civil Engineer
member of the Kratos Team: www.cimne.com/kratos
Tenure Track Lecturer at Universitat Politècnica de Catalunya,
BarcelonaTech (UPC)
Full Research Professor at International Center for Numerical Methods in
Engineering (CIMNE)
C/ Gran Capità, s/n, Campus Nord UPC, Ed. B0, Despatx 102
(please deliver post to the porters of building C1)
08034 – Barcelona – Spain – www.cimne.com -
T.(+34) 93 401 56 96 skype: *rougered4*
<http://www.cimne.com/>
<https://www.facebook.com/cimne> <http://blog.cimne.com/>
<http://vimeo.com/cimne> <http://www.youtube.com/user/CIMNEvideos>
<http://www.linkedin.com/company/cimne> <https://twitter.com/cimne>
Les dades personals contingudes en aquest missatge són tractades amb la
finalitat de mantenir el contacte professional entre CIMNE i voste. Podra
exercir els drets d'accés, rectificació, cancel·lació i oposició,
dirigint-se a cimne@cimne.upc.edu. La utilització de la seva adreça de
correu electronic per part de CIMNE queda subjecte a les disposicions de la
Llei 34/2002, de Serveis de la Societat de la Informació i el Comerç
Electronic.
Imprimiu aquest missatge, només si és estrictament necessari.
<http://www.cimne.com/>
|
Yes, I think something is missing. In the py file you mention, you have the example: This is how a loop is done now when we have a list in json:
and this is how we would like to do it:
And also the important feature of getting the keys and variables from a json. As is done in the read_materials_process.py, which imports the native json from python, i.e.:
I think we also would like to do it without importing json from python.. or can we import it and use it? |
hello, however before changing the materials input i would wait for this branch to be approved, since this feature is not current available in the master branch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have checked it in my Visual Studio and it doesn't compile due to the fact that my VS build version (14.023107.0) is older than minimum version supported by nlohmann json (14.0.25123.0). The updated version won't work with boost.
So we should postponed these changes.
i agree. This is a blocker. Writing an issue for the upstream library |
@RiccardoRossi the branch is still opened |
now that boost python has been replaced maybe you want to give this another try? |
I think it would be worth...
Riccardo
…On Fri, May 18, 2018 at 5:42 PM, Philipp Bucher ***@***.***> wrote:
now that boost python has been replaced maybe you want to give this
another try?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#58 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AHr7ETc713Xf72a6x3S6tR4F5PnDfrClks5tzuvIgaJpZM4MHMnJ>
.
--
*Riccardo Rossi*
PhD, Civil Engineer
member of the Kratos Team: www.cimne.com/kratos
Tenure Track Lecturer at Universitat Politècnica de Catalunya,
BarcelonaTech (UPC)
Full Research Professor at International Center for Numerical Methods in
Engineering (CIMNE)
C/ Gran Capità, s/n, Campus Nord UPC, Ed. B0, Despatx 102
(please deliver post to the porters of building C1)
08034 – Barcelona – Spain – www.cimne.com -
T.(+34) 93 401 56 96 skype: *rougered4*
<http://www.cimne.com/>
<https://www.facebook.com/cimne> <http://blog.cimne.com/>
<http://vimeo.com/cimne> <http://www.youtube.com/user/CIMNEvideos>
<http://www.linkedin.com/company/cimne> <https://twitter.com/cimne>
Les dades personals contingudes en aquest missatge són tractades amb la
finalitat de mantenir el contacte professional entre CIMNE i voste. Podra
exercir els drets d'accés, rectificació, cancel·lació i oposició,
dirigint-se a cimne@cimne.upc.edu. La utilització de la seva adreça de
correu electronic per part de CIMNE queda subjecte a les disposicions de la
Llei 34/2002, de Serveis de la Societat de la Informació i el Comerç
Electronic.
Imprimiu aquest missatge, només si és estrictament necessari.
<http://www.cimne.com/>
|
Which is the difference respect the current version? |
nlohmann is a much cleaner c++11 based implementation. also it natively
uses std containers
…On Fri, May 18, 2018 at 10:04 PM, Vicente Mataix Ferrándiz < ***@***.***> wrote:
Reopened #58 <#58>.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#58 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AHr7EUx9M6ds1UJyyRBk_zxUX2gpvBNaks5tzylBgaJpZM4MHMnJ>
.
--
*Riccardo Rossi*
PhD, Civil Engineer
member of the Kratos Team: www.cimne.com/kratos
Tenure Track Lecturer at Universitat Politècnica de Catalunya,
BarcelonaTech (UPC)
Full Research Professor at International Center for Numerical Methods in
Engineering (CIMNE)
C/ Gran Capità, s/n, Campus Nord UPC, Ed. B0, Despatx 102
(please deliver post to the porters of building C1)
08034 – Barcelona – Spain – www.cimne.com -
T.(+34) 93 401 56 96 skype: *rougered4*
<http://www.cimne.com/>
<https://www.facebook.com/cimne> <http://blog.cimne.com/>
<http://vimeo.com/cimne> <http://www.youtube.com/user/CIMNEvideos>
<http://www.linkedin.com/company/cimne> <https://twitter.com/cimne>
Les dades personals contingudes en aquest missatge són tractades amb la
finalitat de mantenir el contacte professional entre CIMNE i voste. Podra
exercir els drets d'accés, rectificació, cancel·lació i oposició,
dirigint-se a cimne@cimne.upc.edu. La utilització de la seva adreça de
correu electronic per part de CIMNE queda subjecte a les disposicions de la
Llei 34/2002, de Serveis de la Societat de la Informació i el Comerç
Electronic.
Imprimiu aquest missatge, només si és estrictament necessari.
<http://www.cimne.com/>
|
This is ready @RiccardoRossi and @pooyan-dadvand |
kratos/sources/kratos_parameters.cpp
Outdated
@@ -228,6 +228,14 @@ Parameters::Parameters(Parameters const& rOther) | |||
/***********************************************************************************/ | |||
/***********************************************************************************/ | |||
|
|||
Parameters::Parameters(Parameters&& rOther) : Parameters() | |||
{ | |||
swap(rOther); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if this is custom then maybe a different name would be better to not confuse it with the one in the standard ...?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current implementation already has a swap method
Kratos/kratos/includes/kratos_parameters.h
Line 467 in dfe73ec
void swap(Parameters& rOther) noexcept |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is on master
@philbucher does it work with Intel compiler? We should be very cautious with compiler compatibility of new libraries... |
I tested it with Intel and it seems to work 👍 |
is this happening? then we could also implement the long-awaited #2241 |
I will solve the conflict, but this is ready to merge |
Conflict solved |
pybind11::list items(Parameters const& self) | ||
{ | ||
pybind11::list t; | ||
for(Parameters::const_iterator it=self.begin(); it!=self.end(); ++it) | ||
for(auto it=self.begin(); it!=self.end(); ++it) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does auto
determine the correct type here? => iterator
or const_iterator
?
With iterators I am usually a bit unsure
@roigcarlo do you know?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The self is const, so the auto can be only a const iterator.. In any can be changed
for(auto it=self.begin(); it!=self.end(); ++it) | |
for(Parameters::const_iterator it=self.begin(); it!=self.end(); ++it) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted @philbucher
kratos/includes/kratos_parameters.h
Outdated
|
||
// External includes | ||
#include "json/json_fwd.hpp" // Import forward declaration nlohmann json library |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you explain briefly what exactly you did with this?
I know it is needed to pass Travis, but it would be good to know in case someone wants to update the library
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Th forward declaration is only a declaration of the classes (just the name), which means that you can work only with references and pointers, so the compiler can manage the memory for that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
external_libraries/json/json_fwd.hpp
Outdated
@@ -0,0 +1,79 @@ | |||
#ifndef NLOHMANN_JSON_FWD_HPP |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this the original file that you downloaded or did you modify it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the one in the json repository + the declaration of the iterators (in the original just the json class is forward declared)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thx for the effort
I meant that we can also add it in the future, since this is the eternal PR already and now it needs again to be reviewed
If you want you could revert and we can add it in the future
kratos/includes/kratos_parameters.h
Outdated
* This version walks and validates the entire json tree below the point at which the function is called | ||
* @param rDefaultParameters Parameters of reference which we use to check | ||
*/ | ||
void RecursivelyValidateAndAssignDefaults(const Parameters& rDefaultParameters); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this method should only accept a const object, why would it need to modify the input?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not change the current behavior right now
To be discussed in the next week @KratosMultiphysics/technical-committee meeting. |
Hurray
El vie., 11 ene. 2019 10:09, Pooyan Dadvand <notifications@github.com>
escribió:
… To be discussed in the next week @KratosMultiphysics/technical-committee
<https://github.com/orgs/KratosMultiphysics/teams/technical-committee>
meeting.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#58 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ATEMgCg8TEgVl4DJ0HGnmSzaAmUSnNlPks5vCFS6gaJpZM4MHMnJ>
.
|
Special thanks to @RiccardoRossi and @loumalouomega for their effort on this! 👍 |
I am so happy, finally |
Hello,
this branch removes rapidjson as support library for the KratosParameters and replaces it to the "nlohmann" json library.
This is more or less a complete rewrite of the kratos_parameters, which however maintains the same API and should (hopefully) not affect at any user. It passes all of the existing unit tests.
i believe that the new code base is sensibly cleaner than the old version and the nlohmann library is more modern than rapidjson, apart for being contained within a single header.
The most important advantage is that json objects are stored in a std::map instead in a list as happend with rapidjson, making unordered insertion/search much faster.
A nice feature is also that the new lib should also allow serializing/reading to a binary format
WARNING: the current version has not been tested on windows, so before accepting the pull request someone should try that out.