Esempio n. 1
0
        void OnExecute()
        {
            var logger = new LoggerFactory().CreateLogger <Program>();

            // Directory containing integral data generated by Microsoft.
            //Example Liquid data format files

            /*
             * "h2_sto3g_4.dat" // 4 SO
             * "B_sto6g.dat" // 10 SO
             * "Be_sto6g_10.dat" // 10 SO
             * "h2o_sto6g_14.dat" // 14 SO
             * "h2s_sto6g_22.dat" // 22 SO
             * "co2_sto3g_30.dat" // 30 SO
             * "co2_p321_54.dat" // 54 SO
             * "fe2s2_sto3g.dat" // 110 SO
             * "nitrogenase_tzvp_54.dat" // 108 SO
             */

            // For loading data in the format consumed by Liquid.
            logger.LogInformation($"Processing {Path}...");
            using var reader = File.OpenText(Path);
            var generalHamiltonian = (Format switch
            {
                DataFormat.Broombridge => BroombridgeSerializer
                .Deserialize(reader),
                DataFormat.LiQuiD => LiQuiDSerializer
                .Deserialize(reader),
                _ => throw new ArgumentException($"Invalid data format {Format}.")
            })
Esempio n. 2
0
 static void ParseLiQuiD(string path, out int nElectrons, out FermionHamiltonian hamiltonian)
 {
     using var reader = File.OpenText(path);
     nElectrons       = 2;
     hamiltonian      = LiQuiDSerializer
                        .Deserialize(reader)
                        .Single()
                        .OrbitalIntegralHamiltonian
                        .ToFermionHamiltonian(IndexConvention.UpDown);
 }
Esempio n. 3
0
 // This method computes the gate count of simulation by all configurations passed to it.
 internal static async Task <IEnumerable <GateCountResults> > RunGateCount(
     string filename, IntegralDataFormat format, IEnumerable <HamiltonianSimulationConfig> configurations,
     string outputFolder = null
     )
 {
     using var reader = File.OpenText(filename);
     // To get the data for exporting to Q#, we proceed in several steps.
     var jordanWignerEncoding =
         // First, we deserialize the file given by filename, using the
         // format given by format.
         (format switch
     {
         IntegralDataFormat.Liquid => LiQuiDSerializer.Deserialize(reader),
         IntegralDataFormat.Broombridge => BroombridgeSerializer.Deserialize(reader),
         _ => throw new ArgumentException($"Invalid data format {format}.")
     })
Esempio n. 4
0
        public void LoadFromLiquidTest(string line, TermType.OrbitalIntegral termType, OrbitalIntegral term)
        {
            //var test = terms.Item1;
            //string[] lines, FermionTermType termType, FermionTerm[] terms
            var hamiltonian = LiQuiDSerializer.DeserializeSingleProblem(line).OrbitalIntegralHamiltonian;

            Assert.True(hamiltonian.Terms.ContainsKey(termType));
            // Check that expected terms are found

            var orb = hamiltonian.Terms[termType].Keys.First();

            // Check index
            //Assert.True(term == orb);

            // Check coefficient
            Assert.Equal(term.Coefficient, hamiltonian.Terms[termType][term.ToCanonicalForm()].Value);
        }
        static void LoadFromLiquidFile()
        {
            // This is the name of the file we want to load
            var filename = @"B_sto6g.dat"; // This is Ferrodoxin.
            // This is the directory containing the file
            var root = @"Molecules";

            // Deserialize the LiQuiD format.
            using var reader = File.OpenText(Path.Combine(root, filename));
            var problem = LiQuiDSerializer.Deserialize(reader).First();

            // This extracts the `OrbitalIntegralHamiltonian` from problem
            // description format.
            var orbitalIntegralHamiltonian = problem.OrbitalIntegralHamiltonian;

            Assert.True(orbitalIntegralHamiltonian.CountTerms() > 10);
        }