Commit 74c0ad03 authored by Nguyen, Thien Minh's avatar Nguyen, Thien Minh
Browse files

Updated quantum quench example



Signed-off-by: default avatarThien Nguyen <nguyentm@ornl.gov>
parent 72118de2
Loading
Loading
Loading
Loading
+38 −0
Original line number Diff line number Diff line
#include "qcor_qsim.hpp"

// Simulate dynamics of a quantum quench of 
// a 1D antiferromagnetic Heisenberg model.

// Compile and run with:
/// $ qcor -qpu qsim QuantumQuenchSimulation.cpp
/// $ ./a.out
int main(int argc, char **argv) {
  using ModelType = qcor::qsim::ModelBuilder::ModelType;
  // Initial spin state: Neel state (7 qubits/spins)
  const std::vector<int> initial_spins{0, 1, 0, 1, 0, 1, 0};
  auto problemModel = qsim::ModelBuilder::createModel(
      ModelType::Heisenberg, {{"Jx", 1.0},
                              {"Jy", 1.0},
                              {"Jz", 0.2},
                              {"h_ext", 0.0},
                              {"ext_dir", "X"},
                              {"num_spins", 7},
                              {"initial_spins", initial_spins},
                              {"observable", "staggered_magnetization"}});
  // Workflow parameters:
  auto workflow = qsim::getWorkflow(
      "td-evolution", {{"dt", 0.05}, {"steps", 100}});

  // Result should contain the observable expectation value along Trotter steps.
  auto result = workflow->execute(problemModel);
  // Get the observable values (average magnetization)
  const auto obsVals = result.get<std::vector<double>>("exp-vals");

  // Print out for debugging:
  std::cout << "<Staggered Magnetization> = \n"; 
  for (const auto &val : obsVals) {
    std::cout << val << "\n";
  }

  return 0;
}
+12 −8
Original line number Diff line number Diff line
@@ -7,24 +7,28 @@ import numpy as np
import matplotlib.pyplot as plt

# Heisenberg quench model input
problemModel = qsim.ModelBuilder.createModel(ModelType.Heisenberg, {'Jz': 0.8,
                                                       'h_ext': 0.2,
                                                       'ext_dir': 'X',
                                                       'num_spins': 8,
problemModel = qsim.ModelBuilder.createModel(ModelType.Heisenberg, {'Jx': 1.0,
                                                                    'Jy': 1.0,
                                                                    'Jz': 0.2,
                                                                    'h_ext': 0.0,
                                                                    'num_spins': 7,
                                                                    'initial_spins': [0, 1, 0, 1, 0, 1, 0],
                                                                    'observable': 'staggered_magnetization'})
print(problemModel)

# Run TD workflow:
workflow = qsim.getWorkflow(
      'td-evolution', {'dt': 1.0, 'steps': 20})
      'td-evolution', {'dt': 0.05, 'steps': 100})
result = workflow.execute(problemModel)

# Plot the result:
t = np.linspace(0, 20, 21)
t = np.linspace(0, 5, 101)
y = result["exp-vals"]
result_save = np.asarray(y)
result_save.tofile('run_g_0.2.csv',sep=',',format='%10.5f')
axes = plt.axes()
axes.plot(t, y)
axes.set_xlim([0,20])
axes.set_xlim([0,5])
# axes.set_ylim([0,1])
# Save the plot to a file:
os.chdir(os.path.dirname(os.path.abspath(__file__)))