Aspects of the Class Structure in Chroma Bálint Joó Jefferson Lab, Newport News, VA given at HackLatt'06 NeSC, Edinburgh March 29, 2006.

Slides:



Advertisements
Similar presentations
Chapter 1 Object-Oriented Concepts. A class consists of variables called fields together with functions called methods that act on those fields.
Advertisements

Overview of Data Structures and Algorithms
ITEC200 – Week03 Inheritance and Class Hierarchies.
x – independent variable (input)
Object-Oriented PHP (1)
Inheritance. Extending Classes It’s possible to create a class by using another as a starting point  i.e. Start with the original class then add methods,
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Testing an individual module
CS 2511 Fall  Abstraction Abstract class Interfaces  Encapsulation Access Specifiers Data Hiding  Inheritance  Polymorphism.
Sunday, 12 July 2015 BNL Domain Wall Fermions and other 5D Algorithms A D Kennedy University of Edinburgh.
I/O and the SciDAC Software API Robert Edwards U.S. SciDAC Software Coordinating Committee May 2, 2003.
13-Jul-15 Refactoring II. Books Design Patterns is the classic book by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides Basically a catalog.
 By Wayne Cheng.  Introduction  Five Tenets  Terminology  The foundation of C++: Classes.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
CSC 8310 Programming Languages Meeting 2 September 2/3, 2014.
Introduction To System Analysis and design
C++ Object Oriented 1. Class and Object The main purpose of C++ programming is to add object orientation to the C programming language and classes are.
MIT AITI 2002 Abstract Classes, Interfaces. Abstract Classes What is an abstract class? An abstract class is a class in which one or more methods is declared,
CompuCell Software Current capabilities and Research Plan Rajiv Chaturvedi Jesús A. Izaguirre With Patrick M. Virtue.
CSE 332: C++ templates This Week C++ Templates –Another form of polymorphism (interface based) –Let you plug different types into reusable code Assigned.
Inheritance. Recall the plant that we defined earlier… class Plant { public: Plant( double theHeight ) : hasLeaves( true ), height (theHeight) { } Plant(
1 Abstraction  Identify important aspects and ignore the details  Permeates software development programming languages are abstractions built on hardware.
Chroma I: A High Level View Bálint Joó Jefferson Lab, Newport News, VA given at HackLatt'06 NeSC, Edinburgh March 29, 2006.
Recap (önemli noktaları yinelemek) from last week Paradigm Kay’s Description Intro to Objects Messages / Interconnections Information Hiding Classes Inheritance.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
My talk describes how the detailed error diagnosis and the automatic solution procedure of problem solving environment T-algebra can be used for automatic.
Knowledge Technologies March 2001 DataChannel, Inc Preserving Process Hyperlink-Based Workflow Representation W. Eliot Kimber, DataChannel, Inc.
 Three-Schema Architecture Three-Schema Architecture  Internal Level Internal Level  Conceptual Level Conceptual Level  External Level External Level.
The european ITM Task Force data structure F. Imbeaux.
C++ History C++ was designed at AT&T Bell Labs by Bjarne Stroustrup in the early 80's Based on the ‘C’ programming language C++ language standardised in.
Copyright © Curt Hill Generic Classes Template Classes or Container Classes.
Genericity Ranga Rodrigo Based on Mark Priestley's Lectures.
1 Inheritance. 2 Why use inheritance?  The most important aspect of inheritance is that it expresses a relationship between the new class and the base.
ADTs and C++ Classes Classes and Members Constructors The header file and the implementation file Classes and Parameters Operator Overloading.
Objects & Dynamic Dispatch CSE 413 Autumn Plan We’ve learned a great deal about functional and object-oriented programming Now,  Look at semantics.
Programming in Java CSCI-2220 Object Oriented Programming.
Object Oriented Software Development
Chroma: An Application of the SciDAC QCD API(s) Bálint Joó School of Physics University of Edinburgh UKQCD Collaboration Soon to be moving to the JLAB.
Magnetic Field Issues for Simulation and Reconstruction N. Amapane, N. Neumeister Workshop on LHC Physics with High-p T Muons in CMS Bologna, April 9-12,
SciDAC Software Infrastructure for Lattice Gauge Theory Richard C. Brower QCD Project Review May 24-25, 2005 Code distribution see
Computer Science Projects Internal Assessment. Mastery Item Claimed Justification Where Listed Random Access File – Searching Lines P. 53 Random.
Lecture 18 Windows – NT File System (NTFS)
M1G Introduction to Programming 2 5. Completing the program.
Interfaces About Interfaces Interfaces and abstract classes provide more structured way to separate interface from implementation
Object-Oriented Programming © 2013 Goodrich, Tamassia, Goldwasser1Object-Oriented Programming.
C++ Inheritance Data Structures & OO Development I 1 Computer Science Dept Va Tech June 2007 © McQuain Generalization versus Abstraction Abstraction:simplify.
M1G Introduction to Programming 2 3. Creating Classes: Room and Item.
Polymorphism, Virtual Methods and Interfaces Version 1.1.
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Today: –Review declaration, implementation, simple class structure. –Add an exception class and show.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Inheritance and Class Hierarchies Chapter 3. Chapter Objectives  To understand inheritance and how it facilitates code reuse  To understand how Java.
Classes, Interfaces and Packages
Version Control and SVN ECE 297. Why Do We Need Version Control?
Slides prepared by Rose Williams, Binghamton University Chapter 16 Collections and Iterators.
Duke CPS Programming Heuristics l Identify the aspects of your application that vary and separate them from what stays the same ä Take what varies.
Unified Modeling Language (UML)
C# Fundamentals An Introduction. Before we begin How to get started writing C# – Quick tour of the dev. Environment – The current C# version is 5.0 –
Mr H Kandjimi 2016/01/03Mr Kandjimi1 Week 3 –Modularity in C++
Behavioral Design Patterns
Lecture 2 of Computer Science II
Object-Oriented Programming
Domain Wall Fermions and other 5D Algorithms
Chroma: An Application of the SciDAC QCD API(s)
Introduction to Data Structure
ENERGY 211 / CME 211 Lecture 27 November 21, 2008.
Chapter 8 - Design Strategies
C++ Object Oriented 1.
Jim Fawcett CSE687 – Object Oriented Design Spring 2015
Presentation transcript:

Aspects of the Class Structure in Chroma Bálint Joó Jefferson Lab, Newport News, VA given at HackLatt'06 NeSC, Edinburgh March 29, 2006

Philosophy Code as much as possible in terms of abstract / base classes and virtual functions As classes are derived try and write 'defaults' Try to write things only once. Refactor rather than duplicate and extend Aldor category default influence Force type correctness where possible using the Covariant return rule Mirrored hierarchy trees XML and factories - polymorphism of parameters

A Broad Overview of the Base Classes LinearOperato r ConnectStat e SystemSolve r GaugeActi on FermionActio n GaugeBC FermBC InlineMeasurement creates uses aggregates AbsMonomial AbsHamiltonian AbsFieldState AbsMDIntegrato r AbsHMCTrj AbsChronologicalPredictor

ConnectState In order to be useful raw gauge field states need extra info eg: Boundary conditions link smearing eigenvectors/values ConnectState manages this Created by FermionAction // Raw Gauge Field multi1d u(Nd); FermionAction& S =...; Handle state( S.createState(u) ); Handle > S.linOp(state); Raw Field Knows about BC-s Factory Function: applies BC-s to field LinearOperator gets field with BCs applied

ConnectState Some Derivations of ConnectState SimpleConnectState (just u and BCs) EigenState (u and e-values & vectors) StoutState (in development) OverlapState( deprecated older version of EigenState) Member Functions: getLinks() - return internal fields deriv() - force w.r.t thin (unsmeared links)

FermBCs Interface for applying fermionic BCs Templated on type of FermionField Produced by factory Managed/Used by FermionAction and other GaugeBCs and FermBCs (eg Schroedinger Functional) Main memebrs: modifyU(u) – Apply boundaries to gauge field modifyF(psi) – Apply boundaries to fermion field zero(F) – Zero Force on boundary (eg Schroedinger functional)

LinearOperator BaseType for matrices Templated on Fermion Type Function Object ( has overloaded operator() ) template class LinearOperator { public: virtual void operator() (T& chi, const T& psi, enum PlusMinus isign) const = 0; virtual const OrderedSubset& subset() const = 0; //... others omitted for lack of space }; PLUS apply M MINUS apply M + Know which subset to act on Source Vector Target Vector

LinearOperator Created by FermionAction (factory method) Typical Use Pattern: // Raw Gauge Field multi1d u(Nd); FermionAction& S =...; Handle state( S.createState(u) ); Handle > M( S.linOp(state) ) ; LatticeFermion y, x; gaussian(x); (*M)(y, x, PLUS); Create state for Fermion Kernel Create LinearOperator (fix in links) De-reference Handle and apply lin. op: y = M x

Some Derivations of LinearOperator DiffLinearOperator + deriv() - time “derivative” LinearOperator operator() = 0- apply subset() =0 - working subset UnprecLinearOperator *subset() = all EvenOddPrecLinearOperator +evenEvenLinOp()=0,+evenOddLinOp()=0 +oddEvenLinOp()=0, +oddOddLinOp()=0 +evenEvenInvLinOp()=0, +derivEvenEvenLinOp()=0 +derivOddOddLinOp()=0, +derivEvenOddLinOp()=0 +derivOddEvenLinOp()=0, *operator() *unprecLinOp() *derivUnprecLinOp() *subset() = rb[1] – odd subset Default Implentation through virtual functions EvenOddPrecConstDetLinearOperator *deriv() - Default Force implementation EvenOddPrecLogDetLinearOperator *deriv() - Default Force implementation +derivEvenEvenLogDet() = 0 +logDetEvenEven() = 0 EvenOddLinearOperator +evenEvenLinOp()=0,+evenOddLinOp()= 0 +oddEvenLinOp()=0, +oddOddLinOp()=0 +derivEvenEvenLinOp()=0 +derivOddOddLinOp()=0, +derivEvenOddLinOp()=0 +derivOddEvenLinOp()=0, *operator(), *deriv(),*subset() Even-Odd without preconditioning eg staggered eg: clover Schur preconditioning: M=A oo - A oe A ee -1 A eo A ee is gauge independent: eg Wilson Type of momenta

Linear Operators Similar hierarchy is mirrored with 5D variants convention XXXLinOpArray in name Key points Differentiable Linear operator knows how to take derivative wrt to embedded gauge field the second step of chain rule done by ConnectState (deriv wrt thin links) Wilsonesque Hierarchy follows (4D Schur like) Even Odd preconditioning (rather than Hermiticity etc) Workhorse of the fermion sector.

Fermion Actions Manages related Linear Operators, States and propagator Inverters Created by Factory pattern Not “action” in the true sense, does not know about flavour structure (see monomials later) Fermion Action FermBC ConnectState createState() linOp() lMdagM() qprop() quarkProp() LinearOperator (M + M) LinearOperator (M) SystemSolver creates forward s is used by The Fermion Matrix M + M may be optimised (eg overlap) Computes 1 component of propagator Does all components

4D Derivations of Fermion Action FermionAction createState() linOp()=0 lMdagM() = 0 qprop()=0 quarkProp() FermAct4D +getFermBC()=0 *createState() (DiffLinOp) WilsonTypeFermAct +hermitianLinOp() (eg  5 ) (E/O Prec. LinOp) EvenOddPrecWilsonTypeFermAct (E/O Prec. Const. Det. LinOp) (E/O Prec. Log. Det. LinOp) Legend: +extends

5D Derivations of Fermion Action FermionAction createState() linOp()=0 lMdagM() = 0 qprop()=0 quarkProp() FermAct5D +getFermBC()=0 multi1d +linOpPV() (DiffLinOp) WilsonTypeFermAct5D +hermitianLinOp() (eg  5 ) *lMdagM() +linOp4D() +DeltaLs() E/O Prec. E/O Prec LinOp EvenOddPrecWilsonTypeFermAct5D E/O Prec. Const. Det. E/O Prec Const Det LinOp E/O Prec. Log. Det. E/O Prec Log Det LinOp Legend: +extends

Staggered Derivations of FermionAction FermionAction createState() linOp()=0 lMdagM() = 0 qprop()=0 quarkProp() FermAct4D +getFermBC()=0 *createState() (DiffLinOp) E/O LinOp EvenOddPrecStaggeredTypeFermAct +getQuarkMass()

Notes on Fermion Action From DiffFermAct onwards, inheritence tree shadows inheritance of Linear Operators. Travelling towards the leaves of inheritance tree Type “Restriction” allows specialisation of say qprop() Travelling towards root of the tree Type information loss Don't know which branch we came up on Need C++ RTTI to be able to recover type info Use C++ dynamic_cast<> mechanism to attempt to go down a particular branch

HMC Sector Actual HMC part is quite simple – mostly in terms of abstract classes Key classes: Monomial, Hamiltonian, FieldState Integrator, HMC The code for this is in chroma/lib/update/molecdyn AbsMonomial AbsHamiltonian AbsFieldState AbsMDIntegrato r AbsHMCTrj AbsChronologicalPredictor

AbsFieldState This state of fields is a phase space field state The templates P and Q specify types of canonical momenta and coordinates GaugeFieldState – specialises P and Q to be of type multi1d The HMC related classes act on AbsFieldState-s AbsHamiltonian and AbsMonomial compute things on states AbsHMCTrj and AbsIntegrator evolve the states

Hamiltonians and Monomials We evolve the Hamiltonian System H(p,q) = (½) p 2 + ∑ i S i We refer to S i as Monomials (blame Tony!) In each Monomial can contribute MD Force Contribution to the Energy (if it is “exact”) In terms of classes the Hamiltonian aggregates the Forces and Energies of its component Monomials. The hard work is in the Monomials

Hamiltonian & Monomial AbsHamiltonian dsdq(F,s) dsdq(F,s,monomialList) refreshInternalFields() setInternalFields() numMonomials() ExactAbsHamiltonian +mesE(s) +mesKE(s) +mesPE(s) Monomial dsdq(F,s) refreshInternalFields( ) setInternalFields() ExactMonomial +S() FermMonomial ExactFermMonomial ExactFermMonomial4D ExactWilsonTypeFermMonomial5D getFermAct() (WilsonTypeFermAct5D) ExactWilsonTypeFermMonomial getFermAct() (WilsonTypeFermAct) GaugeMonomial - P,Q=LCM Pseudofermions - Internal forwards Exact – can compute energies Momenta are NOT internal This is Pseudofermion refreshment/copy only Update subset of monomials eg for multi timscale integration

Two Flavour Fermionic Monomials TwoFlavorExactWilsonTypeFermMonomial TwoFlavorExactEvenOddPrecWilsonTypeFermMonomial +S_even_even() = 0 +S_odd_odd() EvenOddPrecWilsonTypeFermAct TwoFlavorExactUnprecWilsonTypeFermMonomial UnprecWilsonTypeFermAct TwoFlavorExactEvenOddPrecConstDetWilsonTypeFermMonomial *S_even_even() - Trivial EvenOddPrecConstDetWilsonTypeFermAct TwoFlavorExactEvenOddPrecLogDetWilsonTypeFermMonomial *S_even_even() - Nontrivial (N f log det M ee ) EvenOddPrecLogDetWilsonTypeFermAct S f =   (M + M) -1 

Rational One Flavour Like Monomials S f =  ( M + M) -a/b  =  ( ∑ p i [ M + M + q i ] -1 )  a and b can be used to implement Nroots approach Rational approximation expressed as PFE Use Multi Mass Solver Internally Similar Hierarchy to Two Flavour Monomials Not yet split EvenOddPrec into ConstDet and LogDet

Hasenbusch Like Monomials S f =   [ M 2 ( M + M) -1 M 2 + ]  Implements Two Flavour Hasenbusch Like Ratio of determinants det(M + M) / det (M 2 + M 2 ) Does not automatically include term to cancel the determinant with M 2 Need to add this in with a normal 2 flavor monomial.

LogDetEvenEven Monomials A monomial that simulates det (M ee ) N = N log det M ee for Clover like actions (clover is only one so far) Factor even-even part of the clover term out and use Nroots or Hasenbusch acceleration for the odd- odd part only Downside: in clover case duplicates storage of clover term May also duplicate computation with EvenEven part

Chronological Solvers Two flavour monomials can make use of chronological predictors A chronological predictor is a solver starting guess STRATEGY Strategies available Zero Guess Previous Solution Linear Extrapolation from last two solutions Minimal Residual Extrapolation

MD Integrators Function objects -- ie use operator() destructively change/evolve AbsFieldState - s share crucial components in a namespace, eg: leapP() : p new = p old + dt F; leapQ(): q new = q old + dt p Integrators make use of Hamiltonian to compute forces for all of or some of the monomials Multi timescale integrators – Thanks Carsten! Can put sets of monomials on different timescales Cannot split a single (eg rational) monomial onto many timescales yet! This is work in progress.

Run time binding with XML Allows mix and match of fermion actions, boundaries, etc at run time. XML bound to strings in param structs. acts as polymorphic parameter structure. Factories used to create correct objects when needed WILSON LAST_SOLUTION_4D_PREDICTOR struct TwoFlavorWilsonTypeFermMonomialParams { TwoFlavorWilsonTypeFermMonomialParams(); // Constructor from XML TwoFlavorWilsonTypeFermMonomialParams( XMLReader& in, const std::string& path); InvertParam_t inv_param; std::string ferm_act; std::string predictor_xml; }; Factory product Key

“Inline” Measurements Originally designed to allow inline measurements from within gauge evolution algorithms Function objects operator() called to perform the measurements takes Output XML writer as parameter Communication between measurements through named objects essentially a virtual filesystem forced by slowness of QIO performance on QCDOC – writing objects to scratch directories takes the age of the universe

Named Objects Templated type to encapsulate objects Follows QIO structure: eg has File and Record XML Named objects stored in a map associates name with named object create/delete/lookup methods to manipulate map Special Inline Measurements to read/write objects to/from disk and named object maps. Divorces I/O from measurements completely Recent change: even input gauge field comes from named objects.

Named Objects in Code and XML eg: source creation: TheNamedObjMap::Instance().create (params.named_obj.source_id); TheNamedObjMap::Instance().getData (params.named_obj.source_id) = quark_source; TheNamedObjMap::Instance().get(params.named_obj.source_id).setFileXML(file_xml); TheNamedObjMap::Instance().get(params.named_obj.source_id).setRecordXML(record_xml); In XML: MAKE_SOURCE... sh_source PROPAGATOR... sh_source sh_prop_0 QIO_WRITE_NAMED_OBJECT... sh_prop_0 LatticePropagator./sh_prop_0 MULTIFILE MAKE_SOURCE creates object PROPAGATOR uses the source, creates prop Special “Measurement” Writes named object Also: Tasks to read and erase objects to/from map

Changes in the wind Like all codes Chroma too must evolve with the times I have described chroma v2 here. v3 is next WANTE D R.G. Edwards also known as THE CHROMA KID For wanton and deliberate overnight code- restructurings

Planned Changes to Class Structure in v3 Push boundary conditions into ConnectStates so we can deal correctly with non-trivial boundary conditions in the LinearOperator derivatives eg: Schrodinger Functional BCs so we can factor ConnectStates away from FermionActions eg: to do link smearing independent of FermionAction potentially need to impose BCs after every smearing iteration. Project driven – timing dictated by proposal deadline SF BCs needed for JLab aniso clover project

How the changes will look: CreateState FermBC FermState public: ConnectState Gauge Links (Q) operator()(Q& u) FermionAction LinearOperator linOp(FermState &) ConnectState generalised Holds FermBC Templated on Gauge Type (Q) Knows Derivative Type (P) “Curried Function” Function object binds BCs from XML. Makes FermState-s from Link Fields (Q) ie: factory function function object FermBC now contains fn-s to modify gauge field (Q) fermion field (T) and impose BC-s (zero) on derivative (P) Knock on effect template params for FermAct Diff LinearOperator not needed anymore all Fermion linOps considered differentiable. LinOp knows FermState and hence can deal with BC-s properly in derivatives

Comments Fix current ConnectState inconsitencies currently initialised with multi1d will change to template type Q consistent with HMC – evolution etc Inheritance with 5D FermActs wins nothing doesn't reduce duplication Uncouple – have FermActs and FermActArrays Maintain backward compatibility with XML structure and props etc. But not in the API, sorry.

Summary and Conclusions Simple structure in terms of base classes and virtual functions Virtual functions not used for speed critical operations – no big inefficiency is introduced. “Mirrored” hierarchy of derivations: Covariant Return Rule Nodes on class derivation tree supply default behaviour Detailed leaf-class object creation by factories. Run time “binding”

Summary and Conclusions II Crucial Interfaces LinearOperator Boundary Conditions ConnectState -s FermionAction-s Monomials Two flavour Rational Hasenbusch Gauge

Summary and Conclusion III Measurement Tasks Data flow through Named Objects Named Object I/O managed through special measurement tasks Visual Grid based Chroma anyone? General We have learned a lot about writing Object Oriented Lattice QCD software through writing Chroma Hopefully useful tool to community (definitely to us) We are continually working towards improvements