Simple Inputxml Template

Input Template

A frequent task in scientific computer simulation is to do many similar calculations, where one needs to vary only one or a few parameters. We refer to this method as the aggregate properties. The preferred way to solve this to us is using XML and XSLT templates.

inputtemplate.png

An example for such a parameter set may be

<?xml version="1.0" encoding="UTF-8" ?>
 <experiment>
   <set rgkmax="9" />
    <set rgkmax="10" />
    <set rgkmax="11" />
    <set rgkmax="12" />
 </experiment>

It is a convergence test for rgkmax.

The template is a input file where you want to replace the rgkmax attribute by the value of the set and create a separate file and working directory for each calculation. lets again use the aluminum example:

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" />
<xsl:template match="/">
 
<!-- Authors: chm, jus, sag -->
 
<!--/////////////////////////////////////////////////////////////////////////-->
<!--/// define the name of the input file ///////////////////////////////////-->
<!--/////////////////////////////////////////////////////////////////////////-->
<xsl:variable name="inputfilename"><xsl:text>input.xml</xsl:text></xsl:variable>
 
<!-- Loop over all elements named "set" from reference xml-file -->
<xsl:for-each select = "/experiment/set">
 
  <!-- Define path here -->
  <xsl:variable name="path">
      <xsl:text>./</xsl:text>
      <xsl:for-each select="./@*">
        <xsl:variable name="attr"><xsl:value-of select="name()"/></xsl:variable>
        <xsl:if test="$attr!='id'">
          <xsl:value-of select="name()"/><xsl:text>_</xsl:text>
          <xsl:value-of select="."/>
          <xsl:text>/</xsl:text>
        </xsl:if>
      </xsl:for-each>
      <xsl:value-of select="$inputfilename"/>
  </xsl:variable>
 
 <!-- Write document at Path $path -->
  <xsl:document href="{$path}" method="xml" indent="yes">
 <xsl:comment>
 This file is generated with XSLTPROC using a template file and a reference file
 All parameters from the set filled in by XSLTPROC are listed below:
<!-- list all attributes in input file -->
<xsl:for-each select="./@*">
<xsl:text> </xsl:text>  
<xsl:value-of select="name()"/><xsl:text> </xsl:text>
<xsl:value-of select="."/><xsl:text>
</xsl:text>
</xsl:for-each><xsl:text></xsl:text>  
</xsl:comment>
<!-- ////////////////////////////////////////////////////////////////////////-->
<!-- /// The input file begins here /////////////////////////////////////////-->
<!-- ////////////////////////////////////////////////////////////////////////-->
 
<input xsi:noNamespaceSchemaLocation="excitinginput.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<title>
<xsl:text>Aluminum </xsl:text>
<xsl:value-of select="position()"/>
</title>
<structure>
<crystal scale="3.75">
<basevect>1.0  1.0  0.0</basevect>
<basevect>  1.0  0.0  1.0</basevect>
<basevect>  0.0  1.0  1.0</basevect>
</crystal>
<species speciesfile="Al.xml">
<atom coord="0.0  0.0  0.0" bfcmt="0.0  0.0  0.0"></atom>
</species>
</structure>
 
<groundstate  fromscratch="true" vkloff="0.5  0.5  0.5"   mixer="msec" ngridk="4  4  4">
  <xsl:attribute name="rgkmax"><xsl:value-of select="@rgkmax"/></xsl:attribute>
</groundstate>
</input>
 
<!-- ////////////////////////////////////////////////////////////////////////-->
<!-- /// The input file ends here ///////////////////////////////////////////-->
<!-- ////////////////////////////////////////////////////////////////////////-->
 
</xsl:document>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

The lines where the actual insertion of the rgkmax happens are:

<groundstate solver="Arpack" fromscratch="true" vkloff="0.5  0.5  0.5"   mixer="msec" ngridk="4  4  4">
  <xsl:attribute name="rgkmax"><xsl:value-of select="@rgkmax"/></xsl:attribute>
</groundstate>

The xsl:attribute element will add the rgkmax attribute to its enclosing tag (groundstate).

This template is actually also able to replace many values in the input file and it will create a directory tree resembling the chosen parameters

Generate parameter sets

The simple format of the param sets file can be generated by hand or by some script. If you need a calculation for all permutation of a group of parameters, check Expand All Parameter Permutations.

Generate Jobfile for Cluster

Loadleveler multistep job template

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License