From ebf7511e80c9d657cb9be5ee2b721b6ae6dd8a22 Mon Sep 17 00:00:00 2001 From: Raphael Koh Date: Thu, 23 Jul 2020 17:09:06 -0400 Subject: [PATCH 1/2] Allow default depth for %trace to be set in %config --- src/Jupyter/ConfigurationSource.cs | 7 +++++++ src/Kernel/Magic/ConfigMagic.cs | 8 ++++++-- src/Kernel/Magic/TraceMagic.cs | 7 +++++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/Jupyter/ConfigurationSource.cs b/src/Jupyter/ConfigurationSource.cs index 3ded3daaa3..15d2b403df 100644 --- a/src/Jupyter/ConfigurationSource.cs +++ b/src/Jupyter/ConfigurationSource.cs @@ -69,6 +69,13 @@ private T GetOptionOrDefault(string optionName, T defaultValue) => /// public PhaseDisplayStyle PhaseDisplayStyle => GetOptionOrDefault("dump.phaseDisplayStyle", PhaseDisplayStyle.ArrowOnly); + + /// + /// Allows for setting the default depth for visualizing Q# operations using the + /// %trace command. + /// + public int TraceVisualizationDefaultDepth => + GetOptionOrDefault("trace.defaultDepth", 1); } /// diff --git a/src/Kernel/Magic/ConfigMagic.cs b/src/Kernel/Magic/ConfigMagic.cs index db8abdf039..3d1fb4674e 100644 --- a/src/Kernel/Magic/ConfigMagic.cs +++ b/src/Kernel/Magic/ConfigMagic.cs @@ -6,9 +6,7 @@ using System.Linq; using Microsoft.Jupyter.Core; -using Microsoft.Quantum.IQSharp; using Microsoft.Quantum.IQSharp.Jupyter; -using Microsoft.Quantum.IQSharp.Kernel; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -66,6 +64,12 @@ of basis states of a state vector. Configures the phase visualization style in output from callables such as `DumpMachine` or `DumpRegister`. Supports displaying phase as arrows, numbers (in radians), both, or neither. + + **`trace.defaultDepth`** + + **Value:** integer (default `1`) + + Configures the default depth used in the `%trace` command for visualizing Q# operations. ".Dedent(), Examples = new [] { diff --git a/src/Kernel/Magic/TraceMagic.cs b/src/Kernel/Magic/TraceMagic.cs index db7497f1f6..bbef6a8020 100644 --- a/src/Kernel/Magic/TraceMagic.cs +++ b/src/Kernel/Magic/TraceMagic.cs @@ -77,7 +77,7 @@ or function name that has been defined either in the notebook or in a Q# file in - `{ParameterNameDepth}=` (default=1): The depth at which to render operations along the execution path. ".Dedent(), - Examples = new [] + Examples = new[] { @" Visualize the execution path of a Q# operation defined as `operation MyOperation() : Result`: @@ -137,7 +137,10 @@ public async Task RunAsync(string input, IChannel channel) var symbol = SymbolResolver.Resolve(name) as IQSharpSymbol; if (symbol == null) throw new InvalidOperationException($"Invalid operation name: {name}"); - var depth = inputParameters.DecodeParameter(ParameterNameDepth, defaultValue: 1); + var depth = inputParameters.DecodeParameter( + ParameterNameDepth, + defaultValue: this.ConfigurationSource.TraceVisualizationDefaultDepth + ); if (depth <= 0) throw new ArgumentOutOfRangeException($"Invalid depth: {depth}. Must be >= 1."); var tracer = new ExecutionPathTracer(depth); From 1c03d7bb4f7808f912963ec3249c841bdfc4a7bc Mon Sep 17 00:00:00 2001 From: Raphael Koh Date: Thu, 23 Jul 2020 20:20:57 -0400 Subject: [PATCH 2/2] Fix config magic description --- src/Kernel/Magic/ConfigMagic.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Kernel/Magic/ConfigMagic.cs b/src/Kernel/Magic/ConfigMagic.cs index 3d1fb4674e..dd715af8ab 100644 --- a/src/Kernel/Magic/ConfigMagic.cs +++ b/src/Kernel/Magic/ConfigMagic.cs @@ -67,7 +67,7 @@ Configures the phase visualization style in output from callables such as **`trace.defaultDepth`** - **Value:** integer (default `1`) + **Value:** positive integer (default `1`) Configures the default depth used in the `%trace` command for visualizing Q# operations. ".Dedent(),