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

ParameterHandler: *.json files with keys containing underscores cannot be parsed #16453

Closed
mschreter opened this issue Jan 10, 2024 · 1 comment · Fixed by #16544
Closed

ParameterHandler: *.json files with keys containing underscores cannot be parsed #16453

mschreter opened this issue Jan 10, 2024 · 1 comment · Fixed by #16544
Milestone

Comments

@mschreter
Copy link
Contributor

mschreter commented Jan 10, 2024

Problem description

In a student project, we are currently trying to parse an input file in *.json format with keys containing underscores. This is tested using the code example presented below, where we run into the following assert:

   terminate called after throwing an instance of 'dealii::ParameterHandler::ExcEntryUndeclared'
  what():  
--------------------------------------------------------
An error occurred in line <1234> of file </home/magdalena/code/external_libs/dealii/source/base/parameter_handler.cc> in function
    void dealii::ParameterHandler::set(const std::string&, const std::string&)
The violated condition was: 
    false
Additional information: 
    You can't ask for entry <test
Aborted (core dumped)

When we switch to *.prm format, everything works as expected. We assume that there is an inconsistency in mangling/demangling between boost and deal.II for *.json files (and maybe also for *.xml files (?)). At the moment I don't have a solution for a quick fix, but since I think this might be a common use case, I wanted to report this issue. We could at least add an appropriate assert. I will look into it asap.

@j-brotz FYI

Test code

#include <deal.II/base/parameter_handler.h>
#include <fstream>
#include <iostream>

using namespace dealii;

int
main(int argc, char *argv[])
{
  ParameterHandler prm;

  double test_0 = 0;

 // test if underscore can be parsed
  prm.add_parameter("test_0", test_0);
  
  std::ifstream file;
  file.open(argv[1]);
  prm.parse_input_from_json(file);

  prm.print_parameters(std::cout, ParameterHandler::OutputStyle::ShortJSON);

  return 0;
}

tested with the file test.json

{
 "test_0": "1"
}
@mschreter mschreter changed the title ParameterHandler: Problem with parsing keys containing underscores in *.json files ParameterHandler: *.json files with keys containing underscores cannot be parsed Jan 10, 2024
@bangerth bangerth added this to the Release 9.6 milestone Jan 10, 2024
@marcfehling
Copy link
Member

marcfehling commented Jan 10, 2024

As far as I remember, for xml the parameter names need to be mangled. Internally, we use the same xml algorithms internally to create the json format, so for json those had to be mangled as well.

Could you try a parameter file like:

{
 "test_5f0": "1"
}

See also #11342 and #5993

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants