def get_uccsd_circuit(molecule, theta_vector=None, use_basis_gates=False): """Produce the full UCCSD circuit. Args: molecule :: string - must be a key of MOLECULE_TO_INFO theta_vector :: array - arguments for the vqe ansatz. If None, will generate random angles. use_basis_gates :: bool - Mike and Ike gates if False, Basis gates if True. Returns: circuit :: qiskit.QuantumCircuit - the UCCSD circuit parameterized by theta_vector, unoptimized """ molecule_info = MOLECULE_TO_INFO[molecule] driver = PySCFDriver(atom=molecule_info.atomic_string, basis='sto3g') qmolecule = driver.run() hamiltonian = Hamiltonian( qubit_mapping=QubitMappingType.PARITY, two_qubit_reduction=True, freeze_core=True, orbital_reduction=molecule_info.orbital_reduction) energy_input = hamiltonian.run(qmolecule) qubit_op = energy_input.qubit_op num_spin_orbitals = hamiltonian.molecule_info['num_orbitals'] num_particles = hamiltonian.molecule_info['num_particles'] map_type = hamiltonian._qubit_mapping qubit_reduction = hamiltonian.molecule_info['two_qubit_reduction'] HF_state = HartreeFock(qubit_op.num_qubits, num_spin_orbitals, num_particles, map_type, qubit_reduction) var_form = UCCSD(qubit_op.num_qubits, depth=1, num_orbitals=num_spin_orbitals, num_particles=num_particles, active_occupied=molecule_info.active_occupied, active_unoccupied=molecule_info.active_unoccupied, initial_state=HF_state, qubit_mapping=map_type, two_qubit_reduction=qubit_reduction, num_time_slices=1) if theta_vector is None: theta_vector = [ np.random.rand() * 2 * np.pi for _ in range(var_form._num_parameters) ] circuit = var_form.construct_circuit(theta_vector, use_basis_gates=use_basis_gates) return circuit
HF_state = HartreeFock(qubitOp.num_qubits, num_spin_orbitals, num_particles, map_type, qubit_reduction) # setup UCCSD variational form var_form = UCCSD(qubitOp.num_qubits, depth=1, num_orbitals=num_spin_orbitals, num_particles=num_particles, active_occupied=[0], active_unoccupied=[0, 1], initial_state=HF_state, qubit_mapping=map_type, two_qubit_reduction=qubit_reduction, num_time_slices=1) circuit = var_form.construct_circuit(parameters, use_basis_gates=False) print("Target circuit initialized.", flush=True) #circuit.draw(output='text', line_length=350) backend_sim = Aer.get_backend('unitary_simulator') result = qiskit.execute(circuit, backend_sim).result() U = result.get_unitary() print(U.shape, flush=True) print(U, flush=True) U = transmon_gate(U, d) print("Target U initialized.", flush=True)