Propgage symmetry when adding otbital integral terms to Hamiltonian.
This commit is contained in:
Родитель
8ca3a7aba5
Коммит
0b82e62d16
|
@ -26,6 +26,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "BroombridgeExamples", "Broo
|
|||
ProjectSection(SolutionItems) = preProject
|
||||
Chemistry\tests\TestData\Broombridge\broombridge_v0.1.yaml = Chemistry\tests\TestData\Broombridge\broombridge_v0.1.yaml
|
||||
Chemistry\tests\TestData\Broombridge\broombridge_v0.2.yaml = Chemistry\tests\TestData\Broombridge\broombridge_v0.2.yaml
|
||||
Chemistry\tests\TestData\Broombridge\H2O-6_fourfold_v0.3.yaml = Chemistry\tests\TestData\Broombridge\H2O-6_fourfold_v0.3.yaml
|
||||
Chemistry\tests\TestData\Broombridge\H2O-6_trivial_v0.3.yaml = Chemistry\tests\TestData\Broombridge\H2O-6_trivial_v0.3.yaml
|
||||
Chemistry\tests\TestData\Broombridge\hydrogen_0.1.yaml = Chemistry\tests\TestData\Broombridge\hydrogen_0.1.yaml
|
||||
Chemistry\tests\TestData\Broombridge\hydrogen_0.2.yaml = Chemistry\tests\TestData\Broombridge\hydrogen_0.2.yaml
|
||||
Chemistry\tests\TestData\Broombridge\LiH_0.1.yaml = Chemistry\tests\TestData\Broombridge\LiH_0.1.yaml
|
||||
|
|
|
@ -48,7 +48,6 @@ namespace Microsoft.Quantum.Chemistry.OrbitalIntegrals
|
|||
return hamiltonian;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Creates all fermion terms generated by all symmetries of an orbital integral.
|
||||
/// </summary>
|
||||
|
|
|
@ -32,7 +32,7 @@ namespace Microsoft.Quantum.Chemistry.OrbitalIntegrals
|
|||
/// <param name="orbitalIntegral">Orbital integral to add to Hamiltonian.</param>
|
||||
public void Add(OrbitalIntegral orbitalIntegral)
|
||||
{
|
||||
Add(new OrbitalIntegral(orbitalIntegral.OrbitalIndices), orbitalIntegral.Coefficient);
|
||||
Add(new OrbitalIntegral(orbitalIntegral.OrbitalIndices, symmetry: orbitalIntegral.Symmetry), orbitalIntegral.Coefficient);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
|
||||
<!-- Serialization test data -->
|
||||
<ItemGroup>
|
||||
<!-- Broombridge v0.1 and v0.2 examples -->
|
||||
<!-- Broombridge v0.1, v0.2, and v0.3 examples -->
|
||||
<None Include="..\TestData\Broombridge\broombridge_v0.1.yaml" Link="Broombridge\broombridge_v0.1.yaml">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
|
@ -52,6 +52,12 @@
|
|||
<None Include="..\TestData\Broombridge\LiH_0.1.yaml" Link="Broombridge\LiH_0.1.yaml">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="..\TestData\Broombridge\H2O-6_trivial_v0.3.yaml" Link="Broombridge\H2O-6_trivial_v0.3.yaml">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="..\TestData\Broombridge\H2O-6_fourfold_v0.3.yaml" Link="Broombridge\H2O-6_fourfold_v0.3.yaml">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
|
||||
<!-- FCIDUMP examples -->
|
||||
<None Include="..\TestData\FciDump\h2_anorccmb.fcidump" Link="FciDump\h2_anorccmb.fcidump">
|
||||
|
|
|
@ -63,5 +63,43 @@ namespace Microsoft.Quantum.Chemistry.Tests
|
|||
Assert.True(orb0 == orb1);
|
||||
Assert.False(orb0 == orb2);
|
||||
}
|
||||
|
||||
// Test fourfold symmetry
|
||||
[Theory]
|
||||
[InlineData(0, 0, 0, 0, 1)]
|
||||
[InlineData(0, 0, 0, 1, 4)]
|
||||
[InlineData(0, 0, 1, 0, 4)]
|
||||
[InlineData(0, 1, 0, 0, 4)]
|
||||
[InlineData(1, 0, 0, 0, 4)]
|
||||
[InlineData(1, 1, 0, 0, 2)]
|
||||
[InlineData(0, 1, 1, 0, 2)]
|
||||
[InlineData(0, 0, 1, 2, 4)]
|
||||
[InlineData(0, 1, 2, 0, 4)]
|
||||
[InlineData(0, 1, 2, 3, 4)]
|
||||
public void OrbitalIntegralEnumerateOrbitalSymmetriesFourfoldTest(int i, int j, int k, int l, int elements)
|
||||
{
|
||||
OrbitalIntegral orbitalIntegral = new OrbitalIntegral(new int[] { i, j, k, l }, 0.0, OrbitalIntegral.PermutationSymmetry.Fourfold);
|
||||
var orbitalIntegrals = orbitalIntegral.EnumerateOrbitalSymmetries();
|
||||
Assert.Equal(elements, orbitalIntegrals.Length);
|
||||
}
|
||||
|
||||
// Test trivial symmetry
|
||||
[Theory]
|
||||
[InlineData(0, 0, 0, 0, 1)]
|
||||
[InlineData(0, 0, 0, 1, 1)]
|
||||
[InlineData(0, 0, 1, 0, 1)]
|
||||
[InlineData(0, 1, 0, 0, 1)]
|
||||
[InlineData(1, 0, 0, 0, 1)]
|
||||
[InlineData(1, 1, 0, 0, 1)]
|
||||
[InlineData(0, 1, 1, 0, 1)]
|
||||
[InlineData(0, 0, 1, 2, 1)]
|
||||
[InlineData(0, 1, 2, 0, 1)]
|
||||
[InlineData(0, 1, 2, 3, 1)]
|
||||
public void OrbitalIntegralEnumerateOrbitalSymmetriesTrivialTest(int i, int j, int k, int l, int elements)
|
||||
{
|
||||
OrbitalIntegral orbitalIntegral = new OrbitalIntegral(new int[] { i, j, k, l }, 0.0, OrbitalIntegral.PermutationSymmetry.Trivial);
|
||||
var orbitalIntegrals = orbitalIntegral.EnumerateOrbitalSymmetries();
|
||||
Assert.Equal(elements, orbitalIntegrals.Length);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -8,10 +8,13 @@ using System.IO;
|
|||
using System.Linq;
|
||||
|
||||
using Microsoft.Quantum.Chemistry.Broombridge;
|
||||
using Microsoft.Quantum.Chemistry.Fermion;
|
||||
using Microsoft.Quantum.Chemistry.OrbitalIntegrals;
|
||||
|
||||
using Newtonsoft.Json;
|
||||
|
||||
using Xunit;
|
||||
using YamlDotNet.Core.Tokens;
|
||||
|
||||
namespace Microsoft.Quantum.Chemistry.Tests
|
||||
{
|
||||
|
@ -139,4 +142,37 @@ namespace Microsoft.Quantum.Chemistry.Tests
|
|||
Assert.Equal(original.Schema, serialized.Schema);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class Broombridgev0_3Tests
|
||||
{
|
||||
public string Filename_trivial_symmetry = "Broombridge/H2O-6_trivial_v0.3.yaml";
|
||||
public string Filename_fourfold_symmetry = "Broombridge/H2O-6_fourfold_v0.3.yaml";
|
||||
|
||||
|
||||
// Check that fully expanded trivial and fourfold symmetries lead to the same Hamiltonian.
|
||||
[Fact]
|
||||
public void DeserializeVersionNumbers()
|
||||
{
|
||||
var broombridge_trivial = Deserializers.Deserialize<V0_3.Data>(Filename_trivial_symmetry);
|
||||
var broombridge_fourfold = Deserializers.Deserialize<V0_3.Data>(Filename_fourfold_symmetry);
|
||||
|
||||
var trivial_Hamiltonian = V0_3.ToOrbitalIntegralHamiltonian(broombridge_trivial.ProblemDescriptions.Single());
|
||||
var fourfold_Hamiltonian = V0_3.ToOrbitalIntegralHamiltonian(broombridge_fourfold.ProblemDescriptions.Single());
|
||||
|
||||
FermionHamiltonian x = trivial_Hamiltonian.ToFermionHamiltonian();
|
||||
FermionHamiltonian y = fourfold_Hamiltonian.ToFermionHamiltonian();
|
||||
foreach(var termType in y.Terms)
|
||||
{
|
||||
foreach (var term in termType.Value)
|
||||
{
|
||||
y.Terms[termType.Key][term.Key] = -term.Value;
|
||||
}
|
||||
}
|
||||
|
||||
x.AddHamiltonian(y);
|
||||
|
||||
Assert.Equal(x.Norm(), 0.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Двоичный файл не отображается.
Двоичный файл не отображается.
Двоичный файл не отображается.
Двоичный файл не отображается.
Загрузка…
Ссылка в новой задаче