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
13 changes: 11 additions & 2 deletions src/SpiceSharp-Parser.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31919.166
# Visual Studio Version 18
VisualStudioVersion = 18.5.11612.153 insiders
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SpiceSharpParser", "SpiceSharpParser\SpiceSharpParser.csproj", "{DF3DD787-71CC-4C89-9E33-DC4536A52278}"
EndProject
Expand All @@ -17,6 +17,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SpiceSharpParser.Performanc
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SpiceSharpParser.Tests", "SpiceSharpParser.Tests\SpiceSharpParser.Tests.csproj", "{94394567-BC35-43EE-92CB-31AC780305FE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SpiceSharpParser.AIExamples", "SpiceSharpParser.AIExamples\SpiceSharpParser.AIExamples.csproj", "{2AB238C7-D9DC-94E6-1355-4CDA8CE3429B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -54,6 +56,12 @@ Global
{94394567-BC35-43EE-92CB-31AC780305FE}.ERRORS|Any CPU.Build.0 = Debug|Any CPU
{94394567-BC35-43EE-92CB-31AC780305FE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{94394567-BC35-43EE-92CB-31AC780305FE}.Release|Any CPU.Build.0 = Release|Any CPU
{2AB238C7-D9DC-94E6-1355-4CDA8CE3429B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2AB238C7-D9DC-94E6-1355-4CDA8CE3429B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2AB238C7-D9DC-94E6-1355-4CDA8CE3429B}.ERRORS|Any CPU.ActiveCfg = Debug|Any CPU
{2AB238C7-D9DC-94E6-1355-4CDA8CE3429B}.ERRORS|Any CPU.Build.0 = Debug|Any CPU
{2AB238C7-D9DC-94E6-1355-4CDA8CE3429B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2AB238C7-D9DC-94E6-1355-4CDA8CE3429B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -63,6 +71,7 @@ Global
{690C3742-17AD-46F6-A73D-CAE33C780523} = {A98DF2D4-CFE4-44F3-AD5C-21D6A0648EFD}
{53D996E7-8D58-49D0-97F6-71CAD49670A2} = {CEDE104D-B6B3-433F-A8B3-C06086A4DD4E}
{94394567-BC35-43EE-92CB-31AC780305FE} = {CEDE104D-B6B3-433F-A8B3-C06086A4DD4E}
{2AB238C7-D9DC-94E6-1355-4CDA8CE3429B} = {CEDE104D-B6B3-433F-A8B3-C06086A4DD4E}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F5DF7359-A6BE-4DB6-9200-CEFBAEBAD75E}
Expand Down
117 changes: 117 additions & 0 deletions src/SpiceSharpParser.AIExamples/AcceptedExampleCase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
using System.Text.Json.Serialization;

namespace SpiceSharpParserAIExamples;

internal sealed class AcceptedExampleCase
{
[JsonPropertyName("id")]
public string Id { get; init; } = "";

[JsonPropertyName("source")]
public string Source { get; init; } = "";

[JsonPropertyName("example_id")]
public string ExampleId { get; init; } = "";

[JsonPropertyName("test_name")]
public string TestName { get; init; } = "";

[JsonPropertyName("netlist_hash")]
public string NetlistHash { get; init; } = "";

[JsonPropertyName("generator_model")]
public string GeneratorModel { get; init; } = "";

[JsonPropertyName("generator_source")]
public string GeneratorSource { get; init; } = "";

[JsonPropertyName("quality_tier")]
public string QualityTier { get; init; } = "";

[JsonPropertyName("status")]
public string Status { get; init; } = "";

[JsonPropertyName("pytest_status")]
public string PytestStatus { get; init; } = "";

[JsonPropertyName("prompt_count")]
public int PromptCount { get; init; }

[JsonPropertyName("representative_prompt")]
public string RepresentativePrompt { get; init; } = "";

[JsonPropertyName("pair_ids")]
public List<string> PairIds { get; init; } = [];

[JsonPropertyName("prompts")]
public List<string> Prompts { get; init; } = [];

[JsonPropertyName("measurements")]
public List<MeasurementReport> Measurements { get; init; } = [];
}

internal sealed class MeasurementReport
{
[JsonPropertyName("name")]
public string Name { get; init; } = "";

[JsonPropertyName("key")]
public string Key { get; init; } = "";

[JsonPropertyName("index")]
public int Index { get; init; }

[JsonPropertyName("value")]
public double? Value { get; init; }

[JsonPropertyName("value_is_finite")]
public bool ValueIsFinite { get; init; }

[JsonPropertyName("success")]
public bool Success { get; init; }

[JsonPropertyName("measurement_type")]
public string MeasurementType { get; init; } = "";

[JsonPropertyName("simulation_name")]
public string SimulationName { get; init; } = "";
}

internal sealed class AcceptedExamplesManifest
{
[JsonPropertyName("total_unique_cases")]
public int TotalUniqueCases { get; init; }

[JsonPropertyName("unmatched_accepted_pair_hashes")]
public int UnmatchedAcceptedPairHashes { get; init; }

[JsonPropertyName("sources")]
public List<AcceptedExamplesSourceManifest> Sources { get; init; } = [];
}

internal sealed class AcceptedExamplesSourceManifest
{
[JsonPropertyName("name")]
public string Name { get; init; } = "";

[JsonPropertyName("accepted_pairs_path")]
public string AcceptedPairsPath { get; init; } = "";

[JsonPropertyName("accepted_pairs_sha256")]
public string AcceptedPairsSha256 { get; init; } = "";

[JsonPropertyName("accepted_pair_count")]
public int AcceptedPairCount { get; init; }

[JsonPropertyName("unique_netlist_count")]
public int UniqueNetlistCount { get; init; }

[JsonPropertyName("measured_examples_path")]
public string MeasuredExamplesPath { get; init; } = "";

[JsonPropertyName("measured_examples_sha256")]
public string MeasuredExamplesSha256 { get; init; } = "";

[JsonPropertyName("measured_example_count")]
public int MeasuredExampleCount { get; init; }
}
69 changes: 69 additions & 0 deletions src/SpiceSharpParser.AIExamples/AcceptedExampleFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using System.Security.Cryptography;
using System.Text.Json;
using Xunit;

namespace SpiceSharpParserAIExamples;

internal static class AcceptedExampleFixture
{
private static readonly JsonSerializerOptions JsonOptions = new()
{
PropertyNameCaseInsensitive = true,
};

private static readonly Lazy<IReadOnlyList<AcceptedExampleCase>> LazyCases = new(LoadCases);
private static readonly Lazy<IReadOnlyDictionary<string, AcceptedExampleCase>> LazyCasesById =
new(() => LazyCases.Value.ToDictionary(item => item.Id, StringComparer.Ordinal));
private static readonly Lazy<AcceptedExamplesManifest> LazyManifest = new(LoadManifest);

public static IReadOnlyList<AcceptedExampleCase> All => LazyCases.Value;

public static AcceptedExamplesManifest Manifest => LazyManifest.Value;

public static AcceptedExampleCase Get(string id)
{
Assert.True(LazyCasesById.Value.TryGetValue(id, out var testCase), $"fixture case {id} was not found");
return testCase;
}
public static string Sha256File(string path)
{
using var stream = File.OpenRead(path);
return Convert.ToHexString(SHA256.HashData(stream)).ToLowerInvariant();
}

private static IReadOnlyList<AcceptedExampleCase> LoadCases()

Check warning on line 34 in src/SpiceSharpParser.AIExamples/AcceptedExampleFixture.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Change return type of method 'LoadCases' from 'System.Collections.Generic.IReadOnlyList<SpiceSharpParserAIExamples.AcceptedExampleCase>' to 'System.Collections.Generic.List<SpiceSharpParserAIExamples.AcceptedExampleCase>' for improved performance

See more on https://sonarcloud.io/project/issues?id=SpiceSharp_SpiceSharpParser&issues=AZ5HIDK0EieL4mzaSXsO&open=AZ5HIDK0EieL4mzaSXsO&pullRequest=182
{
var path = FixturePath("accepted_examples_fixture.jsonl");
var cases = new List<AcceptedExampleCase>();
foreach (var line in File.ReadLines(path))
{
if (string.IsNullOrWhiteSpace(line))
{
continue;
}

cases.Add(JsonSerializer.Deserialize<AcceptedExampleCase>(line, JsonOptions)
?? throw new InvalidOperationException($"Could not deserialize fixture line from {path}"));
}

return cases;
}

private static AcceptedExamplesManifest LoadManifest()
{
var path = FixturePath("accepted_examples_manifest.json");
return JsonSerializer.Deserialize<AcceptedExamplesManifest>(File.ReadAllText(path), JsonOptions)
?? throw new InvalidOperationException($"Could not deserialize manifest {path}");
}

private static string FixturePath(string fileName)
{
var path = Path.Combine(AppContext.BaseDirectory, fileName);
if (!File.Exists(path))
{
throw new FileNotFoundException($"Generated fixture file is missing: {path}", path);
}

return path;
}
}
Loading
Loading