// Parses all wavefunctions.
        internal static (StateType, double, object) ToWavefunction(V0_2.State state)
        {
            StateType             method          = ParseInitialStateMethod(state.Method);
            double                energy          = state.Energy != null ? state.Energy.Value : 0.0;
            List <List <string> > superposition   = state.Superposition ?? new List <List <string> >();
            ClusterOperator       clusterOperator = state.ClusterOperator;
            object                outputState;

            if (method == StateType.SparseMultiConfigurational)
            {
                outputState = ToSparseMultiCFWavefunction(superposition);
            }
            else if (method == StateType.UnitaryCoupledCluster)
            {
                outputState = ToUnitaryCCWavefunction(clusterOperator);
            }
            else
            {
                throw new System.ArgumentException($"initial state `{state.Label}` is not recognized or implemented.");
            }
            return(method, energy, outputState);
        }
        // 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);
        }