def test_orbital_reduction(self): """ orbital reduction test --- Remove virtual orbital just for test purposes (not sensible!) """ fermionic_transformation = FermionicTransformation( transformation=TransformationType.FULL, qubit_mapping=QubitMappingType.JORDAN_WIGNER, two_qubit_reduction=False, freeze_core=False, orbital_reduction=[-1]) # get dummy aux operator qmolecule = self.driver.run() fer_op = FermionicOperator(h1=qmolecule.one_body_integrals, h2=qmolecule.two_body_integrals) dummy = fer_op.total_particle_number() expected = (I ^ I) - 0.5 * (I ^ Z) - 0.5 * (Z ^ I) qubit_op, aux_ops = fermionic_transformation.transform( self.driver, [dummy]) self._validate_vars(fermionic_transformation) self._validate_info(fermionic_transformation, num_orbitals=2) self._validate_input_object(qubit_op, num_qubits=2, num_paulis=4) # the first six aux_ops are added automatically, ours is the 7th one self.assertEqual(aux_ops[6], expected)
### ---- construct qubit Hamiltonian ---- h1 = molecule.one_body_integrals h2 = molecule.two_body_integrals ferOp = FermionicOperator(h1=h1, h2=h2) core_energy = 0 # GLOBAL var : qubitOp qubitOp = ferOp.mapping(map_type=map_type, threshold=thre) if qubit_reduction and map_type == "parity": qubitOp = Z2Symmetries.two_qubit_reduction(qubitOp, num_particles) qubitOp.chop(10**-10) qubitOp.simplify() n_qubits = qubitOp.num_qubits ## prepare conserved quantities tot_N = ferOp.total_particle_number().mapping(map_type=map_type, threshold=thre) tot_Ssq = ferOp.total_angular_momentum().mapping(map_type=map_type, threshold=thre) if qubit_reduction and map_type == "parity": tot_N = Z2Symmetries.two_qubit_reduction(tot_N, num_particles) tot_Ssq = Z2Symmetries.two_qubit_reduction(tot_Ssq, num_particles) # ## VQD execution # In[29]: def spsa_optimization(obj_fun, initial_theta, max_trials, save_steps, last_avg, spsa_c, spsa_fargs): """Minimizes obj_fun(theta) with a simultaneous perturbation stochastic approximation algorithm.