Skip to content
Open
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
15 changes: 7 additions & 8 deletions Circuit/Simulation/Simulation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,12 @@ public TransientSolution Solution
set { solution = value; InvalidateProcess(); }
}

private int oversample = 8;
private int oversample = 2;
/// <summary>
/// Oversampling factor for this simulation.
/// </summary>
public int Oversample { get { return oversample; } set { oversample = value; InvalidateProcess(); } }

private int iterations = 8;
/// <summary>
/// Maximum number of iterations allowed for the simulation to converge.
/// </summary>
public int Iterations { get { return iterations; } set { iterations = value; InvalidateProcess(); } }

/// <summary>
/// The sampling rate of this simulation, the sampling rate of the transient solution divided by the oversampling factor.
/// </summary>
Expand Down Expand Up @@ -313,7 +307,12 @@ private Action<int, double, double[][], double[][]> DefineProcess()
code.DeclInit(i.Left, i.Right);

// int it = iterations
LinqExpr it = code.ReDeclInit<int>("it", Iterations);
// This used to be a parameter, defaulted to 8. Experiments seem to show that
// it basically never makes sense to stop iterating at a limit. This sort of
// makes sense, because stopping iteration early suggests that the initial guess
// for the next sample will be worse. So, we're just going to use a very large
// number of iterations just to avoid getting stuck forever.
LinqExpr it = code.ReDeclInit<int>("it", 128);
// do { ... --it } while(it > 0)
code.DoWhile((Break) =>
{
Expand Down
3 changes: 0 additions & 3 deletions LiveSPICE/LiveSimulation.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@
<ComboBoxItem>16</ComboBoxItem>
</ComboBox>

<TextBlock Text="Iterations:" Margin="5, 0, 2, 0" HorizontalAlignment="Right" VerticalAlignment="Center" />
<xctk:IntegerUpDown Value="{Binding Iterations, Delay=1000}" Minimum="1" Maximum="64" />

<Separator />

<ls:ImageButton CommandImage="{x:Static ls:Commands.Simulate}" ImageHeight="16" />
Expand Down
14 changes: 1 addition & 13 deletions LiveSPICE/LiveSimulation.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ partial class LiveSimulation : Window, INotifyPropertyChanged
public Log Log { get { return (Log)log.Content; } }
public Scope Scope { get { return (Scope)scope.Content; } }

protected int oversample = 8;
protected int oversample = 2;
/// <summary>
/// Simulation oversampling rate.
/// </summary>
Expand All @@ -37,16 +37,6 @@ public int Oversample
set { oversample = Math.Max(1, value); RebuildSolution(); NotifyChanged(nameof(Oversample)); }
}

protected int iterations = 8;
/// <summary>
/// Max iterations for numerical algorithms.
/// </summary>
public int Iterations
{
get { return iterations; }
set { iterations = Math.Max(1, value); RebuildSolution(); NotifyChanged(nameof(Iterations)); }
}

private double inputGain = 1.0;
/// <summary>
/// Overall input gain.
Expand Down Expand Up @@ -304,7 +294,6 @@ private void RebuildSolution()
Input = inputs.Keys.ToArray(),
Output = probes.Select(i => i.V).Concat(OutputChannels.Select(i => i.Signal)).ToArray(),
Oversample = Oversample,
Iterations = Iterations,
};
}
catch (Exception Ex)
Expand Down Expand Up @@ -337,7 +326,6 @@ private void UpdateSimulation(bool Rebuild)
Input = inputs.Keys.ToArray(),
Output = probes.Select(i => i.V).Concat(OutputChannels.Select(i => i.Signal)).ToArray(),
Oversample = Oversample,
Iterations = Iterations,
};
}
else
Expand Down
10 changes: 0 additions & 10 deletions LiveSPICEVst/EditorView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,6 @@
<ComboBoxItem>4</ComboBoxItem>
<ComboBoxItem>8</ComboBoxItem>
</ComboBox>
<TextBlock>Iterations:</TextBlock>
<ComboBox x:Name="IterationsComboBox" SelectionChanged="IterationsComboBox_SelectionChanged">
<ComboBoxItem>1</ComboBoxItem>
<ComboBoxItem>2</ComboBoxItem>
<ComboBoxItem>4</ComboBoxItem>
<ComboBoxItem>8</ComboBoxItem>
<ComboBoxItem>16</ComboBoxItem>
<ComboBoxItem>32</ComboBoxItem>
<ComboBoxItem>64</ComboBoxItem>
</ComboBox>
</StackPanel>
<local:SimulationInterface DataContext="{Binding SimulationProcessor}" />
</DockPanel>
Expand Down
17 changes: 0 additions & 17 deletions LiveSPICEVst/EditorView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,6 @@ public void UpdateSchematic()
break;
}
}

for (int i = 0; i < IterationsComboBox.Items.Count; i++)
{
if (int.Parse((IterationsComboBox.Items[i] as ComboBoxItem).Content as string) == Plugin.SimulationProcessor.Iterations)
{
IterationsComboBox.SelectedIndex = i;

break;
}
}
}

private void OversampleComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
Expand All @@ -64,13 +54,6 @@ private void OversampleComboBox_SelectionChanged(object sender, SelectionChanged
Plugin.SimulationProcessor.Oversample = int.Parse((combo.SelectedItem as ComboBoxItem).Content as string);
}

private void IterationsComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ComboBox combo = sender as ComboBox;

Plugin.SimulationProcessor.Iterations = int.Parse((combo.SelectedItem as ComboBoxItem).Content as string);
}

private void LoadCircuitButton_Click(object sender, RoutedEventArgs e)
{
string examples =
Expand Down
2 changes: 0 additions & 2 deletions LiveSPICEVst/LiveSPICEPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ public override byte[] SaveState()
{
SchematicPath = SimulationProcessor.SchematicPath,
OverSample = SimulationProcessor.Oversample,
Iterations = SimulationProcessor.Iterations
};

foreach (var wrapper in SimulationProcessor.InteractiveComponents)
Expand Down Expand Up @@ -142,7 +141,6 @@ public override void RestoreState(byte[] stateData)
}

SimulationProcessor.Oversample = programParameters.OverSample;
SimulationProcessor.Iterations = programParameters.Iterations;

foreach (VSTProgramControlParameter controlParameter in programParameters.ControlParameters)
{
Expand Down
15 changes: 0 additions & 15 deletions LiveSPICEVst/SimulationProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,9 @@ public int Oversample
}
}

public int Iterations
{
get { return iterations; }
set
{
if (iterations != value)
{
iterations = value;

needRebuild = true;
}
}
}

double sampleRate;
int oversample = 2;
int iterations = 8;

Circuit.Circuit circuit = null;
Simulation simulation = null;
Expand Down Expand Up @@ -308,7 +294,6 @@ void UpdateSimulation(bool rebuild)
simulation = new Simulation(ts)
{
Oversample = oversample,
Iterations = iterations,
Input = new[] { inputExpression },
Output = new[] { outputExpression }
};
Expand Down
2 changes: 0 additions & 2 deletions LiveSPICEVst/VstProgramParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ public class VstProgramParameters
{
public string SchematicPath { get; set; }
public int OverSample { get; set; }
public int Iterations { get; set; }
public List<VSTProgramControlParameter> ControlParameters { get; set; }

public VstProgramParameters()
{
OverSample = 2;
Iterations = 8;

ControlParameters = new List<VSTProgramControlParameter>();
}
Expand Down
15 changes: 7 additions & 8 deletions Tests/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,41 +18,40 @@ static async Task<int> Main(string[] args)
.WithArgument<string>("pattern", "Glob pattern for files to test")
.WithOption<bool>(new[] { "--plot" }, "Plot results")
.WithOption(new[] { "--samples" }, () => 4800, "Samples")
.WithHandler(CommandHandler.Create<string, bool, int, int, int, int>(Test)))
.WithHandler(CommandHandler.Create<string, bool, int, int, int>(Test)))
.WithCommand("benchmark", "Run benchmarks", c => c
.WithArgument<string>("pattern", "Glob pattern for files to benchmark")
.WithHandler(CommandHandler.Create<string, int, int, int>(Benchmark)))
.WithHandler(CommandHandler.Create<string, int, int>(Benchmark)))
.WithGlobalOption(new Option<int>("--sampleRate", () => 48000, "Sample Rate"))
.WithGlobalOption(new Option<int>("--oversample", () => 8, "Oversample"))
.WithGlobalOption(new Option<int>("--iterations", () => 8, "Iterations"));
.WithGlobalOption(new Option<int>("--oversample", () => 4, "Oversample"));

return await rootCommand.InvokeAsync(args);
}

public static void Test(string pattern, bool plot, int sampleRate, int samples, int oversample, int iterations)
public static void Test(string pattern, bool plot, int sampleRate, int samples, int oversample)
{
var log = new ConsoleLog() { Verbosity = MessageType.Info };
var tester = new Test();

foreach (var circuit in GetCircuits(pattern, log))
{
var outputs = tester.Run(circuit, t => Harmonics(t, 0.5, 82, 2), sampleRate, samples, oversample, iterations);
var outputs = tester.Run(circuit, t => Harmonics(t, 0.5, 82, 2), sampleRate, samples, oversample);
if (plot)
{
tester.PlotAll(circuit.Name, outputs);
}
}
}

public static void Benchmark(string pattern, int sampleRate, int oversample, int iterations)
public static void Benchmark(string pattern, int sampleRate, int oversample)
{
var log = new ConsoleLog() { Verbosity = MessageType.Error };
var tester = new Test();
string fmt = "{0,-40}{1,12:G4}{2,12:G4}{3,12:G4}{4,12:G4}";
System.Console.WriteLine(fmt, "Circuit", "Analysis (ms)", "Solve (ms)", "Sim (kHz)", "Realtime x");
foreach (var circuit in GetCircuits(pattern, log))
{
double[] result = tester.Benchmark(circuit, t => Harmonics(t, 0.5, 82, 2), sampleRate, oversample, iterations, log: log);
double[] result = tester.Benchmark(circuit, t => Harmonics(t, 0.5, 820, 2), sampleRate, oversample, log: log);
double analyzeTime = result[0];
double solveTime = result[1];
double simRate = result[2];
Expand Down
4 changes: 0 additions & 4 deletions Tests/Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public Dictionary<Expression, List<double>> Run(
int SampleRate,
int Samples,
int Oversample,
int Iterations,
Expression? Input = null,
IEnumerable<Expression>? Outputs = null)
{
Expand All @@ -62,7 +61,6 @@ public Dictionary<Expression, List<double>> Run(
Simulation S = new Simulation(TS)
{
Oversample = Oversample,
Iterations = Iterations,
Input = new[] { Input },
Output = Outputs,
};
Expand Down Expand Up @@ -104,7 +102,6 @@ public double[] Benchmark(
Func<double, double> Vin,
int SampleRate,
int Oversample,
int Iterations,
Expression? Input = null,
IEnumerable<Expression>? Outputs = null,
ILog? log = null)
Expand All @@ -131,7 +128,6 @@ public double[] Benchmark(
Simulation S = new Simulation(TS)
{
Oversample = Oversample,
Iterations = Iterations,
Input = new[] { Input },
Output = Outputs,
};
Expand Down