Tutorials:ToolsHOWTO

From ALPS
Jump to: navigation, search

A number of tools and XSLT stylesheets are being developed to simplify working with the XML files created by the ALPS libraries and programs. Please checkout some XML plot file examples.

archive

archivecat

Usage:

archivecat filename [filename [filename ...]] 

archivecat takes a list of XML files containing results of simulation checkpoints in a <SIMULATION> element of the QMCXML schema. The tool strips off the leading processing instructions and wraps the various simulations inside a <ARCHIVE> element. This archive of simulation results can then be used by XSLT transformers, using for example the stylesheets provided below.

xslttransform

xslttransform is a wrapper for XSLT processors to provide a uniform interface. The usage is:

xslttransform file [stylesheet] 

If the stylesheet argument is not given, the default stylesheet is taken from the XML input file.

The XSLT processor is chosen as follows:

  • If the environment variable ALPS_XSLT_TRANSFORMER is defined, the program it points to is used as transformer
  • Otherwise the standard path is searched for the Gnome xsltproc from http://xmlsoft.org/XSLT/.
  • If xsltproc is not found, the standard path is searched for xalan from the Apache project.
extracttext

extracttext is a script which takes an XML plot file following the XML schema for plot data and an XML archive file containing results of simulation checkpoints in a <SIMULATION> element of the QMCXML schema as provided by archivecat. Alternatively a list of XML task files can be processed which the script wraps into an archive using archivecat.

The tool first parses the plot file using plot2xsl.xsl generating a temporary settings file plotsettings.xsl which is subquently used by archive2plot.xsl to extract the specified data into a temporary plot file following the XML schema for plot data. In a last step plot2text.xsl is invoked to transform the temporary plot file into tabular plain text output.

Alternative usage:

extracttext plot-filename archive-filename
extracttext plot-filename task-filename [task-filename [task-filename ...]]
extracthtml

extracthtml is a script which offers the same functionality as extracttext with the exception of converting the temporary plot file into tabular HTML output.

Alternative usage:

extracthtml plot-filename archive-filename
extracthtml plot-filename task-filename [task-filename [task-filename ...]] 
plot2text

Usage:

plot2text filename 

takes a XML plot file as argument and transforms it into tabular plain text output.

plot2html

Usage:

plot2html filename 

takes a XML plot file as argument and transforms it into tabular HTML output.

XSLT stylesheets

XSLT transformations are the easisest way of extracting specific information from the large XML output files produced by thye ALPS libraries and programs. While we are working on a more flexible set of tools we provide some examples of simple XSLT style sheets that can help the beginning XSLT user:

plot2xsl.xsl

plot2xsl is an XSLT stylesheet to extract information from an XML plot file following the XML schema for plot data which specifies which information from a Monte Carlo output file should be extracted by the XSLT stylesheet archive2plot.xsl. The information is temporarily stored in yet another XSLT stylesheet (plotsettings.xsl).

archive2plot.xsl

archive2plot.xsl is an XSLT stylesheet to extract information from a Monte Carlo output file and plot the value of a measured quantity as a function of a parameter, another measured quantity or an index as specified in the included XSLT stylesheet plotsettings.xsl generated by plot2xsl.xsl. This information is stored in a file following the XML schema for plot data.

plot2text.xsl

plot2text.xsl takes the output of e.g. the archive2plot.xsl transformation, stored in a file following the XML schema for plot data and converts it to tabular plain text output.

plot2html.xsl

plot2html.xsl takes the output of e.g. the archive2plot.xsl transformation, stored in a file following the XML schema for plot data and converts it to tabular HTML output. This is also the default stylesheet attached with the output of archive2plot.xsl to allow easy viewing in an XSLT supporting web browser. These stylesheets are installed in the xml subdirectory of the library installation directory.

We encourage your participation in the development of more flexible and powerful XSLT transformation tools.

XML plot file examples
  • Example 1: Energy versus temperature
   <?xml version="1.0" encoding="UTF-8"?>

   <plot name="Energy versus temperature for some model">
 
     <legend show="true"/>
     <xaxis label="Temperature" type="PARAMETER" name="T"/>
     <yaxis label="Energy"      type="SCALAR_AVERAGE"/>  

     <set label="sprint "/>

   </plot> 
  • Example 2: Energy versus temperature for all system sizes
   <?xml version="1.0" encoding="UTF-8"?>

   <plot name="Energy versus temperature for some model">

     <legend show="true"/>
     <xaxis label="Temperature" type="PARAMETER" name="T"/>
     <yaxis label="Energy"      type="SCALAR_AVERAGE"/>
      
     <for-each name="SystemSize"/>
       
     <constraint name="U"  condition="=3.0" />
     <constraint name="U'" condition="=4.0" />
     <constraint name="t"  condition="=1.0" />
     <constraint name="t'" condition="=2.0" />

     <constraint name="Energy"  type="SCALAR_AVERAGE" condition="<0" />

     <set label="start "/>

   </plot> 

Constraints used in this example

The first constraint <for-each name="SystemSize"/> used in this example describes a loop over all possible values of the specified parameter. In the given example multiple sets are generated one for each system size found in the archive. The second set of constraints, e.g. <constraint name="U" condition="=3.0" />, is used to specify a set of parameters, such as U=3.0 U'=4.0 t=1.0 t'=2.0 in the given example. The last constraint <constraint name="Energy" type="SCALAR_AVERAGE" condition="<0" /> restricts the energy range to negative values. The set label will be automatically generated from the prefix label label="start " in the set description and all the given constraints.

  • Example 3: Green's function versus distance
   <?xml version="1.0" encoding="UTF-8"?>

   <plot name="Green's function versus distance for some model">

     <legend show="true"/>
     <xaxis label="Distance" type="INDEX"/>
     <yaxis label="Green's function" type="VECTOR_AVERAGE"/>

     <constraint label="d" type="INDEX" condition=">=2" />
     <constraint label="d" type="INDEX" condition="<5" />

     <set label="Some parameters of interest"/>
   </plot> 

Constraints used in this example

With the two index constraints shown in this example only Green's functions for distances d=2,3,4 are shown.

  • Example 4: Winding number versus energy
   <?xml version="1.0" encoding="UTF-8"?>

   <plot name="Winding number^2 versus energy for some model">

     <legend show="true"/>
     <xaxis label="Energy" type="SCALAR_AVERAGE"/>
     <yaxis label="Winding number^2" type="VECTOR_AVERAGE" index="0"/>

     <set label="Not neccessarily useful"/>
   </plot> 

Using libxml and php

It may be convenient to extract XML simulation results using a php script: This script finds the parameter MU in the parameter section of the xml document, and then looks through all entries of the vector observable Sz0_Szj and writes them to the standard output.

You will need php and libxml to run this script.

<?php

$doc = new DOMDocument();
$doc->load($argv[1]);
$xpath = new DOMXPath($doc);

//header("Content-type: text/plain; charset=utf-8;");
foreach($xpath->query("/SIMULATION/PARAMETERS/PARAMETER[@name='MU']") as $MUnode){
  echo $MUnode->textContent . " ";
}
foreach ($xpath->query("/SIMULATION/AVERAGES/VECTOR_AVERAGE[@name='Sz0_Szj']/SCALAR_AVERAGE") as $entry) {
  echo $entry->getAttribute("indexvalue") . " ";
  echo $MU . " ";
  foreach ($entry->childNodes as $node) {
    if ($node->nodeName == "MEAN")
      echo $node->textContent . " ";
    if ($node->nodeName == "ERROR")
      echo $node->textContent . "\n";
  }
}
?>

Use php this_script.php xml_file.xml to run the php script.

copyright (c) 1994-2003 by Matthias Troyer and Simon Trebst