Unit test in user project with .prm and .data input files to be read

154 views
Skip to first unread message

Vinayak Gholap

unread,
Oct 4, 2017, 6:03:57 AM10/4/17
to deal.II User Group
Hello all,

I want to set up a unit test where I read input parameters from *.prm file and some input data from a *.data file. I have a single .cc file. Until now without the *.data input file my unit test would run successfully via the "Setting up testsuite in user projects -> Simple Configuration".

For inclusion of input from my *.data file in unit test how can I use the Advanced Configuration setup in this case? I have already implemented a function in my .cc file to read the .data file input.

Thanks in advance!

Regards,
Vinayak Gholap

Daniel Arndt

unread,
Oct 4, 2017, 2:37:23 PM10/4/17
to deal.II User Group
Vinayak,

you should be able to use the SOURCE_DIR preprocessor variable for this purpose.
Have a look at the test parameter_handler/parameter_handler_01 [1] for example.

Best,
Daniel

[1] https://github.com/dealii/dealii/blob/2b9d1c13eea9cc28ad0b757c031d2e61bdb31fc1/tests/parameter_handler/parameter_handler_1.cc

Denis Davydov

unread,
Oct 4, 2017, 4:31:43 PM10/4/17
to deal.II User Group
Hi Vinayak,

Indeed, something like

 SOURCE_DIR + "/relative/path/to/auxiliary_files.dat"

is what you need.

Regards,
Denis.

Vinayak Gholap

unread,
Oct 5, 2017, 8:28:18 AM10/5/17
to deal.II User Group
Hello Daniel,

as I understand this function is to include the .prm file input data. What I have is inside my .prm file:

subsection  somedata
    set input file = xyz.data
end

I read this input string from .prm and via my own implemented function read this xyz.data file. The problem occurs when doing unit test for different .prm input files it cannot read this xyz.data file. The different .prm files are considered by the unit test but the xyz.data within each .prm file is not read.

Regards,
Vinayak Gholap


On Wednesday, October 4, 2017 at 8:37:23 PM UTC+2, Daniel Arndt wrote:

Daniel Arndt

unread,
Oct 5, 2017, 9:16:01 AM10/5/17
to deal.II User Group
Vinayak,


as I understand this function is to include the .prm file input data. What I have is inside my .prm file:

subsection  somedata
    set input file = xyz.data
end

I read this input string from .prm and via my own implemented function read this xyz.data file. The problem occurs when doing unit test for different .prm input files it cannot read this xyz.data file. The different .prm files are considered by the unit test but the xyz.data within each .prm file is not read.
I would still expect this to work using SOURCE_DIR. Namely, you should be able to read you parameter file similar to

std::ifstream in(SOURCE_DIR "parameters.prm");
prm.read_input (in);

and then extract the relevant data file similar to

const std::string data_file = std::string(SOURCE_DIR) + prm.get("input file");

Best,
Daniel

Vinayak Gholap

unread,
Oct 6, 2017, 8:30:45 AM10/6/17
to deal.II User Group
Hello Daniel,

I tried as suggested by you. But the tests fail with below exception

 ----------------------------------------------------
1: Exception on processing:
1:
1: --------------------------------------------------------
1: An error occurred in line <3059> of file </home/vinayak/spack/var/spack/stage/dealii-develop-7cbhdrgdyye44wfu4cmyexwzxauxx6n4/dealii/source/base/parameter_handler.cc> in function
1:     void dealii::ParameterHandler::scan_line(std::__cxx11::string, const string&, unsigned int)
1: The violated condition was:
1:     false
1: Additional information:
1:     Line <1> of file <input file>: The line
1:
1:         <LAMMPS Description>
1:
1: could not be parsed: please check to make sure that the file is not missing a 'set', 'include', 'subsection', or 'end' statement.
1: --------------------------------------------------------
1:
1: Aborting!
1: ----------------------------------------------------
1: terminate called after throwing an instance of 'dealii::ParameterHandler::ExcCannotParseLine'
1:   what(): 
1: --------------------------------------------------------
1: An error occurred in line <3059> of file </home/vinayak/spack/var/spack/stage/dealii-develop-7cbhdrgdyye44wfu4cmyexwzxauxx6n4/dealii/source/base/parameter_handler.cc> in function
1:     void dealii::ParameterHandler::scan_line(std::__cxx11::string, const string&, unsigned int)
1: The violated condition was:
1:     false
1: Additional information:
1:     Line <1> of file <input file>: The line
1:
1:         <LAMMPS Description>
1:
1: could not be parsed: please check to make sure that the file is not missing a 'set', 'include', 'subsection', or 'end' statement.
1: --------------------------------------------------------

My *.data file has following which needs to be considered during unit test:

LAMMPS Description

     2  atoms
     0  bonds
     0  angles
     0  dihedrals
     0  impropers

     2  atom types

  0.0 1.0 xlo xhi
  0.0 1.0 ylo yhi
  0.0 1.0 zlo zhi

Masses

      1        22.989
      2     35.453

Atoms # full
....

Regards,
Vinayak Gholap

Daniel Arndt

unread,
Oct 6, 2017, 9:09:33 AM10/6/17
to deal.II User Group
Vinayak,

Your error looks like you are trying to call read_input on your data file instead of the parameter file.
At least you seem to be able to find the correct path to your data file in the unit test and this is what this thread
is about, isn't it?

Do you have a working setting (without the testsuite setup) for which you can treat your data file appropriately?
If this works, we can try to find out why it doesn't work using the testuite setting.

Best,
Daniel

Vinayak Gholap

unread,
Oct 6, 2017, 10:18:24 AM10/6/17
to deal.II User Group
Hello Daniel,


On Friday, October 6, 2017 at 3:09:33 PM UTC+2, Daniel Arndt wrote:
Vinayak,

Your error looks like you are trying to call read_input on your data file instead of the parameter file.
At least you seem to be able to find the correct path to your data file in the unit test and this is what this thread
is about, isn't it?

I tried to parse the .prm file but still the unit test fail. And yes I am able to find the correct path to my data file but not able to run unit test with it.

Do you have a working setting (without the testsuite setup) for which you can treat your data file appropriately?
If this works, we can try to find out why it doesn't work using the testuite setting.
 
Yes I have a working setting where I am able to read different data files for different .prm files and they work as expected for all.

Regards,
Vinayak Gholap

Daniel Arndt

unread,
Oct 6, 2017, 11:34:56 AM10/6/17
to deal.II User Group
Vinayak,

Your error looks like you are trying to call read_input on your data file instead of the parameter file.
At least you seem to be able to find the correct path to your data file in the unit test and this is what this thread
is about, isn't it?

I tried to parse the .prm file but still the unit test fail. And yes I am able to find the correct path to my data file but not able to run unit test with it.
So again: Are you calling read_input for the parameter file or the data file? How does your setup actually look like?
Is it similar to the one I suggested above?
 

Do you have a working setting (without the testsuite setup) for which you can treat your data file appropriately?
If this works, we can try to find out why it doesn't work using the testuite setting.
 
Yes I have a working setting where I am able to read different data files for different .prm files and they work as expected for all.
Then, the code should be identical apart from putting SOURCE_DIR in the places where you are reading the parameter file and the data file.
Is this the case?

If this doesn't help, can you come up with a minimal example version of the setup you are using?

Best,
Daniel

Denis Davydov

unread,
Oct 6, 2017, 2:23:35 PM10/6/17
to deal.II User Group
Vinayak,

You are mixing several things, it seems.
What you should do in your unit test is something along the lines:
      
      ParameterHandler prm;
     
MyLovelyParameters::declare_parameters(prm);

     
// parameters
      std
::ostringstream oss;
      oss
<< "set Something = 3"                           << std::endl
         
<< "set LAMMPS input  = " << SOURCE_DIR << "/relative/path/to/input.xyz" << std::endl;

      prm
.parse_input_from_string(oss.str().c_str());

     
// use it to do the same as in main.cc
     
// (depends on how things are implemented)

Obviously, you need to adjust this code to what you are actually doing.

The point is, dealII have functionality to run user tests in two ways:
1) take the main executable and pass .rpm file as an argument
This won't work when you need some auxiliary data which is a part of the test.
That is because you don't know the path from which the test will be executed.

2) compile .cc file and run it. In this case, you should populate whatever parameter 
within that .cc file. But this also requires that you separate your program into a library (say with a single class Problem) and
executable main.cc which actually creates an instance of that class and runs it.
So what you do here is essentially the same thing as your main.cc but you feed parameters NOT from the command line argument,
but create them yourself dynamically (SOURCE_DIR will be dynamic macro depending on where you actually configure/build).

Regards,
Denis

Vinayak Gholap

unread,
Oct 12, 2017, 6:13:11 AM10/12/17
to deal.II User Group
Hello Daniel,

I have attached the test.cc (in my case gaussian-charges.cc) , .prm and .data input files. With this setup for test it fails.

Could you help?

Regards,
Vinayak Gholap
atom_2.data
gaussian-charges.cc
gaussian-charges.prm

Denis Davydov

unread,
Oct 12, 2017, 7:34:10 AM10/12/17
to deal.II User Group
Vinayak,

I don't think it's appropriate to request other developers to help you fix your unit test. 
I think both myself and Daniel explained that you need to use the preprocessor variable in your .cc unit tests.
If you have problems getting it right, then it should be trivial to debug: you just check what you write as a path within your .cc file and compare
that to your directory structure. Do you point to the file which exists? Is it the right file? 
You can also run tests in verbose mode to help with this task: ctest -V -R "some/regex"
"Setting up testsuite in user projects" https://www.dealii.org/developer/index.html gives code snippets and explains 
how to setup a  user project into a library+executable.

Note that everyone here in the forum helps others voluntarily. So it's a place to ask questions and seek for advice, 
but the place to ask others to solve your task for you.
Also make sure you read this guidelines post: https://groups.google.com/forum/?fromgroups#!topic/dealii/GRZMUTLIm2I

Regards,
Denis.

Denis Davydov

unread,
Oct 12, 2017, 7:36:48 AM10/12/17
to dea...@googlegroups.com

On 12 Oct 2017, at 13:34, Denis Davydov <davy...@gmail.com> wrote:

Vinayak,

I don't think it's appropriate to request other developers to help you fix your unit test. 
I think both myself and Daniel explained that you need to use the preprocessor variable in your .cc unit tests.
If you have problems getting it right, then it should be trivial to debug: you just check what you write as a path within your .cc file and compare
that to your directory structure. Do you point to the file which exists? Is it the right file? 
You can also run tests in verbose mode to help with this task: ctest -V -R "some/regex"
"Setting up testsuite in user projects" https://www.dealii.org/developer/index.html gives code snippets and explains 
how to setup a  user project into a library+executable.

Note that everyone here in the forum helps others voluntarily. So it's a place to ask questions and seek for advice, 
but the place to ask others to solve your task for you.

but NOT the place...

--
The deal.II project is located at http://www.dealii.org/
For mailing list/forum options, see https://groups.google.com/d/forum/dealii?hl=en
---
You received this message because you are subscribed to a topic in the Google Groups "deal.II User Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/dealii/6YgunmMhva0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to dealii+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages