Select Git revision
Program.cs 52.78 KiB
using MathNet.Numerics.LinearAlgebra;
using MathNet.Numerics.Random;
using OxyPlot;
using OxyPlot.Axes;
using OxyPlot.Series;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
namespace IVMCTrim
{
class Program
{
// This is the entry point.
// Consult readme.md for information about how to run this program.
// Consult fjn1g13@soton.ac.uk if you don't understand something.
// This code is not exemplar C#; rather, the idea is that it should be fairly easy for anyone to reimplement the model from looking at it without taking too long to run.
static void Main(string[] args)
{
// none of our matrices are big enough to warrent multi-threading
MathNet.Numerics.Control.UseSingleThread();
// non-essential stuff so we can run in parallel if we don't have time to wait
var tasks = new List<Task>();
void CreateRun(string outDir, Parameters parameters, int seed, int reportingPeriodMultiplier = 1)
{
tasks.Add(new Task(() => Run(outDir, parameters, seed, reportingPeriodMultiplier)));
}
// prepare a bunch of experiments with the 'standard' configuration, only varying Z
CreateRun("Z000", Configurations.Standard(Z: 0.0), 42);
CreateRun("Z050", Configurations.Standard(Z: 0.5), 542);
CreateRun("Z075", Configurations.Standard(Z: 0.75), 1842);
CreateRun("Z095", Configurations.Standard(Z: 0.95), 2042);
CreateRun("Z000PerfectG", Configurations.PerfectG(Z: 0.0), 42);
// prepare some experiments with unusual configurations
CreateRun("FixedHigh", Configurations.FixedHigh, 42);
CreateRun("Z050E204", Configurations.Standard204(Z: 0.95), 42, reportingPeriodMultiplier: 10); // this one takes a while
CreateRun("Z095L2", Configurations.StandardL2(Z: 0.95), 2042);
CreateRun("Z095MMSO", Configurations.StandardMMSO(Z: 0.95), 2042);
// run the experiments
bool runInParallel = true;
if (runInParallel)
{
// parallel: queue all the experiments are once (will be run subject to the thread pool)
foreach (var t in tasks)
t.Start();
Task.WaitAll(tasks.ToArray());
}
else
{
// sequential: run the experiments one at a time
foreach (var t in tasks)
t.RunSynchronously();
}
}
/// <summary>
/// Runs a single experiment with the given parameters and seed into the given output directory
/// </summary>
public static void Run(string outDir, Parameters parameters, int seed, int reportingPeriodMultiplier = 1)
{
Console.WriteLine($"Running into {outDir}");
System.IO.Directory.CreateDirectory(outDir);
string path(string f) => System.IO.Path.Combine(outDir, f);