// Parses MCF wavefunction. internal static SparseMultiCFWavefunction <SpinOrbital> ToSparseMultiCFWavefunction(List <List <string> > superposition) { var outputState = new SparseMultiCFWavefunction <SpinOrbital>(); // Todo: modify broombridge to have explicit reference state. foreach (var element in superposition) { // First item is the amplitude. double amplitude = double.Parse(element.First().ToString(), System.Globalization.CultureInfo.InvariantCulture); // Second to Second-last are fermion operators. IEnumerable <LadderOperator <SpinOrbital> > operators = element .Take(element.Count() - 1) .Skip(1) .Select(o => V0_1.ParsePolishNotation(o.ToString())); var ladderSequence = new LadderSequence <SpinOrbital>(operators); // Sort operators to index order. IEnumerable <IndexOrderedSequence <SpinOrbital> > sortedOperators = ladderSequence.ToIndexOrder(); // Only select the shortest term with no repeated indices. IndexOrderedSequence <SpinOrbital> sortedOperator = sortedOperators.ToList().OrderBy(o => o.UniqueIndices()).First(); outputState.Set(sortedOperator, new Complex(amplitude, 0.0)); } return(outputState); }
public void Empty() { var term = new LadderSequence(new List <LadderOperator>()); var term2 = new LadderSequence(new List <LadderOperator>()); Dictionary <LadderSequence, double> dictionary = new Dictionary <LadderSequence, double>(); dictionary.Add(term, 0.5); Assert.Equal(0.5, dictionary[term2]); }
public void NotPassByReference() { var ints = new[] { 1, 2, 4, 3 }; var op = new[] { 1, 2, 4, 3 }.ToLadderSequence(); var newTerm = new LadderSequence(op); ints[2] = 5; Assert.Equal(op.Sequence, newTerm.Sequence); op.Sequence[2] = new LadderOperator(RaisingLowering.d, 6); Assert.NotEqual(op.Sequence, newTerm.Sequence); var newTerm2 = new LadderSequence(ints.ToLadderSequence()); ints[1] = 0; Assert.Equal(2, newTerm2.Sequence[1].Index); var op2 = new[] { (u, 2), (d, 5), (d, 8) };
// Parses UCC wavefunction. internal static UnitaryCCWavefunction <SpinOrbital> ToUnitaryCCWavefunction(ClusterOperator clusterOperator) { var outputState = new UnitaryCCWavefunction <SpinOrbital>(); var oneBodyTerms = clusterOperator.OneBodyAmplitudes ?? new List <List <string> >(); var twoBodyTerms = clusterOperator.TwoBodyAmplitudes ?? new List <List <string> >(); foreach (var element in oneBodyTerms.Concat(twoBodyTerms)) { // First item is the amplitude. double amplitude = double.Parse(element.First().ToString(), System.Globalization.CultureInfo.InvariantCulture); // Second to last are fermion operators. IEnumerable <LadderOperator <SpinOrbital> > operators = element .Skip(1) .Select(o => V0_1.ParsePolishNotation(o.ToString())); var ladderSequence = new LadderSequence <SpinOrbital>(operators); // Terms are assumed to be in normal order. var sortedOperator = new IndexOrderedSequence <SpinOrbital>(operators); outputState.Set(sortedOperator, new Complex(amplitude, 0.0)); } var reference = new List <List <string> >() { clusterOperator.Reference }; outputState.Reference = new SingleCFWavefunction <SpinOrbital>( ToSparseMultiCFWavefunction(reference).Excitations.Single().Key.ToIndices() ); return(outputState); }
/// <summary> /// Construct fermion term instance from a normal-ordered sequence of ladder operators. /// </summary> /// <param name="ladderOperators">Normal-ordered sequence of ladder operators.</param> public FermionTerm(LadderSequence <int> ladderOperators) : base(ladderOperators) { }
/// <summary> /// Constructs a Hermitian fermion term from a normal-ordered sequence of ladder operators. /// </summary> /// <param name="ladderOperators">Normal-ordered sequence of ladder operators.</param> public HermitianFermionTerm(LadderSequence <int> ladderOperators) : base(ladderOperators) { NormalizeToCanonicalOrder(); }