Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • normann/preprocessor
  • Dynare/preprocessor
  • FerhatMihoubi/preprocessor
  • MichelJuillard/preprocessor
  • sebastien/preprocessor
  • lnsongxf/preprocessor
  • albop/preprocessor
  • DoraK/preprocessor
  • amg/preprocessor
  • wmutschl/preprocessor
  • JohannesPfeifer/preprocessor
11 results
Select Git revision
Show changes
Commits on Source (2026)
Showing with 7226 additions and 709 deletions
# This file should be kept in sync with the one in dynare.git (which also
# contains more explanations).
Language: Cpp
Standard: c++20
ColumnLimit: 100
BasedOnStyle: GNU
AllowShortFunctionsOnASingleLine: None
AlwaysBreakTemplateDeclarations: Yes
BreakConstructorInitializers: AfterColon
BreakInheritanceList: AfterColon
Cpp11BracedListStyle: true
DeriveLineEnding: false
IndentPPDirectives: AfterHash
InsertNewlineAtEOF: true
PackConstructorInitializers: NextLine
PPIndentWidth: 1
PointerAlignment: Left
# RemoveParentheses: ReturnStatement
# RemoveSemicolon: true
SpaceAfterTemplateKeyword: false
SpaceBeforeParens: ControlStatements
SpaceBeforeCpp11BracedList: true
# TODO: add the following check families:
# - bugprone-*
# - cppcoreguidelines-
# NB: as of clang-tidy 16, we get several false positives inside boost, notably this one:
# https://github.com/llvm/llvm-project/issues/40486
Checks: 'performance-*,modernize-*,-modernize-use-trailing-return-type,-clang-diagnostic-unqualified-std-cast-call'
# For checking that no file has been unduly ignored, run:
# $ git ls-files -i --exclude-per-directory=.gitignore
# Any file that is displayed should be removed from the ignore list
# (possibly by an exclusion rule beginning with an exclamation mark)
# Generic ignore rules
*~
*.o
*.a
*.fig
\#*\#
# Build system rules
.deps
Makefile
Makefile.in
configure
config.log
config.status
aclocal.m4
autom4te.cache
config.guess
config.sub
depcomp
install-sh
/missing
/compile
ylwrap
ar-lib
# Preprocessor
/src/dynare_m
/src/dynare_m.exe
/src/DynareBison.cc
/src/DynareBison.hh
/src/FlexLexer.h
/src/DynareFlex.cc
/src/location.hh
/src/position.hh
/src/stack.hh
/src/macro/MacroBison.cc
/src/macro/MacroBison.hh
/src/macro/MacroFlex.cc
/src/macro/location.hh
/src/macro/position.hh
/src/macro/stack.hh
/src/doc/
# macOS stuff
.DS_Store
variables:
TERM: linux
MINGW64_BOOST_VERSION: 1.88.0-2
WGET_OPTIONS: '--no-verbose --no-use-server-timestamps --retry-connrefused --retry-on-host-error'
# To ensure that "false && true" fails, see https://gitlab.com/gitlab-org/gitlab-runner/-/issues/25394#note_412609647
FF_ENABLE_BASH_EXIT_CODE_CHECK: 'true'
build_linux_x86_64:
stage: build
script:
- meson setup -D buildtype=release build
- meson compile -C build -v
artifacts:
paths:
- build/src/dynare-preprocessor
build_linux_arm64:
stage: build
script:
- meson setup -D buildtype=release --cross-file scripts/linux-arm64-cross.ini build
- meson compile -C build -v
artifacts:
paths:
- build/src/dynare-preprocessor
build_windows_x86_64:
stage: build
script:
- mkdir -p tarballs
- '[[ -f tarballs/mingw-w64-x86_64-boost-$MINGW64_BOOST_VERSION-any.pkg.tar.zst ]] || wget $WGET_OPTIONS -P tarballs http://repo.msys2.org/mingw/x86_64/mingw-w64-x86_64-boost-$MINGW64_BOOST_VERSION-any.pkg.tar.zst'
- mkdir -p deps
- tar xf tarballs/mingw-w64-x86_64-boost-$MINGW64_BOOST_VERSION-any.pkg.tar.zst --directory deps
- echo -e "[properties]\nboost_root = '$(pwd)/deps/mingw64/'" > boost.ini
- meson setup -D buildtype=release --cross-file scripts/windows-cross.ini --cross-file boost.ini build
- meson compile -C build -v
cache:
# This cache is shared between all branches, to save space
key: $CI_JOB_NAME
paths:
- tarballs/
artifacts:
paths:
- build/src/dynare-preprocessor.exe
build_macos_x86_64:
stage: build
tags:
- macOS
script:
- arch -x86_64 meson setup -D buildtype=release --native-file scripts/homebrew-native-x86_64.ini build
- arch -x86_64 meson compile -C build -v
artifacts:
paths:
- build/src/dynare-preprocessor
build_macos_arm64:
stage: build
tags:
- macOS
script:
- export PATH="/opt/homebrew/bin:$PATH"
- arch -arm64 meson setup -D buildtype=release --native-file scripts/homebrew-native-arm64.ini build
- arch -arm64 meson compile -C build -v
artifacts:
paths:
- build/src/dynare-preprocessor
test_clang_format:
stage: test
script:
- meson setup build-clang-format
- ninja -C build-clang-format clang-format-check
needs: []
test_clang_tidy:
stage: test
script:
# Hack needed for meson < 1.6.0 which only looks for unversioned clang-tidy
- mkdir -p ~/.local/bin && ln -s /usr/bin/clang-tidy-19 ~/.local/bin/clang-tidy
- export PATH="$HOME/.local/bin:$PATH"
- meson setup build-clang-tidy
# Generate Flex and Bison files
- meson compile -C build-clang-tidy
- ninja -C build-clang-tidy clang-tidy
needs: []
when: manual
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
......@@ -645,7 +645,7 @@ the "copyright" line and a pointer to where the full notice is found.
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
......@@ -664,11 +664,11 @@ might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.
<https://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
<https://www.gnu.org/licenses/why-not-lgpl.html>.
SUBDIRS = src
ACLOCAL_AMFLAGS = -I m4
EXTRA_DIST = \
license.txt \
COPYING
dist-hook:
rm -rf `find $(distdir) -name '.git*'`
<a name="logo"/>
<div align="center">
<a href="http://www.dynare.org/" target="_blank">
<img src="http://www.dynare.org/img/dynare.png" alt="Dynare Logo"></img>
<a href="https://www.dynare.org/" target="_blank">
<img src="https://www.dynare.org/assets/images/logo/dlogo.svg" alt="Dynare Logo"></img>
</a>
</div>
......@@ -9,12 +9,9 @@
The Dynare Preprocessor defines the Dynare model language. It takes in a `.mod`
file, computes the derivatives of the model represented therein, and produces
Matlab/Octave, C, Julia, or JSON output.
There is more to come here. For the moment, see the [Dynare
repository](https://github.com/DynareTeam/dynare)
MATLAB/Octave, Julia, or JSON output.
# License
Most of the source files are covered by the GNU General Public Licence version
3 or later. There are some exceptions. See [license.txt](license.txt) for specifics.
3 or later. There are some exceptions, see the respective file headers.
dnl Process this file with autoconf to produce a configure script.
dnl Copyright (C) 2009-2018 Dynare Team
dnl
dnl This file is part of Dynare.
dnl
dnl Dynare is free software: you can redistribute it and/or modify
dnl it under the terms of the GNU General Public License as published by
dnl the Free Software Foundation, either version 3 of the License, or
dnl (at your option) any later version.
dnl
dnl Dynare is distributed in the hope that it will be useful,
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
dnl GNU General Public License for more details.
dnl
dnl You should have received a copy of the GNU General Public License
dnl along with Dynare. If not, see <http://www.gnu.org/licenses/>.
AC_PREREQ([2.62])
AC_INIT([dynare-preprocessor], [1.0-unstable])
AC_CONFIG_SRCDIR([src/DynareMain.cc])
AM_INIT_AUTOMAKE([1.11 -Wall -Wno-portability foreign no-dist-gzip dist-xz tar-pax])
AC_PROG_CC
AC_PROG_CXX
AC_CANONICAL_HOST
case ${host_os} in
*mingw32*)
# On mingw32, we don't want dynamic libgcc
# Note that static-libstdc++ is only supported since GCC 4.5 (but generates no error on older versions)
LDFLAGS="$LDFLAGS -static-libgcc -static-libstdc++ -static-libgfortran"
have_windows="yes"
;;
*cygwin*)
AC_MSG_WARN([You are compiling for the Cygwin target. This means that the preprocessor will])
AC_MSG_WARN([not run from MATLAB unless you add the Cygwin DLL to the path.])
AC_MSG_WARN([This is probably not what you want. Consider using a MinGW cross-compiler.])
have_windows="yes"
;;
esac
# Use C++ for testing headers
AC_LANG([C++])
CXXFLAGS="$CXXFLAGS -Wall -Wno-parentheses"
# If default 'ar' is not available, try to find one with a host prefix (see ticket #145)
AC_CHECK_PROGS([AR], [ar ${host_alias}-ar])
AC_PROG_RANLIB
AM_PROG_AR
AM_PROG_LEX
# Hack to get lex include dir, ticket #575
AC_PATH_PROG([LEXPATH], [$LEX])
AC_SUBST([LEXINC], [`eval "echo $LEXPATH | sed 's|\(.*\)$LEX$|\1../include|'"`])
AC_CHECK_PROG([YACC], [bison], [bison])
if test "x$YACC" = "x"; then
unset YACC # AM_MISSING_PROG needs an unset variable: an empty variable won't do
AM_MISSING_PROG([YACC], [bison])
fi
# We need 1.36 because of unordered_{set,hash} used by Dynare++
AX_BOOST_BASE([1.36], [], [AC_MSG_ERROR([Can't find Boost >= 1.36])])
CPPFLAGS_SAVED="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
AC_CHECK_HEADERS([boost/graph/adjacency_list.hpp], [], [AC_MSG_ERROR([Can't find Boost Graph Library])])
AC_CHECK_HEADERS([boost/algorithm/string/trim.hpp], [], [AC_MSG_ERROR([Can't find Boost String Library])])
AC_CHECK_HEADERS([boost/algorithm/string/split.hpp], [], [AC_MSG_ERROR([Can't find Boost String Library])])
AC_CHECK_HEADERS([boost/lexical_cast.hpp], [], [AC_MSG_ERROR([Can't find Boost Lexical Cast Header])])
CPPFLAGS="$CPPFLAGS_SAVED"
# Don't use deprecated hash structures
AC_DEFINE([BOOST_NO_HASH], [], [Don't use deprecated STL hash structures])
AC_CHECK_PROG([DOXYGEN], [doxygen], [doxygen])
AM_CONDITIONAL([HAVE_DOXYGEN], [test "x$DOXYGEN" != "x"])
AC_CONFIG_FILES([Makefile
src/Makefile
src/macro/Makefile
])
if test "x$DOXYGEN" != "x"; then
BUILD_DYNARE_PREPROC_DOC="yes"
else
BUILD_DYNARE_PREPROC_DOC="no (missing doxygen)"
fi
AC_MSG_NOTICE([
The Dynare Preprocessor is now configured to build...
Binaries (with "make")
Dynare preprocessor: yes
HTML documentation (with "make html"):
Dynare preprocessor developer doc: $BUILD_DYNARE_PREPROC_DOC
])
AC_OUTPUT
doc/logos/cepremap.jpg

25.3 KiB

doc/logos/dlogo.png

55.6 KiB

\documentclass[aspectratio=169]{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{upquote}
\usepackage{amsmath}
\usepackage[copyright]{ccicons}
\usetheme{Boadilla}
\graphicspath{{../logos/}}
\title{The Dynare Macro Processor}
\author{Sébastien Villemot}
\pgfdeclareimage[height=0.8cm]{logo}{dlogo}
\institute[Dynare Team]{\pgfuseimage{logo}}
\date{31 May 2024}
\AtBeginSection[]
{
\begin{frame}
\frametitle{Outline}
\tableofcontents[currentsection]
\end{frame}
}
\begin{document}
\begin{frame}
\titlepage
\end{frame}
\begin{frame}
\frametitle{Outline}
\tableofcontents
\end{frame}
\section{Overview}
\begin{frame}
\frametitle{Motivation}
\begin{itemize}
\item The \textbf{Dynare language} (used in \texttt{.mod} files) is well suited for many economic models
\begin{itemize}
\item It's a markup language that defines models
\item Lacks a programmatic element
\end{itemize}
\item The \textbf{Dynare macro language} adds a programmatic element to Dynare
\begin{itemize}
\item Introduces conditionals, loops, and other simple programmatic directives
\item Used to speed up model development
\item Useful in various situations
\begin{itemize}
\item Multi-country models
\item Creation of modular \texttt{.mod} files
\item Variable flipping
\item Conditional inclusion of equations
\item ...among others
\end{itemize}
\end{itemize}
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Design of the macro language}
\begin{itemize}
\item The Dynare macro language provides a set of \textbf{macro commands} that can be used in \texttt{.mod} files
\item The macro processor transforms a \texttt{.mod} file with macro commands into a \texttt{.mod} file without macro commands (doing text expansions/inclusions) and then feeds it to the Dynare parser
\item The key point to understand is that the macro processor only does \textbf{text substitution} (like the C preprocessor or the PHP language)
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Dynare Flowchart}
\includegraphics[width=0.95\linewidth]{new-design.pdf}
\end{frame}
\section{Syntax}
\begin{frame}[fragile=singleslide]
\frametitle{Macro Directives}
\begin{itemize}
\item Directives begin with: \verb+@#+
\item A directive gives instructions to the macro processor
\item Main directives are:
\begin{itemize}
\item file inclusion: \verb+@#include+
\item definition of a macro processor variable or function: \verb+@#define+
\item conditional statements: \verb+@#if/@#ifdef/@#ifndef/@#else/@#elseif/@#endif+
\item loop statements: \verb+@#for/@#endfor+
\end{itemize}
\item Most directives fit on one line. If needed however, two backslashes (\textit{i.e.} \verb+\\+) at the end of a line indicate that the directive is continued on the next line.
\item Directives are not terminated with a semicolon
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Values}
\begin{itemize}
\item The macro processor can handle values of 5 different types:
\begin{enumerate}
\item boolean (logical value, true or false)
\item real (double precision floating point number)
\item string (of characters)
\item tuple
\item array
\end{enumerate}
\item Values of the types listed above can be cast to other types
\begin{itemize}
\item \texttt{(real) "3.1"} $\rightarrow$ \texttt{3.1}
\item \texttt{(string) 3.1} $\rightarrow$ \texttt{"3.1"}
\item \texttt{(array) 4} $\rightarrow$ \texttt{[4]}
\item \texttt{(real) [5]} $\rightarrow$ \texttt{5}
\item \texttt{(real) [6, 7]} $\rightarrow$ \texttt{error}
\item \texttt{(bool) -1 \&\& (bool) 2} $\rightarrow$ \texttt{true}
\end{itemize}
\end{itemize}
\end{frame}
\begin{frame}[fragile=singleslide]
\frametitle{Macro-expressions (1/8)}
\begin{itemize}
\item Macro-expressions are constructed using literals (\textit{i.e.} fixed values) of the 5 basic types
described above, macro-variables, standard operators, function calls and comprehensions.
\item Macro-expressions can be used in two places:
\begin{itemize}
\item inside macro directives; no special markup is required
\item in the body of the \texttt{.mod} file, between an ``at''-sign and curly braces (like \verb+@{expr}+); the macro processor will substitute the expression with its value
\end{itemize}
\end{itemize}
\end{frame}
\begin{frame}[fragile=singleslide]
\frametitle{Macro-expressions (2/8): Boolean}
Boolean literals are \texttt{true} and \texttt{false}.
\begin{block}{Operators on booleans}
\begin{itemize}
\item comparison operators: \texttt{== !=}
\item logical operators:
\begin{itemize}
\item conjunction (“and”): \texttt{\&\&}
\item disjunction (“or”): \texttt{||}
\item negation (“not”): \texttt{!}
\end{itemize}
\end{itemize}
\end{block}
\end{frame}
\begin{frame}[fragile=singleslide]
\frametitle{Macro-expressions (3/8): Real}
\begin{block}{Operators on reals}
\begin{itemize}
\item arithmetic operators: \texttt{+ - * / \^{}}
\item comparison operators: \texttt{< > <= >= == !=}
\item logical operators: \verb+&& || !+
\item range with unit increment: \texttt{1:4} is equivalent to
real array \texttt{[1, 2, 3, 4]} \\ (NB: \texttt{[1:4]} is equivalent to an
array containing an array of reals, \textit{i.e.} \texttt{[[1, 2, 3, 4]]})
\item range with user-defined increment: \\ \texttt{4:-1.1:-1} is equivalent to real array \texttt{[4, 2.9, 1.8, 0.7, -0.4]}
\end{itemize}
\end{block}
\begin{block}{Functions for reals}
\begin{itemize}
\item \texttt{min}, \texttt{max}, \texttt{exp}, \texttt{ln} (or \texttt{log}), \texttt{log10}
\item \texttt{sign}, \texttt{floor}, \texttt{ceil}, \texttt{trunc}, \texttt{round}, \texttt{mod}
\item \texttt{sin}, \texttt{cos}, \texttt{tan}, \texttt{asin}, \texttt{acos}, \texttt{atan}
\item \texttt{sqrt}, \texttt{cbrt}, \texttt{erf}, \texttt{erfc}, \texttt{normpdf}, \texttt{normcdf}, \texttt{gamma}, \texttt{lgamma}
\end{itemize}
\end{block}
\end{frame}
\begin{frame}[fragile=singleslide]
\frametitle{Macro-expressions (4/8): String}
String literals have to be declared between \textit{double} quotes, e.g. \texttt{"string"}
\begin{block}{Operators on character strings}
\begin{itemize}
\item comparison operators: \texttt{< > <= >= == !=}
\item concatenation: \texttt{+}
\item string length: \texttt{length()}
\item string emptiness: \texttt{isempty()}
\item extraction of substrings: if \texttt{s} is a string, then one can write \texttt{s[3]} or \texttt{s[4:6]}
\end{itemize}
\end{block}
\end{frame}
\begin{frame}[fragile=singleslide]
\frametitle{Macro-expressions (5/8): Tuple}
Tuples are enclosed by parentheses and elements are separated by commas (like
\texttt{(a,b,c)} or \texttt{(1,2.2,c)}).
\begin{block}{Operators on tuples}
\begin{itemize}
\item comparison operators: \texttt{== !=}
\item functions: \texttt{length()}, \texttt{isempty()}
\item testing membership in tuple: \texttt{in} operator \\ (example:
\texttt{"b" in ("a", "b", "c")} returns \texttt{true})
\end{itemize}
\end{block}
\end{frame}
\begin{frame}[fragile=singleslide]
\frametitle{Macro-expressions (6/8): Array (1/2)}
Arrays are enclosed by brackets, and their elements are separated by commas
(like \texttt{[1,[2,3],4]} or \texttt{["US", "EA"]}).
\begin{block}{Operators on arrays}
\begin{itemize}
\item comparison operators: \texttt{== !=}
\item dereferencing: if \texttt{v} is an array, then \texttt{v[2]} is its $2^{\textrm{nd}}$ element
\item concatenation: \texttt{+}
\item functions: \texttt{sum()}, \texttt{length()}, \texttt{isempty()}
\item extraction of sub-arrays: \textit{e.g.} \texttt{v[4:6]}
\item testing membership of an array: \texttt{in} operator \\ (example:
\texttt{"b" in ["a", "b", "c"]} returns \texttt{true})
\end{itemize}
\end{block}
\end{frame}
\begin{frame}[fragile=singleslide]
\frametitle{Macro-expressions (6/8): Array (2/2)}
Arrays can be seen as representing a set of elements (assuming no element
appears twice in the array). Several set operations can thus be performed on
arrays: union, intersection, difference, Cartesian product and power.
\begin{block}{Set operations on arrays}
\begin{itemize}
\item set union: \texttt{|}
\item set intersection: \texttt{\&}
\item set difference: \texttt{-}
\item Cartesian product of two arrays: \texttt{*}
\item Cartesian power of an array: \texttt{\^}
\end{itemize}
\end{block}
For example: if \texttt{A} and \texttt{B} are arrays, then the following
set operations are valid: \texttt{A|B}, \texttt{A\&B}, \texttt{A-B},
\texttt{A*B}, \texttt{A\^{}3}.
NB: the array resulting from Cartesian product or power has tuples as its elements.
\end{frame}
\begin{frame}[fragile=singleslide]
\frametitle{Macro-expressions (7/8): Comprehension (1/3)}
Comprehensions are a shorthand way of creating arrays from other arrays. This is done by filtering, mapping, or both.
\begin{block}{Filtering}
\begin{itemize}
\item Allows one to choose those elements from an array for which a condition holds
\item Syntax: \texttt{[} \textit{variable/tuple} \texttt{in} \textit{array} \texttt{when}
\textit{condition} \texttt{]}
\item Example: Choose even numbers from array
\begin{itemize}
\item Code: \texttt{[ i in 1:5 when mod(i,2) == 0 ]}
\item Result: \texttt{[2, 4]}
\end{itemize}
\end{itemize}
\end{block}
\end{frame}
\begin{frame}[fragile=singleslide]
\frametitle{Macro-expressions (7/8): Comprehension (2/3)}
\begin{block}{Mapping}
\begin{itemize}
\item Allows one to apply a transformation to every element of an array
\item Syntax: \texttt{[} \textit{expr} \texttt{for} \textit{variable/tuple}
\texttt{in} \textit{array} \texttt{]}
\item Example: Square elements in array
\begin{itemize}
\item Code: \texttt{[ i\^{}2 for i in 1:5 ]}
\item Result: \texttt{[1, 4, 9, 16, 25]}
\end{itemize}
\item Example: Swap pairs of an array
\begin{itemize}
\item Code: \texttt{[ (j,i) for (i,j) in (1:2)\^{}2 ]}
\item Result: \texttt{[(1, 1), (2, 1), (1, 2), (2, 2)]}
\end{itemize}
\end{itemize}
\end{block}
\end{frame}
\begin{frame}[fragile=singleslide]
\frametitle{Macro-expressions (7/8): Comprehension (3/3)}
\begin{block}{Mapping and Filtering}
\begin{itemize}
\item Allows one to apply a transformation to the elements selected from an array
\item Syntax: \texttt{[} \textit{expr} \texttt{for} \textit{variable/tuple}
\texttt{in} \textit{array} \texttt{when} \textit{condition} \texttt{]}
\item Example: Square of odd numbers between 1 and 5
\begin{itemize}
\item Code: \texttt{[ i\^{}2 for i in 1:5 when mod(i,2) == 1 ]}
\item Result: \texttt{[1, 9, 25]}
\end{itemize}
\end{itemize}
\end{block}
\end{frame}
\begin{frame}[fragile=singleslide]
\frametitle{Macro-expressions (8/8): Functions}
\begin{itemize}
\item Can take any number of arguments
\item Dynamic binding: is evaluated when invoked during the macroprocessing stage, not when defined
\item Can be included in expressions; valid operators depend on return type
\end{itemize}
\begin{block}{Declaration syntax}
\verb+@#define +\textit{function\_signature}\verb+ = +\textit{expression}
\end{block}
\begin{block}{Example}
If we declare the following function:
\begin{verbatim}
@#define distance(x, y) = sqrt(x^2 + y^2)
\end{verbatim}
Then \texttt{distance(3, 4)} will be equivalent to \texttt{5}.
\end{block}
\end{frame}
\begin{frame}[fragile=singleslide]
\frametitle{Defining macro-variables (1/2)}
The value of a macro-variable can be defined with the \verb+@#define+
directive.
The macro processor has its own list of variables, which are different from model variables and MATLAB/Octave variables
\begin{block}{Syntax}
\verb+@#define +\textit{variable\_name}\verb+ = +\textit{expression}
\end{block}
\begin{block}{Examples}
\begin{verbatim}
@#define x = 5 // Real
@#define y = "US" // String
@#define v = [ 1, 2, 4 ] // Real array
@#define w = [ "US", "EA" ] // String array
@#define z = 3 + v[2] // Equals 5
@#define t = ("US" in w) // Equals true
\end{verbatim}
\end{block}
\end{frame}
\begin{frame}[fragile=singleslide]
\frametitle{Defining macro-variables (2/2)}
Macro variables can also be defined on the Dynare command line by using the
\texttt{-D} option, for easily switching between different flavours of a model.
\begin{block}{Example 1}
\begin{verbatim}
dynare myfile.mod -Dx=5
\end{verbatim}
The macro-variable \texttt{x} will be equal to \texttt{5} when running \texttt{myfile.mod}.
\end{block}
\begin{block}{Example 2}
Use single quotes around the \texttt{-D} option when there are spaces or
special characters in the variable definition.
\begin{verbatim}
dynare myfile.mod '-DA=[ i in [1,2,3] when i > 1 ]'
\end{verbatim}
The macro-variable \texttt{A} will be equal to \texttt{[2,3]} when running \texttt{myfile.mod}.
\end{block}
\end{frame}
\begin{frame}[fragile=singleslide]
\frametitle{Expression substitution}
\framesubtitle{Dummy example}
\begin{block}{Before macro processing}
\begin{verbatim}
@#define x = 1
@#define y = [ "B", "C" ]
@#define i = 2
@#define f(x) = x + " + " + y[i]
@#define i = 1
model;
A = @{y[i] + f("D")};
end;
\end{verbatim}
\end{block}
\begin{block}{After macro processing}
\begin{verbatim}
model;
A = BD + B;
end;
\end{verbatim}
\end{block}
\end{frame}
\begin{frame}[fragile=singleslide]
\frametitle{Include directive (1/2)}
\begin{itemize}
\item This directive simply inserts the text of another file in its place
\begin{block}{Syntax}
\verb+@#include "+\textit{filename}\verb+"+
\end{block}
\begin{block}{Example}
\begin{verbatim}
@#include "modelcomponent.mod"
\end{verbatim}
\end{block}
\item Equivalent to a copy/paste of the content of the included file
\item Note that it is possible to nest includes (\textit{i.e.} to include a
file with an included file)
\end{itemize}
\end{frame}
\begin{frame}[fragile=singleslide]
\frametitle{Include directive (2/2)}
\begin{itemize}
\item The filename can be given by a macro-variable (useful in loops):
\begin{block}{Example with variable}
\begin{verbatim}
@#define fname = "modelcomponent.mod"
@#include fname
\end{verbatim}
\end{block}
\item Files to include are searched for in the current directory. Other directories can
be added with the
\verb+@#includepath+ directive, the \texttt{-I} command line option, or the
\texttt{[paths]} section in config files.
\end{itemize}
\end{frame}
\begin{frame}[fragile=singleslide]
\frametitle{Loop directive (1/4)}
\begin{block}{Syntax 1: Simple iteration over one variable}
\verb+@#for +\textit{variable\_name}\verb+ in +\textit{array\_expr} \\
\verb+ +\textit{loop\_body} \\
\verb+@#endfor+
\end{block}
\begin{block}{Syntax 2: Iteration over several variables at the same time}
\verb+@#for +\textit{tuple}\verb+ in +\textit{array\_expr} \\
\verb+ +\textit{loop\_body} \\
\verb+@#endfor+
\end{block}
\begin{block}{Syntax 3: Iteration with some values excluded}
\verb+@#for +\textit{tuple\_or\_variable}\verb+ in +\textit{array\_expr} \verb+ when +\textit{expr}\\
\verb+ +\textit{loop\_body} \\
\verb+@#endfor+
\end{block}
\end{frame}
\begin{frame}[fragile=singleslide]
\frametitle{Loop directive (2/4)}
\begin{block}{Example: before macro processing}
\small
\begin{verbatim}
model;
@#for country in [ "home", "foreign" ]
GDP_@{country} = A * K_@{country}^a * L_@{country}^(1-a);
@#endfor
end;
\end{verbatim}
\normalsize
\end{block}
\begin{block}{Example: after macro processing}
\small
\begin{verbatim}
model;
GDP_home = A * K_home^a * L_home^(1-a);
GDP_foreign = A * K_foreign^a * L_foreign^(1-a);
end;
\end{verbatim}
\normalsize
\end{block}
\end{frame}
\begin{frame}[fragile=singleslide]
\frametitle{Loop directive (3/4)}
\begin{block}{Example: loop over several variables}
\small
\begin{verbatim}
@#define A = [ "X", "Y", "Z"]
@#define B = [ 1, 2, 3]
model;
@#for (i,j) in A*B
e_@{i}_@{j} = …
@#endfor
end;
\end{verbatim}
\normalsize
This will loop over \texttt{e\_X\_1}, \texttt{e\_X\_2}, …, \texttt{e\_Z\_3} (9
variables in total)
\end{block}
\end{frame}
\begin{frame}[fragile=singleslide]
\frametitle{Loop directive (4/4)}
\begin{block}{Example: loop over several variables with filtering}
\small
\begin{verbatim}
model;
@#for (i,j,k) in (1:10)^3 when i^2+j^2==k^2
e_@{i}_@{j}_@{k} = …
@#endfor
end;
\end{verbatim}
\normalsize
This loop will iterate over only 4 triplets: \texttt{(3,4,5)},
\texttt{(4,3,5)}, \texttt{(6,8,10)}, \texttt{(8,6,10)}.
\end{block}
\end{frame}
\begin{frame}[fragile=singleslide]
\frametitle{Conditional directives (1/3)}
\begin{columns}[T]
\column{0.47\linewidth}
\begin{block}{Syntax 1}
\verb+@#if +\textit{bool\_or\_real\_expr} \\
\verb+ +\textit{body included if expr is true (or != 0)} \\
\verb+@#endif+
\end{block}
\column{0.47\linewidth}
\begin{block}{Syntax 2}
\verb+@#if +\textit{bool\_or\_real\_expr} \\
\verb+ +\textit{body included if expr is true (or != 0)} \\
\verb+@#else+ \\
\verb+ +\textit{body included if expr is false (or 0)} \\
\verb+@#endif+
\end{block}
\end{columns}
\end{frame}
\begin{frame}[fragile=singleslide]
\frametitle{Conditional directives (2/3)}
\begin{block}{Syntax 3}
\scriptsize
\verb+@#if +\textit{bool\_or\_real\_expr1} \\
\verb+ +\textit{body included if expr1 is true (or != 0)} \\
\verb+@#elseif +\textit{bool\_or\_real\_expr2} \\
\verb+ +\textit{body included if expr2 is true (or != 0)} \\
\verb+@#else+ \\
\verb+ +\textit{body included if expr1 and expr2 are false (or 0)} \\
\verb+@#endif+
\end{block}
\begin{block}{Example: alternative monetary policy rules}
\scriptsize
\begin{verbatim}
@#define linear_mon_pol = false // or 0
...
model;
@#if linear_mon_pol
i = w*i(-1) + (1-w)*i_ss + w2*(pie-piestar);
@#else
i = i(-1)^w * i_ss^(1-w) * (pie/piestar)^w2;
@#endif
...
end;
\end{verbatim}
\scriptsize
\end{block}
\end{frame}
\begin{frame}[fragile=singleslide]
\frametitle{Conditional directives (3/3)}
\begin{columns}[T]
\column{0.47\linewidth}
\begin{block}{Syntax 1}
\verb+@#ifdef +\textit{variable\_name} \\
\verb+ +\textit{body included if variable defined} \\
\verb+@#endif+
\end{block}
\column{0.47\linewidth}
\begin{block}{Syntax 2}
\verb+@#ifdef +\textit{variable\_name} \\
\verb+ +\textit{body included if variable defined} \\
\verb+@#else+ \\
\verb+ +\textit{body included if variable not defined} \\
\verb+@#endif+
\end{block}
\end{columns}
\bigskip
\begin{itemize}
\item There is also \verb+@#ifndef+, which is the opposite of \verb+@#ifdef+
(\textit{i.e.} it tests whether a variable is \emph{not} defined).
\item NB: There is
\emph{no} \verb+@#elseifdef+ or \verb+@#elseifndef+ directive; use
\verb+elseif defined(variable_name)+ to achieve the desired objective.
\end{itemize}
\end{frame}
\begin{frame}[fragile=singleslide]
\frametitle{Echo directives}
\begin{itemize}
\item The echo directive will simply display a message on standard output
\item The echomacrovars directive will display all of the macro variables (or
those specified) and their values
\item The \texttt{save} option allows saving this information to \texttt{options\_.macrovars\_line\_x}, where \texttt{x} denotes the line number where the statement was encountered
\end{itemize}
\begin{block}{Syntax}
\verb+@#echo +\textit{string\_expr} \\
\verb+@#echomacrovars +\\
\verb+@#echomacrovars +\textit{list\_of\_variables}\\
\verb+@#echomacrovars(save)+\\
\verb+@#echomacrovars(save) +\textit{list\_of\_variables}\\
\end{block}
\begin{block}{Examples}
\begin{verbatim}
@#echo "Information message."
\end{verbatim}
\end{block}
\end{frame}
\begin{frame}[fragile=singleslide]
\frametitle{Error directive}
\begin{itemize}
\item The error directive will display the message and make Dynare stop (only makes sense inside a conditional directive)
\end{itemize}
\begin{block}{Syntax}
\verb+@#error +\textit{string\_expr} \\
\end{block}
\begin{block}{Example}
\begin{verbatim}
@#error "Error message!"
\end{verbatim}
\end{block}
\end{frame}
\begin{frame}
\frametitle{Macro-related command line options}
\begin{itemize}
\item \texttt{savemacro}: Useful for debugging or learning purposes, saves the output of the macro processor. If your \texttt{.mod} file is called \texttt{file.mod}, the output is saved to \texttt{file\_macroexp.mod}.
\item NB: \texttt{savemacro=filename} allows a user-defined file name
\item \texttt{linemacro}: In the output of \texttt{savemacro}, print line numbers where the macro directives were placed.
\item \texttt{onlymacro}: Stops processing after the macro processing step.
\end{itemize}
\end{frame}
\section{Common uses}
\begin{frame}[fragile=singleslide]
\frametitle{Modularization}
\begin{itemize}
\item The \verb+@#include+ directive can be used to split \texttt{.mod} files into several modular components
\item Example setup:
\begin{description}
\item[\texttt{modeldesc.mod}:] contains variable declarations, model equations, and shock declarations
\item[\texttt{simulate.mod}:] includes \texttt{modeldesc.mod}, calibrates parameters, and runs stochastic simulations
\item[\texttt{estim.mod}:] includes \texttt{modeldesc.mod}, declares priors on parameters, and runs Bayesian estimation
\end{description}
\item Dynare can be called on \texttt{simulate.mod} and \texttt{estim.mod}
\item But it makes no sense to run it on \texttt{modeldesc.mod}
\item Advantage: no need to manually copy/paste the whole model (during initial development) or port model changes (during development)
\end{itemize}
\end{frame}
\begin{frame}[fragile=singleslide]
\frametitle{Indexed sums or products}
\framesubtitle{Example: moving average}
\begin{columns}[T]
\column{0.47\linewidth}
\begin{block}{Before macro processing}
\begin{verbatim}
@#define window = 2
var x MA_x;
...
model;
...
MA_x = @{1/(2*window+1)}*(
@#for i in -window:window
+x(@{i})
@#endfor
);
...
end;
\end{verbatim}
\end{block}
\column{0.47\linewidth}
\begin{block}{After macro processing}
\begin{verbatim}
var x MA_x;
...
model;
...
MA_x = 1/5*(
+x(-2)
+x(-1)
+x(0)
+x(1)
+x(2)
);
...
end;
\end{verbatim}
\end{block}
\end{columns}
\end{frame}
\begin{frame}[fragile=singleslide]
\frametitle{Multi-country models}
\framesubtitle{\texttt{.mod} file skeleton example}
\scriptsize
\begin{verbatim}
@#define countries = [ "US", "EA", "AS", "JP", "RC" ]
@#define nth_co = "US"
@#for co in countries
var Y_@{co} K_@{co} L_@{co} i_@{co} E_@{co} ...;
parameters a_@{co} ...;
varexo ...;
@#endfor
model;
@#for co in countries
Y_@{co} = K_@{co}^a_@{co} * L_@{co}^(1-a_@{co});
...
@# if co != nth_co
(1+i_@{co}) = (1+i_@{nth_co}) * E_@{co}(+1) / E_@{co}; // UIP relation
@# else
E_@{co} = 1;
@# endif
@#endfor
end;
\end{verbatim}
\normalsize
\end{frame}
\begin{frame}
\frametitle{Endogeneizing parameters (1/4)}
\begin{itemize}
\item When calibrating the model, it may be useful to pin down parameters by targeting endogenous objects
\item Example:
\begin{gather*}
y_t = \left(\alpha^{\frac{1}{\xi}} \ell_t^{1-\frac{1}{\xi}} + (1-\alpha)^{\frac{1}{\xi}}k_t^{1-\frac{1}{\xi}}\right)^{\frac{\xi}{\xi - 1}} \\
lab\_rat_t = \frac{w_t \ell_t}{p_t y_t}
\end{gather*}
\item In the model, $\alpha$ is a (share) parameter, and $lab\_rat_t$ is an endogenous variable
\item We observe that:
\begin{itemize}
\item setting a value for $\alpha$ is not straightforward!
\item but we have real world data for $lab\_rat_t$
\item it is clear that these two objects are economically linked
\end{itemize}
\end{itemize}
\end{frame}
\begin{frame}[fragile=singleslide]
\frametitle{Endogeneizing parameters (2/4)}
\begin{itemize}
\item Therefore, when computing the steady state by solving the static model:
\begin{itemize}
\item we make $\alpha$ a variable and the steady state value $lab\_rat$ of the dynamic variable $lab\_rat_t$ a parameter
\item we impose an economically sensible value for $lab\_rat$
\item the solution algorithm deduces the implied value for $\alpha$
\end{itemize}
\item We call this method ``variable flipping'', because it treats $\alpha$ as a variable and $lab\_rat$ as a parameter for the purpose of the static model
\end{itemize}
\end{frame}
\begin{frame}[fragile=singleslide]
\frametitle{Endogeneizing parameters (3/4)}
\framesubtitle{Example implementation}
\begin{itemize}
\item File \texttt{modeqs.mod}:
\begin{itemize}
\item contains variable declarations and model equations
\item For declaration of \texttt{alpha} and \texttt{lab\_rat}:
\footnotesize
\begin{verbatim}
@#if steady
var alpha;
parameter lab_rat;
@#else
parameter alpha;
var lab_rat;
@#endif
\end{verbatim}
\normalsize
\end{itemize}
\end{itemize}
\end{frame}
\begin{frame}[fragile=singleslide]
\frametitle{Endogeneizing parameters (4/4)}
\framesubtitle{Example implementation}
\begin{itemize}
\item File \texttt{steadystate.mod}:
\begin{itemize}
\item begins with \verb+@#define steady = true+
\item followed by \verb+@#include "modeqs.mod"+
\item initializes parameters (including \texttt{lab\_rat}, excluding \texttt{alpha})
\item computes steady state (using guess values for endogenous, including \texttt{alpha})
\item saves values of parameters and variables at steady-state in a file, using the \texttt{save\_params\_and\_steady\_state} command
\end{itemize}
\item File \texttt{simulate.mod}:
\begin{itemize}
\item begins with \verb+@#define steady = false+
\item followed by \verb+@#include "modeqs.mod"+
\item loads values of parameters and variables at steady-state from file, using the \texttt{load\_params\_and\_steady\_state} command
\item computes simulations
\end{itemize}
\end{itemize}
\end{frame}
\begin{frame}[fragile=singleslide]
\frametitle{MATLAB/Octave loops vs macro processor loops (1/3)}
Suppose you have a model with a parameter $\rho$, and you want to make
simulations for three values: $\rho = 0.8, 0.9, 1$. There are
several ways of doing this:
\begin{block}{With a MATLAB/Octave loop}
\begin{verbatim}
rhos = [ 0.8, 0.9, 1];
for i = 1:length(rhos)
set_param_value('rho',rhos(i));
stoch_simul(order=1);
if info(1)~=0
error('Simulation failed for parameter draw')
end
end
\end{verbatim}
\end{block}
\begin{itemize}
\item The loop is not unrolled
\item MATLAB/Octave manages the iterations
\item NB: always check whether the error flag \texttt{info(1)==0} to prevent erroneously relying on stale results from previous iterations
\end{itemize}
\end{frame}
\begin{frame}[fragile=singleslide]
\frametitle{MATLAB/Octave loops vs macro processor loops (2/3)}
\begin{block}{With a macro processor loop (case 1)}
\begin{verbatim}
rhos = [ 0.8, 0.9, 1];
@#for i in 1:3
set_param_value('rho',rhos(@{i}));
stoch_simul(order=1);
if info(1)~=0
error('Simulation failed for parameter draw')
end
@#endfor
\end{verbatim}
\end{block}
\begin{itemize}
\item Very similar to previous example
\item Loop is unrolled
\item Dynare macro processor manages the loop index but not the data array (\texttt{rhos})
\end{itemize}
\end{frame}
\begin{frame}[fragile=singleslide]
\frametitle{MATLAB/Octave loops vs macro processor loops (3/3)}
\begin{block}{With a macro processor loop (case 2)}
\begin{verbatim}
@#for rho_val in [ 0.8, 0.9, 1]
set_param_value('rho',@{rho_val});
stoch_simul(order=1);
if info(1)~=0
error('Simulation failed for parameter draw')
end
@#endfor
\end{verbatim}
\end{block}
\begin{itemize}
\item Shorter syntax, since list of values directly given in the loop construct
\item NB: Array not stored as MATLAB/Octave variable, hence cannot be used in MATLAB/Octave
\end{itemize}
\end{frame}
\begin{frame}
\begin{center}
\vfill {\LARGE Thanks for your attention! \\
Questions?}
\vfill
{\LARGE My email: \texttt{sebastien@dynare.org}}
\vfill
\end{center}
\vfill
\begin{columns}[T]
\column{0.2\textwidth}
\column{0.09\textwidth}
\ccbysa
\column{0.71\textwidth}
\tiny
Copyright © 2008-2024 Dynare Team \\
License: \href{http://creativecommons.org/licenses/by-sa/4.0/}{Creative
Commons Attribution-ShareAlike 4.0}
\end{columns}
\end{frame}
\end{document}
File added
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://web.resource.org/cc/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="862.10712"
height="382.82141"
id="svg5540"
sodipodi:version="0.32"
inkscape:version="0.45.1"
version="1.0"
sodipodi:docbase="K:\Commun\Villemot\Macroprocessor"
sodipodi:docname="new-design.svg"
inkscape:output_extension="org.inkscape.output.svg.inkscape"
inkscape:export-filename="K:\Commun\Villemot\Macroprocessor\new-design.png"
inkscape:export-xdpi="90"
inkscape:export-ydpi="90">
<defs
id="defs5542">
<marker
inkscape:stockid="Arrow1Lend"
orient="auto"
refY="0"
refX="0"
id="Arrow1Lend"
style="overflow:visible">
<path
id="path3243"
d="M 0,0 L 5,-5 L -12.5,0 L 5,5 L 0,0 z "
style="fill-rule:evenodd;stroke:#000000;stroke-width:1pt;marker-start:none"
transform="matrix(-0.8,0,0,-0.8,-10,0)" />
</marker>
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="0.7"
inkscape:cx="488.94636"
inkscape:cy="380.52134"
inkscape:document-units="px"
inkscape:current-layer="layer1"
width="1052.3622px"
height="744.09448px"
inkscape:window-width="1024"
inkscape:window-height="712"
inkscape:window-x="-4"
inkscape:window-y="-4" />
<metadata
id="metadata5545">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Calque 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(-78.642861,-39.058769)">
<g
id="g4418"
transform="translate(467.50002,289.64286)">
<text
sodipodi:linespacing="125%"
id="text4420"
y="56.6479"
x="361.42862"
style="font-size:20px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:center;line-height:125%;writing-mode:lr-tb;text-anchor:middle;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Arial"
xml:space="preserve"><tspan
id="tspan4422"
y="56.6479"
x="361.42862"
sodipodi:role="line">Matlab files</tspan><tspan
id="tspan4424"
y="81.6479"
x="361.42862"
sodipodi:role="line">representing</tspan><tspan
id="tspan4426"
y="106.6479"
x="361.42862"
sodipodi:role="line">the model</tspan></text>
<path
transform="matrix(1.0528522,0,0,1.0682674,-22.862484,-9.0197689)"
d="M 431.42857 79.808769 A 66.428574 51.42857 0 1 1 298.57143,79.808769 A 66.428574 51.42857 0 1 1 431.42857 79.808769 z"
sodipodi:ry="51.42857"
sodipodi:rx="66.428574"
sodipodi:cy="79.808769"
sodipodi:cx="365"
id="path4428"
style="opacity:1;color:#000000;fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
sodipodi:type="arc" />
</g>
<g
id="g4430"
transform="translate(-555.35711,282.49999)">
<text
sodipodi:linespacing="125%"
id="text4432"
y="65.21933"
x="691.42859"
style="font-size:20px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:center;line-height:125%;writing-mode:lr-tb;text-anchor:middle;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Arial"
xml:space="preserve"><tspan
y="65.21933"
x="691.42859"
id="tspan4434"
sodipodi:role="line">Output:</tspan><tspan
id="tspan4436"
y="90.21933"
x="691.42859"
sodipodi:role="line">Results,</tspan><tspan
id="tspan4438"
y="115.21933"
x="691.42859"
sodipodi:role="line">Graphics</tspan></text>
<path
d="M 747.14283 85.523056 A 54.285713 51.42857 0 1 1 638.5714,85.523056 A 54.285713 51.42857 0 1 1 747.14283 85.523056 z"
sodipodi:ry="51.42857"
sodipodi:rx="54.285713"
sodipodi:cy="85.523056"
sodipodi:cx="692.85712"
id="path4440"
style="opacity:1;color:#000000;fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
sodipodi:type="arc" />
</g>
<g
id="g4452"
transform="translate(-25.357118,291.07143)">
<text
sodipodi:linespacing="125%"
id="text4454"
y="68.076462"
x="525.71436"
style="font-size:20px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:center;line-height:125%;writing-mode:lr-tb;text-anchor:middle;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Arial"
xml:space="preserve"><tspan
y="68.076462"
x="525.71436"
id="tspan4456"
sodipodi:role="line">Dynare</tspan><tspan
id="tspan4458"
y="93.076462"
x="525.71436"
sodipodi:role="line">Matlab routines</tspan></text>
<rect
y="36.951626"
x="448.57144"
height="75.714287"
width="152.85715"
id="rect4460"
style="opacity:1;color:#000000;fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate" />
</g>
<path
style="opacity:1;color:#000000;fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.5;stroke-linecap:butt;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:url(#Arrow1Lend);stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
d="M 757.92859,365.8802 L 577.07147,365.8802"
id="path4466"
inkscape:connector-type="polyline"
inkscape:connection-end="#g4452"
inkscape:connection-start="#g4418" />
<path
style="opacity:1;color:#000000;fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.5;stroke-linecap:butt;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:url(#Arrow1Lend);stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
d="M 422.21432,366.33835 L 192.78572,367.69591"
id="path4468"
inkscape:connector-type="polyline"
inkscape:connection-start="#g4452"
inkscape:connection-end="#g4430" />
<g
id="g6668">
<text
sodipodi:linespacing="125%"
id="text4470"
y="117.30877"
x="143.92857"
style="font-size:20px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:center;line-height:125%;writing-mode:lr-tb;text-anchor:middle;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Arial"
xml:space="preserve"><tspan
y="117.30877"
x="143.92857"
id="tspan4472"
sodipodi:role="line">MOD file</tspan><tspan
id="tspan4474"
y="142.30877"
x="143.92857"
sodipodi:role="line">with macro</tspan><tspan
id="tspan4482"
y="167.30877"
x="143.92857"
sodipodi:role="line">commands</tspan></text>
<path
transform="matrix(1.0725676,0,0,0.999374,99.5973,-252.25554)"
d="M 98.57143 390.52304 A 58.57143 56.42857 0 1 1 -18.57143,390.52304 A 58.57143 56.42857 0 1 1 98.57143 390.52304 z"
sodipodi:ry="56.42857"
sodipodi:rx="58.57143"
sodipodi:cy="390.52304"
sodipodi:cx="40"
id="path4504"
style="color:#000000;fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
sodipodi:type="arc" />
</g>
<g
id="g5516"
transform="translate(316.78572,-245.35715)">
<text
sodipodi:linespacing="125%"
id="text4476"
y="368.38019"
x="307.14285"
style="font-size:20px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:center;line-height:125%;writing-mode:lr-tb;text-anchor:middle;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Arial"
xml:space="preserve"><tspan
y="368.38019"
x="307.14285"
id="tspan4478"
sodipodi:role="line">MOD file</tspan><tspan
id="tspan4480"
y="393.38019"
x="307.14285"
sodipodi:role="line">without macro</tspan><tspan
id="tspan4484"
y="418.38019"
x="307.14285"
sodipodi:role="line">commands</tspan></text>
<path
transform="translate(-8.5714286,-4.2857143)"
d="M 389.99999 391.95163 A 72.85714 65 0 1 1 244.28571,391.95163 A 72.85714 65 0 1 1 389.99999 391.95163 z"
sodipodi:ry="65"
sodipodi:rx="72.85714"
sodipodi:cy="391.95163"
sodipodi:cx="317.14285"
id="path5475"
style="opacity:1;color:#000000;fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
sodipodi:type="arc" />
</g>
<g
id="g5510"
transform="translate(243.92858,-236.78572)">
<text
sodipodi:linespacing="125%"
id="text4486"
y="372.66592"
x="165.71428"
style="font-size:20px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:center;line-height:125%;writing-mode:lr-tb;text-anchor:middle;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Arial"
xml:space="preserve"><tspan
id="tspan4490"
y="372.66592"
x="165.71428"
sodipodi:role="line">Macro</tspan><tspan
id="tspan4492"
y="397.66592"
x="165.71428"
sodipodi:role="line">Processor</tspan></text>
<rect
y="339.80878"
x="110"
height="72.85714"
width="115.71429"
id="rect5477"
style="opacity:1;color:#000000;fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate" />
</g>
<g
id="g5523"
transform="translate(372.5,-249.64286)">
<text
sodipodi:linespacing="125%"
id="text4494"
y="368.38019"
x="455.71426"
style="font-size:20px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:center;line-height:125%;writing-mode:lr-tb;text-anchor:middle;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Arial"
xml:space="preserve"><tspan
y="368.38019"
x="455.71426"
id="tspan4496"
sodipodi:role="line">Parser,</tspan><tspan
id="tspan4498"
y="393.38019"
x="455.71426"
sodipodi:role="line">Analytical</tspan><tspan
id="tspan4500"
y="418.38019"
x="455.71426"
sodipodi:role="line">derivator...</tspan></text>
<rect
y="339.80878"
x="395.71429"
height="94.285713"
width="120"
id="rect5479"
style="opacity:1;color:#000000;fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate" />
</g>
<path
style="opacity:1;color:#000000;fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.5;stroke-linecap:butt;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:url(#Arrow1Lend);stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
d="M 206.35715,138.3618 L 352.92858,139.13938"
id="path5532"
inkscape:connector-type="polyline"
inkscape:connection-end="#g5510"
inkscape:connection-start="#g6668" />
<path
style="opacity:1;color:#000000;fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.5;stroke-linecap:butt;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:url(#Arrow1Lend);stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
d="M 470.64287,140.23901 L 551.5,141.32071"
id="path5534"
inkscape:connector-type="polyline"
inkscape:connection-start="#g5510"
inkscape:connection-end="#g5516" />
<path
style="opacity:1;color:#000000;fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.5;stroke-linecap:butt;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:url(#Arrow1Lend);stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
d="M 699.21428,140.48835 L 767.21429,138.81229"
id="path5536"
inkscape:connector-type="polyline"
inkscape:connection-start="#g5516"
inkscape:connection-end="#g5523" />
<path
style="opacity:1;color:#000000;fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.5;stroke-linecap:butt;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:url(#Arrow1Lend);stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
d="M 828.36474,185.45163 L 828.75359,309.8802"
id="path5538"
inkscape:connector-type="polyline"
inkscape:connection-end="#g4418"
inkscape:connection-start="#g5523" />
<rect
style="opacity:1;color:#000000;fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.5;stroke-linecap:butt;stroke-linejoin:miter;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:1.5, 4.5;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
id="rect5596"
width="634.28571"
height="201.42857"
x="305.71429"
y="39.808769" />
<text
xml:space="preserve"
style="font-size:20px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:center;line-height:125%;writing-mode:lr-tb;text-anchor:middle;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Arial"
x="404.28574"
y="232.66591"
id="text6567"
sodipodi:linespacing="125%"><tspan
sodipodi:role="line"
id="tspan6569"
x="404.28574"
y="232.66591">Dynare preprocessor</tspan></text>
</g>
</svg>
latexmk_exe = find_program('latexmk', required : false, disabler : true)
# We have to set TEXINPUTS because the current directory is not the source
# directory when latexmk is invoked (and using the -cd option in combination
# with -outdir/-auxdir does not work in all cases because @OUTDIR@ and
# @PRIVATE_DIR@ can be relative paths)
# Without the -g flag, latexmk remembers a previous build failure and will refuse
# to recompile even if the error has been fixed in the TeX source
latexmk_command = [ latexmk_exe, '-pdf', '-g', '-outdir=@OUTDIR@', '-auxdir=@PRIVATE_DIR@', '@INPUT@']
# The \graphicspath{} command does not compute directories relative to TEXINPUTS,
# so add these manually
logos_dir = meson.current_source_dir() / 'logos'
macroprocessor_pdf = custom_target('macroprocessor.pdf',
output : 'macroprocessor.pdf',
input : 'macroprocessor/macroprocessor.tex',
command : latexmk_command,
env : { 'TEXINPUTS': meson.current_source_dir()
+ '/macroprocessor:' + logos_dir + ':' },
depend_files : [ 'macroprocessor/new-design.pdf',
'logos/dlogo.png' ],
build_by_default : false,
install : true,
install_dir : 'share/doc/dynare')
preprocessor_pdf = custom_target('preprocessor.pdf',
output : 'preprocessor.pdf',
input : 'preprocessor/preprocessor.tex',
command : latexmk_command,
env : { 'TEXINPUTS': meson.current_source_dir() + '/preprocessor:'
+ logos_dir + ':' },
depend_files : [ 'preprocessor/expr.png',
'preprocessor/expr-sharing.png',
'preprocessor/json-preprocessor.png',
'preprocessor/matrices.png',
'preprocessor/overview.png', 'logos/dlogo.png' ],
build_by_default : false,
install : true,
install_dir : 'share/doc/dynare')
if HAVE_PDFLATEX
if HAVE_BEAMER
pdf-local: preprocessor.pdf
endif
endif
SRC = preprocessor.tex expr.png expr-sharing.png matrices.png overview.png json-preprocessor.png
EXTRA_DIST = $(SRC)
preprocessor.pdf: $(SRC)
$(PDFLATEX) preprocessor
$(PDFLATEX) preprocessor
clean-local:
rm -f *.pdf *.toc *.aux *.log *.nav *.snm *.vrb *.out *~
\documentclass{beamer}
%\documentclass[draft]{beamer}
%\documentclass[handout]{beamer}
\mode<handout>
{
\usepackage{pgfpages}
\pgfpagesuselayout{4 on 1}[a4paper,border shrink=3mm,landscape]
\usetheme{Madrid}
\usecolortheme{seagull}
}
\mode<beamer>
{
\usetheme{Madrid}
\setbeamercovered{transparent}
}
\documentclass[aspectratio=169]{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{amsmath}
\usepackage[copyright]{ccicons}
\usetheme{Boadilla}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\newenvironment{witemize}{\itemize\addtolength{\itemsep}{8pt}}{\enditemize}
\newenvironment{wenumerate}{\enumerate\addtolength{\itemsep}{8pt}}{\enditemize}
\usepackage{times}
\usepackage[copyright]{ccicons}
\graphicspath{{../logos}}
\titlegraphic{\includegraphics{dlogo.png}}
\title{The Dynare Preprocessor}
\author[S. Villemot, H.Bastani]{Sébastien Villemot \and Houtan Bastani}
\institute{CEPREMAP}
\institute[CEPREMAP]{\includegraphics[scale=0.15]{cepremap.jpg}}
\date{1 February 2017}
\setbeamertemplate{title page}
{
\vbox{}
\begingroup
\centering
{\usebeamercolor[fg]{titlegraphic}\inserttitlegraphic\par}\vskip1em
\begin{beamercolorbox}[sep=8pt,center]{title}
\usebeamerfont{title}\inserttitle\par%
\ifx\insertsubtitle\@empty%
\else%
\vskip0.25em%
{\usebeamerfont{subtitle}\usebeamercolor[fg]{subtitle}\insertsubtitle\par}%
\fi%
\end{beamercolorbox}%
\vskip1em\par
\begin{beamercolorbox}[sep=8pt,center]{author}
\usebeamerfont{author}\insertauthor
\end{beamercolorbox}
\begin{beamercolorbox}[sep=8pt,center]{institute}
\usebeamerfont{institute}\insertinstitute
\end{beamercolorbox}
\begin{beamercolorbox}[sep=8pt,center]{date}
\usebeamerfont{date}\insertdate
\end{beamercolorbox}
\endgroup
\vfill
}
\AtBeginSection[]
{
\begin{frame}{Outline}
......@@ -48,10 +68,10 @@
\column{0.2\textwidth}
\column{0.09\textwidth}
\ccbysa
\ccbysa
\column{0.71\textwidth}
\tiny
Copyright © 2007--2017 Dynare Team \\
Copyright © 2007--2023 Dynare Team \\
Licence: \href{http://creativecommons.org/licenses/by-sa/4.0/}{Creative
Commons Attribution-ShareAlike 4.0}
\end{columns}
......@@ -72,35 +92,106 @@
\begin{frame}
\frametitle{Calling Dynare}
\begin{itemize}
\begin{witemize}
\item Dynare is called from the host language platform with the syntax \texttt{dynare <<filename>>.mod}
\item This call can be followed by certain options:
\begin{itemize}
\item Some of these options impact host language platform functionality, \textit{e.g.} \texttt{nograph} prevents graphs from being displayed in Matlab
\item Some cause differences in the output created by default, \textit{e.g.} \texttt{notmpterms} prevents temporary terms from being written to the static/dynamic files
\item While others impact the functionality of the macroprocessor or the preprocessor, \textit{e.g.} \texttt{nostrict} shuts off certain checks that the preprocessor does by defalut
\item Some of these options impact host language platform functionality\\
$\rightarrow$ \textit{e.g.} \texttt{nograph} prevents graphs from being displayed in MATLAB
\item Some cause differences in the output created by default\\
$\rightarrow$ \texttt{notmpterms} prevents temporary terms from being written to the static/dynamic files
\item While others impact the functionality of the macroprocessor or the preprocessor\\
$\rightarrow$ \textit{e.g.} \texttt{nostrict} shuts off certain checks that the preprocessor does by default
\end{itemize}
\item MATLAB command line supports syntax completion since Dynare 6.x
\end{witemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Command line options in the mod-file}
\begin{witemize}
\item Command line options can alternatively be defined in the first line of the .mod file
\item Avoids to always have to invoke an option at the command line\\
$\rightarrow$ particularly useful for the \texttt{nostrict} option during the development phase of a model
\item Definition must be
\begin{itemize}
\item a one-line Dynare comment, i.e. begin //
\item the options must be enclosed in \texttt{----+ options:} and \texttt{+----} and must be whitespace separated
\item As in the command line, if an option admits a value, the equal symbol must not be surrounded by spaces
\end{itemize}
\begin{block}{Example}
\begin{verbatim}
// --+ options: json=compute, stochastic, nostrict +--
\end{verbatim}
\end{block}
\end{witemize}
\end{frame}
\section{Macro processing}
\begin{frame}
\frametitle{Macro processing}
\begin{witemize}
\item The Dynare macro language provides a set of macro commands that can be used in \texttt{mod} files
\item The macro processor employs text expansions/inclusions to transform a \texttt{mod} file with macro commands into a \texttt{mod} file without macro commands\\
$\rightarrow$ result can be stored using \texttt{savemacro} option
\item The result is fed to the parser\\
$\rightarrow$ use \texttt{onlymacro} to stop after macro processing before parsing
\item Attention: the macro processor only does text substitution; objects computed in later steps are not available yet and cannot be conditioned on for that reason
\end{witemize}
\end{frame}
\section{Parsing}
\begin{frame}
\frametitle{Parsing overview}
\begin{itemize}
\begin{witemize}
\item Parsing is the action of transforming an input text (a \texttt{mod} file in our case) into a data structure suitable for computation
\item The parser consists of three components:
\begin{itemize}
\begin{wenumerate}
\item the \alert{lexical analyzer}, which recognizes the ``words'' of the \texttt{mod} file (analog to the \textit{vocabulary} of a language)
\item the \alert{syntax analyzer}, which recognizes the ``sentences'' of the \texttt{mod} file (analog to the \textit{grammar} of a language)
\item the \alert{parsing driver}, which coordinates the whole process and constructs the data structure using the results of the lexical and syntax analyses
\end{itemize}
\end{itemize}
\end{wenumerate}
\end{witemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Undesired Parsing}
\begin{witemize}
\item Dynare will try to parse all tokens it recognizes
\item Code not recognized by the parser is directly passed to the preprocessor output\\
$\rightarrow$ allows using MATLAB/Octave commands directly in the mod-file
\item Causes problems when one wants to invoke commands containing recognized tokens
\end{witemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Bypassing the parsing}
\begin{witemize}
\item The \texttt{verbatim} block instructs Dynare not to parse text contained in it
\item In the following example, \texttt{stoch\_simul} would otherwise be recognized as a Dynare command during parsing
\end{witemize}
\begin{block}{Verbatim example}
\begin{verbatim}
verbatim;
rhos = [ 0.8, 0.9, 1];
for iter = 1:length(rhos)
set_param_value('rho',rhos(iter));
[info, oo_, options_, M_] = stoch_simul(M_, options_, oo_, var_list_)
if info(1)~=0
error('Simulation failed for parameter draw')
end
end
end;
\end{verbatim}
\end{block}
\end{frame}
\begin{frame}
\frametitle{Lexical analysis}
\begin{itemize}
\frametitle{1.\ Lexical analysis}
\begin{witemize}
\item The lexical analyzer recognizes the ``words'' (or \alert{lexemes}) of the language
\item Defined in \texttt{DynareFlex.ll}, it is transformed into C++ source code by the program \texttt{flex}
\item This file details the list of known lexemes (described by regular expressions) and the associated \alert{token} for each of them
......@@ -108,7 +199,7 @@
\item For variable names or numbers, the token also contains the associated string for further processing
%\item \textit{Note:} the list of tokens can be found at the beginning of \texttt{DynareBison.yy}
\item When invoked, the lexical analyzer reads the next characters of the input, tries to recognize a lexeme, and either produces an error or returns the associated token
\end{itemize}
\end{witemize}
\end{frame}
\begin{frame}[fragile]
......@@ -143,7 +234,7 @@ SEMICOLON
\end{frame}
\begin{frame}
\frametitle{Syntax analysis}
\frametitle{2.\ Syntax analysis}
\framesubtitle{In Dynare}
\begin{itemize}
\item The \texttt{mod} file grammar is described in \texttt{DynareBison.yy}, which is transformed into C++ source code by the program \texttt{bison}
......@@ -185,13 +276,13 @@ expression := expression PLUS expression
\begin{frame}
\frametitle{Semantic actions}
\begin{itemize}
\item So far we have only described how to accept valid \texttt{mod} files and to reject others
\begin{witemize}
\item So far we have only described how to accept valid \texttt{mod} files and reject others
\item But validating is not enough: one needs to do something with the parsed \texttt{mod} file
\item Every grammar rule can have a \alert{semantic action} associated with it: C/C++ code enclosed by curly braces
\item Every rule can return a semantic value (referenced by \texttt{\$\$} in the action)
\item In the action, it is possible to refer to semantic values returned by components of the rule (using \texttt{\$1}, \texttt{\$2}, \ldots)
\end{itemize}
\end{witemize}
\end{frame}
\begin{frame}[fragile]
......@@ -222,15 +313,15 @@ expression := expression PLUS expression
\end{frame}
\begin{frame}
\frametitle{Parsing driver}
\frametitle{3.\ Parsing driver}
The class \texttt{ParsingDriver} has the following roles:
\begin{itemize}
\begin{witemize}
\item It opens the \texttt{mod} file and launches the lexical and syntaxic analyzers on it
\item It implements most of the semantic actions of the grammar
\item By doing so, it creates an object of type \texttt{ModFile}, which is the data structure representing the \texttt{mod} file
\item Or, if there is a parsing error (unknown keyword, undeclared symbol, syntax error), it displays the line and column numbers where the error occurred and exits
\end{itemize}
\end{witemize}
\end{frame}
\section{Data structure representing a \texttt{mod} file}
......@@ -254,7 +345,7 @@ The class \texttt{ParsingDriver} has the following roles:
\begin{frame}
\frametitle{The symbol table (1/3)}
\begin{itemize}
\begin{witemize}
\item A \alert{symbol} is simply the name of a variable (endogenous, exogenous, local, auxiliary, etc), parameter, external function, \ldots basically everything that is not recognized as a Dynare keyword
\item \alert{SymbolTable} is a simple class used to maintain the list of the symbols used in the \texttt{mod} file
\item For each symbol, it stores:
......@@ -263,7 +354,7 @@ The class \texttt{ParsingDriver} has the following roles:
\item its type (an enumerator defined in \texttt{CodeInterpreter.hh})
\item a unique integer identifier (also has a unique identifier by type)
\end{itemize}
\end{itemize}
\end{witemize}
\end{frame}
\begin{frame}
......@@ -285,20 +376,20 @@ The class \texttt{ParsingDriver} has the following roles:
\begin{frame}
\frametitle{The symbol table (3/3)}
\begin{itemize}
\begin{witemize}
\item Symbol table filled in:
\begin{itemize}
\begin{witemize}
\item using the \texttt{var}, \texttt{varexo}, \texttt{varexo\_det}, \texttt{parameter}, \texttt{external\_function}, \texttt{trend\_var}, and \texttt{log\_trend\_var} declarations
\item using pound sign (\#) constructions in the model block
\item using pound sign (\#) constructions (``model-local variables'') in the model block
\item on the fly during parsing: local variables outside models or unknown functions when an undeclared symbol is encountered
\item during the creation of auxiliary variables in the transform pass
\end{itemize}
\end{witemize}
\item Roles of the symbol table:
\begin{itemize}
\item permits parcimonious and more efficient representation of expressions (no need to duplicate or compare strings, only handle a pair of integers)
\begin{witemize}
\item permits parsimonious and more efficient representation of expressions (no need to duplicate or compare strings, only handle a pair of integers)
\item ensures that a given symbol is used with only one type
\end{itemize}
\end{itemize}
\end{witemize}
\end{witemize}
\end{frame}
\begin{frame}
......@@ -317,30 +408,30 @@ The class \texttt{ParsingDriver} has the following roles:
\begin{frame}
\frametitle{Expression trees (2/3)}
\begin{itemize}
\begin{witemize}
\item A tree node is represented by an instance of the abstract class \texttt{ExprNode}
\item This class has 5 sub-classes, corresponding to the 5 types of non-external-function nodes:
\begin{itemize}
\begin{wenumerate}
\item \texttt{NumConstNode} for constant nodes: contains the identifier of the numerical constants it represents
\item \texttt{VariableNode} for variable/parameters nodes: contains the identifier of the variable or parameter it represents
\item \texttt{UnaryOpNode} for unary operators (\textit{e.g.} unary minus, $\log$, $\sin$): contains an enumerator representing the operator, and a pointer to its child
\item \texttt{BinaryOpNode} for binary operators (\textit{e.g.} $+$, $*$, pow): contains an enumerator representing the operator, and pointers to its two children
\item \texttt{TrinaryOpNode} for trinary operators (\textit{e.g.} $normcdf$, $normpdf$): contains an enumerator representing the operator and pointers to its three children
\end{itemize}
\end{itemize}
\end{wenumerate}
\end{witemize}
\end{frame}
\begin{frame}
\frametitle{Expression trees (3/3)}
\begin{itemize}
\begin{witemize}
\item The abstract class \texttt{ExprNode} has an abstract sub-class called \texttt{AbstractExternalFunctionNode}
\item This abstract sub-class has 3 sub-classes, corresponding to the 3 types of external function nodes:
\begin{itemize}
\begin{wenumerate}
\item \texttt{ExternalFunctionNode} for external functions. Contains the identifier of the external function and a vector of its arguments
\item \texttt{FirstDerivExternalFunctionNode} for the first derivative of an external function. In addition to the information contained in \texttt{ExternalFunctionNode}, contains the index w.r.t. which this node is the derivative.
\item \texttt{SecondDerivExternalFunctionNode} for the second derivative of an external function. In addition to the information contained in \texttt{FirstDerivExternalFunctionNode}, contains the index w.r.t. which this node is the second derivative.
\end{itemize}
\end{itemize}
\end{wenumerate}
\end{witemize}
\end{frame}
......@@ -367,28 +458,28 @@ The class \texttt{ParsingDriver} has the following roles:
\begin{frame}
\frametitle{Constructing expression trees}
\begin{itemize}
\begin{witemize}
\item Class \texttt{DataTree} contains a set of methods for constructing expression trees
\item Construction is done bottom-up, node by node:
\begin{itemize}
\begin{witemize}
\item one method for adding a constant node (\texttt{AddPossiblyNegativeConstant(double)})
\item one method for a log node (\texttt{AddLog(arg)})
\item one method for a plus node (\texttt{AddPlus(arg1, arg2)})
\end{itemize}
\end{witemize}
\item These methods take pointers to \texttt{ExprNode}, allocate the memory for the node, construct it, and return its pointer
\item These methods are called:
\begin{itemize}
\begin{witemize}
\item from \texttt{ParsingDriver} in the semantic actions associated to the parsing of expressions
\item during symbolic derivation, to create derivatives expressions
\item during symbolic derivation to create derivatives expressions
\item when creating the static model from the dynamic model
\item \ldots
\end{itemize}
\end{itemize}
\end{witemize}
\end{witemize}
\end{frame}
\begin{frame}
\frametitle{Reduction of constants and symbolic simplifications}
\begin{itemize}
\begin{witemize}
\item The construction methods compute constants whenever possible
\begin{itemize}
\item Suppose you ask to construct the node $1+1$
......@@ -405,19 +496,20 @@ The class \texttt{ParsingDriver} has the following roles:
\item $x^0 = 1$
\end{itemize}
\item When a simplification rule applies, no new node is created
\end{itemize}
\item Attention: this may cause the program to detect issues not directly visible to users like a division by 0
\end{witemize}
\end{frame}
\begin{frame}
\frametitle{Sub-expression sharing (1/2)}
\begin{itemize}
\begin{witemize}
\item Consider the two following expressions: $(1+z)*\log(y)$ and $2^{(1+z)}$
\item Expressions share a common sub-expression: $1+z$
\item The internal representation of these expressions is:
\begin{center}
\includegraphics[width=7cm]{expr-sharing.png}
\end{center}
\end{itemize}
\end{witemize}
\end{frame}
\begin{frame}
......@@ -438,107 +530,107 @@ The class \texttt{ParsingDriver} has the following roles:
\begin{frame}
\frametitle{Final remarks about expressions}
\begin{itemize}
\begin{witemize}
\item Storage of negative constants
\begin{itemize}
\begin{witemize}
\item class \texttt{NumConstNode} only accepts positive constants
\item a negative constant is stored as a unary minus applied to a positive constant
\item this is a kind of identification constraint to avoid having two ways of representing negative constants: $(-2)$ and $-(2)$
\end{itemize}
\end{witemize}
\item Widely used constants
\begin{itemize}
\begin{witemize}
\item class \texttt{DataTree} has attributes containing pointers to constants: $0$, $1$, $2$, $-1$, \texttt{NaN}, $\infty$, $-\infty$, and $\pi$
\item these constants are used in many places (in simplification rules, in derivation algorithm\ldots)
\item sub-expression sharing algorithm ensures that these constants will never be duplicated
\end{itemize}
\end{itemize}
\end{witemize}
\end{witemize}
\end{frame}
\begin{frame}
\frametitle{List of statements}
\begin{itemize}
\begin{witemize}
\item A statement is represented by an instance of a subclass of the abstract class \texttt{Statement}
\item Three groups of statements:
\begin{itemize}
\item initialization statements (parameter initialization with $p = \ldots$, \texttt{initval}, \texttt{histval}, or \texttt{endval} block)
\item shocks blocks (\texttt{shocks}, \texttt{mshocks}, \ldots)
\item computing tasks (\texttt{steady}, \texttt{check}, \texttt{simul}, \ldots)
\item computing tasks (\texttt{steady}, \texttt{check}, \texttt{perfect\_foresight\_solver}, \ldots)
\end{itemize}
\item Each type of statement has its own class (\textit{e.g.} \texttt{InitValStatement}, \texttt{SimulStatement}, \ldots)
\item Each type of statement has its own class (\textit{e.g.} \texttt{InitValStatement}, \texttt{PerfectForesightSolverStatement}, \ldots)
\item The class \texttt{ModFile} stores a list of pointers of type \texttt{Statement*}, corresponding to the statements of the \texttt{mod} file, in their order of declaration
\item Heavy use of polymorphism in the check pass, computing pass, and when writing outputs: abstract class \texttt{Statement} provides a virtual method for these 3 actions
\end{itemize}
\end{witemize}
\end{frame}
\begin{frame}
\frametitle{Evaluation context}
\begin{itemize}
\begin{witemize}
\item The \texttt{ModFile} class contains an \alert{evaluation context}
\item It is a map associating a numerical value to some symbols
\item Filled in with \texttt{initval} block values and parameter initializations
\item Used during equation normalization (in the block decomposition), for finding non-zero entries in the jacobian
\item Used in testing that trends are compatible with a balanced growth path, for finding non-zero cross partials of equations with respect to trend variables and endogenous varibales
\end{itemize}
\item Used during equation normalization (in the block decomposition), for finding non-zero entries in the Jacobian
\item Used in testing that trends are compatible with a balanced growth path, for finding non-zero cross partials of equations with respect to trend variables and endogenous variables
\end{witemize}
\end{frame}
\section{Check pass}
\begin{frame}
\frametitle{Error checking during parsing}
\begin{itemize}
\begin{witemize}
\item Some errors in the \texttt{mod} file can be detected during parsing:
\begin{itemize}
\begin{witemize}
\item syntax errors
\item use of undeclared symbols in model block, initval block\ldots
\item use of a symbol incompatible with its type (\textit{e.g.} parameter in initval, local variable used both in model and outside model)
\item multiple shock declarations for the same variable
\end{itemize}
\end{witemize}
\item But some other checks can only be done when parsing is completed\ldots
\end{itemize}
\end{witemize}
\end{frame}
\begin{frame}
\frametitle{Check pass}
\begin{itemize}
\begin{witemize}
\item The check pass is implemented through the method \texttt{ModFile::checkPass()}
\item Performs many checks. Examples include:
\begin{itemize}
\begin{witemize}
\item check there is at least one equation in the model (except if doing a standalone BVAR estimation)
\item checks for coherence in statements (\textit{e.g.} options passed to statements do not conflict with each other, required options have been passed)
\item checks for coherence among statements (\textit{e.g.} if \texttt{osr} statement is present, ensure \texttt{osr\_params} and \texttt{optim\_weights} statements are present)
\item checks for coherence between statements and attributes of \texttt{mod} file (\textit{e.g.} \texttt{use\_dll} is not used with \texttt{block} or \texttt{bytecode})
\end{itemize}
\end{itemize}
\end{witemize}
\end{witemize}
\end{frame}
\section{Transform pass}
\begin{frame}
\frametitle{Transform pass (1/2)}
\begin{itemize}
\begin{witemize}
\item The transform pass is implemented through the method \texttt{ModFile::transformPass(bool nostrict)}
\item It makes necessary transformations (notably to the dynamic model, symbol table, and statements list) preparing the \texttt{ModFile} object for the computing pass. Examples of transformations include:
\begin{itemize}
\item It makes necessary transformations (notably to the dynamic model, symbol table, and statements list), preparing the \texttt{ModFile} object for the computing pass. Examples of transformations include:
\begin{witemize}
\item creation of auxiliary variables and equations for leads, lags, expectation operator, differentiated forward variables, etc.
\item detrending of model equations if nonstationary variables are present
\item decreasing leads/lags of predetermined variables by one period
\item addition of FOCs of Langrangian for Ramsey problem
\item addition of FOCs of Lagrangian for Ramsey problem
\item addition of \texttt{dsge\_prior\_weight} initialization before all other statements if estimating a DSGE-VAR where the weight of the DSGE prior of the VAR is calibrated
\end{itemize}
\end{itemize}
\end{witemize}
\end{witemize}
\end{frame}
\begin{frame}
\frametitle{Transform pass (2/2)}
\begin{itemize}
\begin{witemize}
\item It then freezes the symbol table, meaning that no more symbols can be created on the \texttt{ModFile} object
\item Finally checks are performed on the transformed model. Examples include:
\begin{itemize}
\item same number of endogenous varibables as equations (not done in certain situations, \textit{e.g.} Ramsey, discretionary policy, etc.)
\item correspondence among variables and statements, \textit{e.g.} Ramsey policy, identification, perfect foresight solver, and simul are incompatible with deterministic exogenous variables
\item correspondence among statements, \textit{e.g.} for DSGE-VAR without \texttt{bayesian\_irf} option, the number of shocks must be greater than or equal to the number of observed variables
\end{itemize}
\end{itemize}
\item Finally, checks are performed on the transformed model. Examples include:
\begin{witemize}
\item same number of endogenous variables as equations (not done in certain situations, \textit{e.g.} Ramsey, discretionary policy, where checks are done in MATLAB)
\item correspondence among variables and statements, \textit{e.g.} Ramsey policy, identification, perfect foresight solver, and perfect foresight solver are incompatible with deterministic exogenous variables
\item correspondence among statements, \textit{e.g.} for DSGE-VAR with \texttt{bayesian\_irf} option, the number of shocks must be equal to the number of observed variables
\end{witemize}
\end{witemize}
\end{frame}
......@@ -548,9 +640,9 @@ The class \texttt{ParsingDriver} has the following roles:
\frametitle{Overview of the computing pass}
\begin{itemize}
\item Computing pass implemented in \texttt{ModFile::computingPass()}
\item Creates Static model from Dynamic (by removing leads/lags)
\item Creates static model from dynamic one (by removing leads/lags)
\item Determines which derivatives to compute
\item Then calls \texttt{DynamicModel::computingPass()} which computes:
\item Then calls \texttt{DynamicModel::computingPass()}, which computes:
\begin{itemize}
\item leag/lag variable incidence matrix
\item symbolic derivatives w.r.t. endogenous, exogenous, and parameters, if needed
......@@ -558,34 +650,34 @@ The class \texttt{ParsingDriver} has the following roles:
\item temporary terms
\item computes equation cross references, if desired
\end{itemize}
\item NB: analagous operations for Static model are performed by \texttt{StaticModel::computingPass()}
\item Asserts that equations declared linear are indeed linear (by checking that Hessian == 0)
\item NB: analogous operations for static model are performed by \texttt{StaticModel::computingPass()}
\item Asserts that equations declared \texttt{linear} are indeed linear (by checking that Hessian == 0)
\item Finally, calls \texttt{Statement::computingPass()} on all statements
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Model Variables}
\begin{itemize}
\begin{witemize}
\item In the context of class \texttt{ModelTree}, a \alert{variable} is a pair (symbol, lag)
\item The symbol must correspond to a variable of type endogenous, exogenous, deterministic exogenous variable, or parameter
\item The \texttt{SymbolTable} class keeps track of valid symbols while the \texttt{variable\_node\_map} keeps track of model variables (symbol, lag pairs stored in \texttt{VariableNode} objects)
\item The \texttt{SymbolTable} class keeps track of valid symbols, while the \texttt{variable\_node\_map} keeps track of model variables (symbol, lag pairs stored in \texttt{VariableNode} objects)
\item After the computing pass, the \texttt{DynamicModel} class writes the leag/lag incidence matrix:
\begin{itemize}
\item three rows: the first row indicates $t-1$, the second row $t$, and the third row $t+1$
\begin{witemize}
\item \texttt{max\_lag + max\_lead + 1} rows (usually 3): the first row indicates $t-1$ (if applicable), the second row $t$, and the third row $t+1$ (if applicable)
\item one column for every endogenous symbol in order of declaration; NB: includes endogenous auxiliary variables created during the transform pass
\item elements of the matrix are either 0 (if the variable does not appear in the model) or correspond to the variable's column in the Jacobian of the dynamic model
\end{itemize}
\end{itemize}
\end{witemize}
\end{witemize}
\end{frame}
\begin{frame}
\frametitle{Static versus dynamic model}
\begin{itemize}
\begin{witemize}
\item The static model is simply the dynamic model without leads and lags
\item Static model used to characterize the steady state
\item The jacobian of the static model is used in the (Matlab) solver for determining the steady state
\end{itemize}
\item The Jacobian of the static model is used in the (MATLAB) solver for determining the steady state
\end{witemize}
\begin{block}{Example}
\begin{itemize}
\item suppose dynamic model is $2x_t \cdot x_{t-1} = 0$
......@@ -598,41 +690,41 @@ The class \texttt{ParsingDriver} has the following roles:
\begin{frame}
\frametitle{Which derivatives to compute?}
\begin{itemize}
\begin{witemize}
\item In deterministic mode:
\begin{itemize}
\item static jacobian w.r.t. endogenous variables only
\item dynamic jacobian w.r.t. endogenous variables only
\item static Jacobian w.r.t. endogenous variables only
\item dynamic Jacobian w.r.t. endogenous variables only
\end{itemize}
\item In stochastic mode:
\begin{itemize}
\item static jacobian w.r.t. endogenous variables only
\item dynamic jacobian w.r.t. endogenous, exogenous, and deterministic exogenous variables
\item dynamic hessian w.r.t. endogenous, exogenous, and deterministic exogenous variables
\item static Jacobian w.r.t. endogenous variables only
\item dynamic Jacobian w.r.t. endogenous, exogenous, and deterministic exogenous variables
\item dynamic Hessian w.r.t. endogenous, exogenous, and deterministic exogenous variables
\item possibly dynamic 3rd derivatives (if \texttt{order} option $\geq 3$)
\item possibly dynamic jacobian and/or hessian w.r.t. parameters (if \texttt{identification} or analytic derivs needed for \texttt{estimation} and \texttt{params\_derivs\_order} $>0$)
\item possibly dynamic Jacobian and/or Hessian w.r.t. parameters (if \texttt{identification} or analytic derivs needed for \texttt{estimation} and \texttt{params\_derivs\_order} $>0$)
\end{itemize}
\item For Ramsey policy: the same as above, but with one further order of derivation than declared by the user with \texttt{order} option (the derivation order is determined in the check pass, see \texttt{RamseyPolicyStatement::checkPass()})
\end{itemize}
\end{witemize}
\end{frame}
\begin{frame}
\frametitle{Derivation algorithm (1/2)}
\begin{itemize}
\begin{witemize}
\item Derivation of the model implemented in \texttt{ModelTree::computeJacobian()}, \texttt{ModelTree::computeHessian()}, \texttt{ModelTree::computeThirdDerivatives()}, and \texttt{ModelTree::computeParamsDerivatives()}
\item Simply call \texttt{ExprNode::getDerivative(deriv\_id)} on each equation node
\item Use of polymorphism:
\begin{itemize}
\begin{witemize}
\item for a constant or variable node, derivative is straightforward ($0$ or $1$)
\item for a unary, binary, trinary op nodes and external function nodes, recursively calls method \texttt{computeDerivative()} on children to construct derivative
\end{itemize}
\end{itemize}
\end{witemize}
\end{witemize}
\end{frame}
\begin{frame}
\frametitle{Derivation algorithm (2/2)}
\framesubtitle{Optimizations}
\begin{itemize}
\begin{witemize}
\item Caching of derivation results
\begin{itemize}
\item method \texttt{ExprNode::getDerivative(deriv\_id)} memorizes its result in a member attribute (\texttt{derivatives}) the first time it is called
......@@ -642,21 +734,21 @@ The class \texttt{ParsingDriver} has the following roles:
\item Efficiently finds symbolic derivatives equal to $0$
\begin{itemize}
\item consider the expression $x+y^2$
\item without any computation, you know its derivative w.r.t. $z$ is zero
\item without any computation, you know its derivative w.r.t.\ $z$ is zero
\item each node stores in an attribute (\texttt{non\_null\_derivatives}) the set of variables which appear in the expression it represents ($\{x,y\}$ in the example)
\item this set is computed in \texttt{prepareForDerivation()}
\item when \texttt{getDerivative(deriv\_id)} is called, immediately returns zero if \texttt{deriv\_id} is not in that set
\end{itemize}
\end{itemize}
\end{witemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Temporary terms (1/2)}
\begin{itemize}
\item When the preprocessor writes equations and derivatives in its outputs, it takes advantage of sub-expression sharing
\item In Matlab static and dynamic output files, equations are preceded by a list of \alert{temporary terms}
\item In MATLAB static and dynamic output files, equations are preceded by a list of \alert{temporary terms}
\item These terms are variables containing expressions shared by several equations or derivatives
\item Using these terms greatly enhances the computing speed of the model residual, jacobian, hessian, or third derivative
\item Using these terms greatly enhances the computing speed of the model residual, Jacobian, Hessian, or third derivative
\end{itemize}
\begin{block}{Example}
\begin{columns}[t]
......@@ -681,26 +773,27 @@ residual(1)=3*T1+1;
\begin{frame}
\frametitle{Temporary terms (2/2)}
\begin{itemize}
\item Expression storage in the preprocessor implements maximal sharing but this is not optimal for the Matlab output files, because creating a temporary variable also has a cost (in terms of CPU and of memory)
\begin{witemize}
\item Expression storage in the preprocessor implements maximal sharing, but this is not optimal for the MATLAB output files, because creating a temporary variable also has a cost (in terms of CPU and of memory)
\item Computation of temporary terms implements a trade-off between:
\begin{itemize}
\begin{witemize}
\item cost of duplicating sub-expressions
\item cost of creating new variables
\end{itemize}
\end{witemize}
\item Algorithm uses a recursive cost calculation, which marks some nodes as being ``temporary''
\item \textit{Problem}: redundant with optimizations done by the C/C++ compiler (when Dynare is in DLL mode) $\Rightarrow$ compilation very slow on big models
\end{itemize}
\item \textit{Problem}: redundant with optimizations done by the C/C++ compiler (when Dynare is in DLL mode)\\
$\Rightarrow$ compilation very slow on big models
\end{witemize}
\end{frame}
\begin{frame}
\frametitle{The special case of Ramsey policy}
\begin{itemize}
\frametitle{The special case of Ramsey model}
\begin{witemize}
\item For most statements, the method \texttt{computingPass()} is a no-op\ldots
\item \ldots except for \texttt{planner\_objective} statement, which serves to declare planner objective when doing optimal policy under commitment
\item Class \texttt{PlannerObjectiveStatement} contains an instance of \texttt{ModelTree}, which stores the objective function (\texttt{i.e.} only one equation in the tree)
\item Class \texttt{PlannerObjectiveStatement} contains an instance of \texttt{ModelTree} which stores the objective function (\texttt{i.e.} only one equation in the tree)
\item During the computing pass, triggers the computation of the first and second order (static) derivatives of the objective
\end{itemize}
\end{witemize}
\end{frame}
\section{Writing outputs}
......@@ -709,21 +802,22 @@ residual(1)=3*T1+1;
\frametitle{Output overview}
\begin{itemize}
\item Implemented in \texttt{ModFile::writeOutputFiles()}
\item If \texttt{mod} file is \texttt{model.mod}, all created filenames will begin with \texttt{model}
\item Main output file is \texttt{model.m}, containing:
\item If \texttt{mod} file is \texttt{mymodel.mod}, all created filenames will begin with \texttt{mymodel}
\item Main output file is \texttt{mymodel.driver}, containing:
\begin{itemize}
\item general initialization commands
\item symbol table output (from \texttt{SymbolTable::writeOutput()})
\item lead/lag incidence matrix (from \texttt{DynamicModel::writeDynamicMFile()})
\item call to Matlab functions corresponding to the statements of the \texttt{mod} file (written by calling \texttt{Statement::writeOutput()} on all statements through polymorphism)
\item call to MATLAB functions corresponding to the statements of the \texttt{mod} file (written by calling \texttt{Statement::writeOutput()} on all statements through polymorphism)
\end{itemize}
\item Subsidiary output files:
\begin{itemize}
\item one for the static model
\item one for the dynamic model
\item one for the auxiliary variables
\item for the static model (residuals, temporary terms, derivatives)
\item for the dynamic model (residuals, temporary terms, derivatives)
\item one for the auxiliary variables in the dynamic model (if relevant)
\item one for the steady state file (if relevant)
\item one for the planner objective (if relevant)
\item for the planner objective and Lagrange multipliers (static residuals and derivatives, if relevant)
\item one each for the static and dynamic parameter derivatives (if required)
\end{itemize}
\end{itemize}
\end{frame}
......@@ -732,20 +826,20 @@ residual(1)=3*T1+1;
\frametitle{Model output files}
Three possible output types:
\begin{itemize}
\item Matlab/Octave mode: static and dynamic files in Matlab
\item MATLAB/Octave mode: static and dynamic files in MATLAB
\item Julia mode: static and dynamic files in Julia
\item DLL mode:
\begin{itemize}
\item static and dynamic files in C++ source code (with corresponding headers)
\item compiled through \texttt{mex} to allow execution from within Matlab
\item compiled through \texttt{mex} to allow execution from within MATLAB
\end{itemize}
\item Sparse DLL mode:
\begin{itemize}
\item static file in Matlab
\item static file in MATLAB
\item two possibilities for dynamic file:
\begin{itemize}
\item by default, a C++ source file (with header) and a binary file, to be read from the C++ code
\item or, with \texttt{no\_compiler} option, a binary file in custom format, executed from Matlab through \texttt{simulate} DLL
\item or, with \texttt{no\_compiler} option, a binary file in custom format, executed from MATLAB through \texttt{simulate} DLL
\item the second option serves to bypass compilation of C++ file which can be very slow
\end{itemize}
\end{itemize}
......@@ -769,7 +863,7 @@ residual(1)=3*T1+1;
\item Dump preprocessor altogether: do everything with Julia
\begin{itemize}
\item Pros: simple to distribute, move away from C++ (no contributions, requires more expertise)
\item Cons: Matlab/Octave users must also download Julia, a big project, speed (?)
\item Cons: MATLAB/Octave users must also download Julia, a big project, speed (?)
\end{itemize}
\asuivre
\end{enumerate}
......@@ -813,7 +907,7 @@ residual(1)=3*T1+1;
\item No divergence of codebase: don't need to repeat code (checks, transformations, etc.) across platforms
\item Creates \texttt{mod} files that can be used on other host language platforms
\item Adds one more HLP library to distribute
\item Need to design/implement classes that will store processed dynare \texttt{mod} file in various HLPs
\item Need to design/implement classes that will store processed Dynare \texttt{mod} file in various HLPs
\end{itemize}
\end{frame}
......
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: Dynare-preprocessor
Upstream-Contact: Dynare Team, whose members in 2018 are:
Stéphane Adjemian <stephane.adjemian@univ-lemans.fr>
Houtan Bastani <houtan@dynare.org>
Michel Juillard <michel.juillard@mjui.fr>
Frédéric Karamé <frederic.karame@univ-lemans.fr>
Junior Maih <junior.maih@gmail.com>
Ferhat Mihoubi <fmihoubi@univ-evry.fr>
Johannes Pfeifer <jpfeifer@gmx.de>
Marco Ratto <marco.ratto@ec.europa.eu>
Sébastien Villemot <sebastien.villemot@sciencespo.fr>
Source: http://www.dynare.org
Files: *
Copyright: 1996-2018 Dynare Team
License: GPL-3+
Files: m4/ax_boost_base.m4
Copyright: 2008 Thomas Porschberg <thomas@randspringer.de>
2009 Peter Adolphs
License: permissive-autoconf
License: GPL-3+
Dynare is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
.
Dynare is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
.
You should have received a copy of the GNU General Public License
along with Dynare. If not, see <http://www.gnu.org/licenses/>.
License: GPL-3+ with Autoconf exception
This program is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Public License for more details.
.
You should have received a copy of the GNU General Public License along
with this program. If not, see <http://www.gnu.org/licenses/>.
.
As a special exception, the respective Autoconf Macro's copyright owner
gives unlimited permission to copy, distribute and modify the configure
scripts that are the output of Autoconf when processing the Macro. You
need not follow the terms of the GNU General Public License when using
or distributing such scripts, even though portions of the text of the
Macro appear in them. The GNU General Public License (GPL) does govern
all other use of the material that constitutes the Autoconf Macro.
.
This special exception to the GPL applies to versions of the Autoconf
Macro released by the Autoconf Archive. When you make and distribute a
modified version of the Autoconf Macro, you may extend this special
exception to the GPL to apply to your modified version as well.
License: LGPL-2.1+
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or (at
your option) any later version.
.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
General Public License for more details.
.
You should have received a copy of the GNU Lesser General Public License
along with this library. If not, see <http://www.gnu.org/licenses/>.
License: LGPL-3+
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
License: permissive-autoconf
Copying and distribution of this file, with or without modification, are
permitted in any medium without royalty provided the copyright notice
and this notice are preserved. This file is offered as-is, without any
warranty.
# ===========================================================================
# http://www.gnu.org/software/autoconf-archive/ax_boost_base.html
# ===========================================================================
#
# SYNOPSIS
#
# AX_BOOST_BASE([MINIMUM-VERSION], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
#
# DESCRIPTION
#
# Test for the Boost C++ libraries of a particular version (or newer)
#
# If no path to the installed boost library is given the macro searchs
# under /usr, /usr/local, /opt and /opt/local and evaluates the
# $BOOST_ROOT environment variable. Further documentation is available at
# <http://randspringer.de/boost/index.html>.
#
# This macro calls:
#
# AC_SUBST(BOOST_CPPFLAGS) / AC_SUBST(BOOST_LDFLAGS)
#
# And sets:
#
# HAVE_BOOST
#
# LICENSE
#
# Copyright (c) 2008 Thomas Porschberg <thomas@randspringer.de>
# Copyright (c) 2009 Peter Adolphs
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
# and this notice are preserved. This file is offered as-is, without any
# warranty.
#serial 21
AC_DEFUN([AX_BOOST_BASE],
[
AC_ARG_WITH([boost],
[AS_HELP_STRING([--with-boost@<:@=ARG@:>@],
[use Boost library from a standard location (ARG=yes),
from the specified location (ARG=<path>),
or disable it (ARG=no)
@<:@ARG=yes@:>@ ])],
[
if test "$withval" = "no"; then
want_boost="no"
elif test "$withval" = "yes"; then
want_boost="yes"
ac_boost_path=""
else
want_boost="yes"
ac_boost_path="$withval"
fi
],
[want_boost="yes"])
AC_ARG_WITH([boost-libdir],
AS_HELP_STRING([--with-boost-libdir=LIB_DIR],
[Force given directory for boost libraries. Note that this will override library path detection, so use this parameter only if default library detection fails and you know exactly where your boost libraries are located.]),
[
if test -d "$withval"
then
ac_boost_lib_path="$withval"
else
AC_MSG_ERROR(--with-boost-libdir expected directory name)
fi
],
[ac_boost_lib_path=""]
)
if test "x$want_boost" = "xyes"; then
boost_lib_version_req=ifelse([$1], ,1.20.0,$1)
boost_lib_version_req_shorten=`expr $boost_lib_version_req : '\([[0-9]]*\.[[0-9]]*\)'`
boost_lib_version_req_major=`expr $boost_lib_version_req : '\([[0-9]]*\)'`
boost_lib_version_req_minor=`expr $boost_lib_version_req : '[[0-9]]*\.\([[0-9]]*\)'`
boost_lib_version_req_sub_minor=`expr $boost_lib_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
if test "x$boost_lib_version_req_sub_minor" = "x" ; then
boost_lib_version_req_sub_minor="0"
fi
WANT_BOOST_VERSION=`expr $boost_lib_version_req_major \* 100000 \+ $boost_lib_version_req_minor \* 100 \+ $boost_lib_version_req_sub_minor`
AC_MSG_CHECKING(for boostlib >= $boost_lib_version_req)
succeeded=no
dnl On 64-bit systems check for system libraries in both lib64 and lib.
dnl The former is specified by FHS, but e.g. Debian does not adhere to
dnl this (as it rises problems for generic multi-arch support).
dnl The last entry in the list is chosen by default when no libraries
dnl are found, e.g. when only header-only libraries are installed!
libsubdirs="lib"
ax_arch=`uname -m`
case $ax_arch in
x86_64|ppc64|s390x|sparc64|aarch64)
libsubdirs="lib64 lib lib64"
;;
esac
dnl first we check the system location for boost libraries
dnl this location ist chosen if boost libraries are installed with the --layout=system option
dnl or if you install boost with RPM
if test "$ac_boost_path" != ""; then
BOOST_CPPFLAGS="-I$ac_boost_path/include"
for ac_boost_path_tmp in $libsubdirs; do
if test -d "$ac_boost_path"/"$ac_boost_path_tmp" ; then
BOOST_LDFLAGS="-L$ac_boost_path/$ac_boost_path_tmp"
break
fi
done
elif test "$cross_compiling" != yes; then
for ac_boost_path_tmp in /usr /usr/local /opt /opt/local ; do
if test -d "$ac_boost_path_tmp/include/boost" && test -r "$ac_boost_path_tmp/include/boost"; then
for libsubdir in $libsubdirs ; do
if ls "$ac_boost_path_tmp/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi
done
BOOST_LDFLAGS="-L$ac_boost_path_tmp/$libsubdir"
BOOST_CPPFLAGS="-I$ac_boost_path_tmp/include"
break;
fi
done
fi
dnl overwrite ld flags if we have required special directory with
dnl --with-boost-libdir parameter
if test "$ac_boost_lib_path" != ""; then
BOOST_LDFLAGS="-L$ac_boost_lib_path"
fi
CPPFLAGS_SAVED="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
export CPPFLAGS
LDFLAGS_SAVED="$LDFLAGS"
LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
export LDFLAGS
AC_REQUIRE([AC_PROG_CXX])
AC_LANG_PUSH(C++)
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
@%:@include <boost/version.hpp>
]], [[
#if BOOST_VERSION >= $WANT_BOOST_VERSION
// Everything is okay
#else
# error Boost version is too old
#endif
]])],[
AC_MSG_RESULT(yes)
succeeded=yes
found_system=yes
],[
])
AC_LANG_POP([C++])
dnl if we found no boost with system layout we search for boost libraries
dnl built and installed without the --layout=system option or for a staged(not installed) version
if test "x$succeeded" != "xyes"; then
_version=0
if test "$ac_boost_path" != ""; then
if test -d "$ac_boost_path" && test -r "$ac_boost_path"; then
for i in `ls -d $ac_boost_path/include/boost-* 2>/dev/null`; do
_version_tmp=`echo $i | sed "s#$ac_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'`
V_CHECK=`expr $_version_tmp \> $_version`
if test "$V_CHECK" = "1" ; then
_version=$_version_tmp
fi
VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'`
BOOST_CPPFLAGS="-I$ac_boost_path/include/boost-$VERSION_UNDERSCORE"
done
fi
else
if test "$cross_compiling" != yes; then
for ac_boost_path in /usr /usr/local /opt /opt/local ; do
if test -d "$ac_boost_path" && test -r "$ac_boost_path"; then
for i in `ls -d $ac_boost_path/include/boost-* 2>/dev/null`; do
_version_tmp=`echo $i | sed "s#$ac_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'`
V_CHECK=`expr $_version_tmp \> $_version`
if test "$V_CHECK" = "1" ; then
_version=$_version_tmp
best_path=$ac_boost_path
fi
done
fi
done
VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'`
BOOST_CPPFLAGS="-I$best_path/include/boost-$VERSION_UNDERSCORE"
if test "$ac_boost_lib_path" = ""; then
for libsubdir in $libsubdirs ; do
if ls "$best_path/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi
done
BOOST_LDFLAGS="-L$best_path/$libsubdir"
fi
fi
if test "x$BOOST_ROOT" != "x"; then
for libsubdir in $libsubdirs ; do
if ls "$BOOST_ROOT/stage/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi
done
if test -d "$BOOST_ROOT" && test -r "$BOOST_ROOT" && test -d "$BOOST_ROOT/stage/$libsubdir" && test -r "$BOOST_ROOT/stage/$libsubdir"; then
version_dir=`expr //$BOOST_ROOT : '.*/\(.*\)'`
stage_version=`echo $version_dir | sed 's/boost_//' | sed 's/_/./g'`
stage_version_shorten=`expr $stage_version : '\([[0-9]]*\.[[0-9]]*\)'`
V_CHECK=`expr $stage_version_shorten \>\= $_version`
if test "$V_CHECK" = "1" -a "$ac_boost_lib_path" = "" ; then
AC_MSG_NOTICE(We will use a staged boost library from $BOOST_ROOT)
BOOST_CPPFLAGS="-I$BOOST_ROOT"
BOOST_LDFLAGS="-L$BOOST_ROOT/stage/$libsubdir"
fi
fi
fi
fi
CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
export CPPFLAGS
LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
export LDFLAGS
AC_LANG_PUSH(C++)
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
@%:@include <boost/version.hpp>
]], [[
#if BOOST_VERSION >= $WANT_BOOST_VERSION
// Everything is okay
#else
# error Boost version is too old
#endif
]])],[
AC_MSG_RESULT(yes)
succeeded=yes
found_system=yes
],[
])
AC_LANG_POP([C++])
fi
if test "$succeeded" != "yes" ; then
if test "$_version" = "0" ; then
AC_MSG_NOTICE([[We could not detect the boost libraries (version $boost_lib_version_req_shorten or higher). If you have a staged boost library (still not installed) please specify \$BOOST_ROOT in your environment and do not give a PATH to --with-boost option. If you are sure you have boost installed, then check your version number looking in <boost/version.hpp>. See http://randspringer.de/boost for more documentation.]])
else
AC_MSG_NOTICE([Your boost libraries seems to old (version $_version).])
fi
# execute ACTION-IF-NOT-FOUND (if present):
ifelse([$3], , :, [$3])
else
AC_SUBST(BOOST_CPPFLAGS)
AC_SUBST(BOOST_LDFLAGS)
AC_DEFINE(HAVE_BOOST,,[define if the Boost library is available])
# execute ACTION-IF-FOUND (if present):
ifelse([$2], , :, [$2])
fi
CPPFLAGS="$CPPFLAGS_SAVED"
LDFLAGS="$LDFLAGS_SAVED"
fi
])
# Meson file for building the preprocessor in a standalone fashion.
# It is not used when building Dynare as a whole.
project('dynare-preprocessor', 'cpp',
version : '7-unstable',
# NB: update C++ standard in .clang-format whenever the following is modified
default_options : [ 'cpp_std=gnu++20', 'warning_level=2' ],
meson_version : '>=0.64.0')
add_global_arguments('-DPACKAGE_VERSION="' + meson.project_version() + '"', language : 'cpp')
if get_option('warning_level').to_int() >= 2
add_global_arguments('-Wold-style-cast', language : 'cpp')
endif
cpp_compiler = meson.get_compiler('cpp')
subdir('src')
subdir('doc')
# Meson native file for compiling under Homebrew / arm64
[binaries]
cpp = '/opt/homebrew/bin/g++-14'
flex = '/opt/homebrew/opt/flex/bin/flex'
bison = '/opt/homebrew/opt/bison/bin/bison'
[built-in options]
# XCode 15 (on Ventura and Sonoma) has a linker issue, see https://github.com/mesonbuild/meson/issues/12282, workaround is to use ld_classic
cpp_link_args = [ '-Wl,-ld_classic' ]
\ No newline at end of file