Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.
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
7 changes: 7 additions & 0 deletions src/Jupyter/ConfigurationSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ private T GetOptionOrDefault<T>(string optionName, T defaultValue) =>
/// </summary>
public PhaseDisplayStyle PhaseDisplayStyle =>
GetOptionOrDefault("dump.phaseDisplayStyle", PhaseDisplayStyle.ArrowOnly);

/// <summary>
/// Allows for setting the default depth for visualizing Q# operations using the
/// <c>%trace</c> command.
/// </summary>
public int TraceVisualizationDefaultDepth =>
GetOptionOrDefault("trace.defaultDepth", 1);
}

/// <summary>
Expand Down
8 changes: 6 additions & 2 deletions src/Kernel/Magic/ConfigMagic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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:** positive integer (default `1`)

Configures the default depth used in the `%trace` command for visualizing Q# operations.
".Dedent(),
Examples = new []
{
Expand Down
7 changes: 5 additions & 2 deletions src/Kernel/Magic/TraceMagic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ or function name that has been defined either in the notebook or in a Q# file in
- `{ParameterNameDepth}=<integer>` (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`:
Expand Down Expand Up @@ -137,7 +137,10 @@ public async Task<ExecutionResult> 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<int>(ParameterNameDepth, defaultValue: 1);
var depth = inputParameters.DecodeParameter<int>(
ParameterNameDepth,
defaultValue: this.ConfigurationSource.TraceVisualizationDefaultDepth
);
if (depth <= 0) throw new ArgumentOutOfRangeException($"Invalid depth: {depth}. Must be >= 1.");

var tracer = new ExecutionPathTracer(depth);
Expand Down