/// <summary> /// Translate initial state specified by a unitary coupled-cluster operator acting on a single-reference state /// to a format consumable by Q#. /// </summary> /// <param name="terms">single-reference state and cluster operator terms.</param> /// <returns>Q# description of unitary coupled-cluster state.</returns> internal static QArray <JordanWignerInputState> InitialStateUnitaryCoupledCluster( UnitaryCCWavefunction <int> wavefunction) { // The last term is the reference state. var referenceState = wavefunction.Reference; var clusterOperator = wavefunction.Excitations; var stateElements = clusterOperator.Select(o => InitialStatePrep(o.Value, o.Key, checkAnnihilation: false)).ToList(); stateElements.Add(InitialStatePrep(new System.Numerics.Complex(1.0, 0.0), referenceState, checkAnnihilation: true)); var stateQSharp = new QArray <JordanWignerInputState>(stateElements); return(stateQSharp); }
// 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); }