Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/driver/Entry.ml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ let stan2cpp model_name model (flags : Flags.t) (output : other_output -> unit)
output (Warnings (Pedantic_analysis.warn_uninitialized mir));
if flags.warn_pedantic then
output (Warnings (Pedantic_analysis.warn_pedantic mir));
if flags.debug_settings.debug_print_factor_graph then
print_endline
(Factor_graph.factor_graph_to_dot (Factor_graph.prog_factor_graph mir));
debug_output_mir output mir flags.debug_settings.print_mir;
let* generation_context =
match flags.debug_settings.debug_data_json with
Expand Down
6 changes: 4 additions & 2 deletions src/driver/Flags.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ and debug_settings =
; print_lir: bool
; debug_generate_data: bool
; debug_generate_inits: bool
; debug_data_json: (string * string) option }
; debug_data_json: (string * string) option
; debug_print_factor_graph: bool }

and debug_options = Off | Basic | Pretty

Expand Down Expand Up @@ -63,7 +64,8 @@ let default =
; print_lir= false
; debug_generate_data= false
; debug_generate_inits= false
; debug_data_json= None }
; debug_data_json= None
; debug_print_factor_graph= false }
; line_length= 78
; canonicalizer_settings= Frontend.Canonicalize.none
; warn_pedantic= false
Expand Down
3 changes: 2 additions & 1 deletion src/driver/Flags.mli
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ and debug_settings =
; print_lir: bool
; debug_generate_data: bool
; debug_generate_inits: bool
; debug_data_json: (string * string) option }
; debug_data_json: (string * string) option
; debug_print_factor_graph: bool }

and debug_options = Off | Basic | Pretty

Expand Down
12 changes: 10 additions & 2 deletions src/stanc/CLI.ml
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,12 @@ module Debug_Options = struct
it." in
debug_basic_or_pretty ~doc "debug-transformed-mir"

let debug_print_factor_graph =
let doc =
"For debugging purposes: print a conservative over-approximation of the \
factor graph for the model(s) implemented in the Stan program." in
Arg.(value & flag & info ["debug-print-factor-graph"] ~doc ~docs)

let force_soa =
let doc =
"Debugging features. Valid values: $(b,-fsoa) to force on the Struct of \
Expand Down Expand Up @@ -370,7 +376,8 @@ module Conversion = struct
and+ print_lir = debug_lir
and+ debug_generate_data
and+ debug_generate_inits
and+ debug_data_json = Term.ret debug_data_json in
and+ debug_data_json = Term.ret debug_data_json
and+ debug_print_factor_graph in
Driver.Flags.
{ print_ast
; print_typed_ast
Expand All @@ -382,7 +389,8 @@ module Conversion = struct
; print_lir
; debug_generate_data
; debug_generate_inits
; debug_data_json }
; debug_data_json
; debug_print_factor_graph }

let flags : Driver.Flags.t Term.t =
let open Options in
Expand Down
1 change: 1 addition & 0 deletions src/stancjs/conversion.ml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ let process_flags name code (flags : 'a Js.opt) includes :
; print_mem_patterns= is_flag_set "debug-mem-patterns"
; force_soa= None
; print_lir= is_flag_set "debug-lir"
; debug_print_factor_graph= is_flag_set "debug-print-factor-graph"
; debug_generate_data= is_flag_set "debug-generate-data"
; debug_generate_inits= is_flag_set "debug-generate-inits"
; debug_data_json=
Expand Down
11 changes: 11 additions & 0 deletions test/integration/cli-args/debug-flags.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,17 @@ Flags not used elsewhere in the tests
parameters real theta; //real
}

$ stanc basic.stan --debug-print-factor-graph
graph {
"bernoulli_lupmf(y, theta)" [shape=box]
"beta_lupdf(theta, promote(1, real, data), promote(1, real, data))" [shape=box]
theta
y
"bernoulli_lupmf(y, theta)" -- theta
"bernoulli_lupmf(y, theta)" -- y
"beta_lupdf(theta, promote(1, real, data), promote(1, real, data))" -- theta
}

$ stanc parse_error.stan --debug-parse
Syntax error in 'parse_error.stan', line 1, column 0 to column 5, parsing error:
-------------------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions test/integration/cli-args/stanc.t
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ Show help
--debug-parse
For debugging purposes: print the parser actions.

--debug-print-factor-graph
For debugging purposes: print a conservative over-approximation of
the factor graph for the model(s) implemented in the Stan program.

--debug-transformed-mir
For debugging purposes: print the MIR after the backend has
transformed it.
Expand Down