| 18 | namespace cudaq::detail { |
| 19 | |
| 20 | evolve_result evolveSingle(const cudaq::rydberg_hamiltonian &hamiltonian, |
| 21 | const cudaq::schedule &schedule, |
| 22 | std::optional<int> shots_count = std::nullopt) { |
| 23 | auto amp = hamiltonian.get_amplitude(); |
| 24 | auto ph = hamiltonian.get_phase(); |
| 25 | auto dg = hamiltonian.get_delta_global(); |
| 26 | std::vector<std::pair<double, double>> amp_ts; |
| 27 | std::vector<std::pair<double, double>> ph_ts; |
| 28 | std::vector<std::pair<double, double>> dg_ts; |
| 29 | for (const auto &step : schedule) { |
| 30 | auto amp_res = amp.evaluate({{"t", step}}); |
| 31 | amp_ts.push_back(std::make_pair(amp_res.real(), step.real())); |
| 32 | |
| 33 | auto ph_res = ph.evaluate({{"t", step}}); |
| 34 | ph_ts.push_back(std::make_pair(ph_res.real(), step.real())); |
| 35 | |
| 36 | auto dg_res = dg.evaluate({{"t", step}}); |
| 37 | dg_ts.push_back(std::make_pair(dg_res.real(), step.real())); |
| 38 | } |
| 39 | |
| 40 | auto atoms = cudaq::ahs::AtomArrangement(); |
| 41 | for (auto pair : hamiltonian.get_atom_sites()) |
| 42 | atoms.sites.push_back({pair.first, pair.second}); |
| 43 | atoms.filling = hamiltonian.get_atom_filling(); |
| 44 | |
| 45 | auto omega = cudaq::ahs::PhysicalField(); |
| 46 | omega.time_series = cudaq::ahs::TimeSeries(amp_ts); |
| 47 | |
| 48 | auto phi = cudaq::ahs::PhysicalField(); |
| 49 | phi.time_series = cudaq::ahs::TimeSeries(ph_ts); |
| 50 | |
| 51 | auto delta = cudaq::ahs::PhysicalField(); |
| 52 | delta.time_series = cudaq::ahs::TimeSeries(dg_ts); |
| 53 | |
| 54 | auto drive = cudaq::ahs::DrivingField(); |
| 55 | drive.amplitude = omega; |
| 56 | drive.phase = phi; |
| 57 | drive.detuning = delta; |
| 58 | |
| 59 | auto program = cudaq::ahs::Program(); |
| 60 | program.setup.ahs_register = atoms; |
| 61 | program.hamiltonian.drivingFields = {drive}; |
| 62 | program.hamiltonian.localDetuning = {}; |
| 63 | |
| 64 | std::ostringstream programName; |
| 65 | programName << "__analog_hamiltonian_kernel__" << []() { |
| 66 | const char chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; |
| 67 | const auto length = sizeof(chars) / sizeof(char); |
| 68 | std::random_device rd; |
| 69 | std::mt19937 generator(rd()); |
| 70 | std::uniform_int_distribution<> distribution(0, length - 1); |
| 71 | std::string result; |
| 72 | result.reserve(10); |
| 73 | for (int i = 0; i < 10; ++i) |
| 74 | result += chars[distribution(generator)]; |
| 75 | return result; |
| 76 | }(); |
| 77 | |