Exemplo n.º 1
0
 public FciDumpDataFixture()
 {
     using var reader = File.OpenText(
               Path.Join(
                   "FciDump", "h2_anorccmb.fcidump"
                   )
               );
     problem = FciDumpSerializer.Deserialize(reader).Single();
 }
 internal static V0_2.ProblemDescription ToBroombridgeV0_2(
     this ElectronicStructureProblem problem
     ) => new V0_2.ProblemDescription
 {
     BasisSet = problem.BasisSet != null
                     ? new V0_1.BasisSet
     {
         Name = problem.BasisSet?.Name,
         Type = problem.BasisSet?.Type
     }
                     : null,
     CoulombRepulsion = problem.CoulombRepulsion.ToBroombridgeV0_2(),
     EnergyOffset     = problem.EnergyOffset.ToBroombridgeV0_2(),
     FciEnergy        = problem.FciEnergy?.ToBroombridgeV0_2(),
     Geometry         = problem.Geometry?.ToBroombridgeV0_2(),
     Hamiltonian      = problem.OrbitalIntegralHamiltonian.ToBroombridgeV0_1(),
     InitialStates    = problem.InitialStates?.ToBroombridgeV0_2(),
     Metadata         = problem.Metadata,
     NElectrons       = problem.NElectrons,
     NOrbitals        = problem.NOrbitals,
     ScfEnergy        = problem.ScfEnergy?.ToBroombridgeV0_2(),
     ScfEnergyOffset  = problem.ScfEnergyOffset?.ToBroombridgeV0_2()
 };
Exemplo n.º 3
0
        internal static IEnumerable <Action> IsEqualTo(this ElectronicStructureProblem expected, ElectronicStructureProblem actual)
        {
            // NB: This does not yet check all metadata, as some metadata does not yet roundtrip
            //     correctly. See https://github.com/microsoft/QuantumLibraries/issues/279 for an
            //     example and for discussion.
            yield return(() =>
                         actual.CoulombRepulsion.Value.Should().Be(
                             expected.CoulombRepulsion.Value,
                             because: "Coulomb repulsion should match"
                             ));

            yield return(() =>
                         actual.EnergyOffset.Value.Should().Be(
                             expected.EnergyOffset.Value,
                             because: "energy offset should match"
                             ));

            yield return(() =>
                         actual.NElectrons.Should().Be(
                             expected.NElectrons,
                             because: "# of electrons should match"
                             ));

            yield return(() =>
                         actual.NOrbitals.Should().Be(
                             expected.NOrbitals,
                             because: "# of orbitals should match"
                             ));

            // yield return () =>
            //     actual.OrbitalIntegralHamiltonian.Terms.Should().ContainKeys(
            //         expected.OrbitalIntegralHamiltonian.Terms.Keys
            //     ).And.HaveCount(
            //         expected.OrbitalIntegralHamiltonian.Terms.Count,
            //         because: "# of kinds of terms should match"
            //     );

            var onlyInActual =
                actual.OrbitalIntegralHamiltonian.Terms.Keys
                .Except(expected.OrbitalIntegralHamiltonian.Terms.Keys);

            // Make sure that any keys that are only in the actual
            // problem are trivial.
            foreach (var termType in onlyInActual)
            {
                var term = actual.OrbitalIntegralHamiltonian.Terms[termType];
                // Make sure that any terms, if present, have coefficient zero.
                yield return(() => term.Values.Should().OnlyContain(item => item.Value == 0.0));
            }

            // Check the actual terms themselves.
            foreach (var termType in expected.OrbitalIntegralHamiltonian.Terms.Keys)
            {
                yield return(() =>
                             actual.OrbitalIntegralHamiltonian.Terms[termType].Count.Should().Be(
                                 expected.OrbitalIntegralHamiltonian.Terms[termType].Count,
                                 because: $"# of terms of type {termType} should match"
                                 ));

                // Now that we've checked that the count is correct, we can check
                // each individual term.
                foreach (var index in expected.OrbitalIntegralHamiltonian.Terms[termType])
                {
                    yield return(() =>
                                 actual.OrbitalIntegralHamiltonian.Terms[termType][index.Key].Should().Be(
                                     index.Value,
                                     $"term with index {index.Key} of type {termType} should match"
                                     ));
                }
            }
        }