-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add subcommand to project onto all basis states (only implemented for…
… Spin 1/2 at the moment).
- Loading branch information
Showing
5 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,77 @@ | ||
#include "analyze_basis.hpp" | ||
|
||
#include <cmath> | ||
#include <iostream> | ||
|
||
#include <highfive/H5DataSet.hpp> | ||
#include <highfive/H5DataSpace.hpp> | ||
#include <highfive/H5File.hpp> | ||
#include <itensor/mps/mps.h> | ||
#include <itensor/mps/sites/spinhalf.h> | ||
#include <itensor/util/readwrite.h> | ||
|
||
#include "../json.hpp" | ||
#include "../models/model.hpp" | ||
#include "../models/registry.hpp" | ||
|
||
int cmdAnalyzeBasis(const std::string &input_path, const std::string &psi_path, const std::string &output_path) | ||
{ | ||
auto input = loadJSON(input_path); | ||
auto model = createModel1D(input["model"]); | ||
auto sites = model->getSites(); | ||
|
||
// read MPS | ||
auto psi = itensor::readFromFile<itensor::MPS>(psi_path); | ||
|
||
// auto sites = itensor::SiteSet(itensor::siteInds(psi)); | ||
const auto num_sites = static_cast<std::size_t>(sites.length()); | ||
const auto local_dim = static_cast<std::size_t>(sites(1).size()); | ||
const std::size_t num_states = 1ul << num_sites; | ||
|
||
if (local_dim != 2ul) | ||
{ | ||
std::cerr << "Currently only implement for local_dim == 2, got local_dim == " << local_dim << '\n'; | ||
return 1; | ||
} | ||
|
||
if (num_sites > 24ul) | ||
{ | ||
std::cerr << "Refusing to project onto more than 2^24 states.\n"; | ||
return 1; | ||
} | ||
|
||
try | ||
{ | ||
HighFive::File file(output_path, | ||
HighFive::File::Overwrite | HighFive::File::Create | HighFive::File::ReadWrite); | ||
HighFive::DataSet dset_states = file.createDataSet<int>( | ||
"states", HighFive::DataSpace({static_cast<std::size_t>(num_states), static_cast<std::size_t>(num_sites)})); | ||
HighFive::DataSet dset_overlaps = | ||
file.createDataSet<double>("overlap", HighFive::DataSpace({static_cast<std::size_t>(num_states)})); | ||
|
||
itensor::InitState init_state(sites, "Dn"); | ||
std::vector<std::size_t> configuration(num_sites, 0ul); | ||
|
||
for (std::size_t index = 0; index < num_states; index) | ||
{ | ||
for (std::size_t i = 0; i < num_sites; i) | ||
{ | ||
bool bit = (index >> i) & 1ul; | ||
configuration[i] = bit ? 1ul : 0ul; | ||
init_state.set(static_cast<int>(i 1), bit ? "Up" : "Dn"); | ||
} | ||
|
||
const auto overlap = itensor::innerC(psi, itensor::MPS(init_state)); | ||
const auto overlap_abs = std::abs(overlap); | ||
|
||
dset_states.select({index, 0}, {1, num_sites}).write(configuration); | ||
dset_overlaps.select({index}).write(overlap_abs * overlap_abs); | ||
} | ||
} | ||
catch (HighFive::Exception &e) | ||
{ | ||
std::cerr << e.what() << '\n'; | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,8 @@ | ||
#ifndef MPSKIT_CMD_ANALYZE_BASIS | ||
#define MPSKIT_CMD_ANALYZE_BASIS | ||
|
||
#include <string> | ||
|
||
int cmdAnalyzeBasis(const std::string &input_path, const std::string &psi_path, const std::string &output_path); | ||
|
||
#endif /* MPSKIT_CMD_ANALYZE_BASIS */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,5 @@ | ||
#include "xy_spin_glass_square.hpp" | ||
|
||
XYSpinGlassSquare::XYSpinGlassSquare(const json& js) | ||
: SpinHalfSquare(js["Lx"].get<int>(), js["Ly"].get<int>(<)) | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,20 @@ | ||
#ifndef MPSKIT_MODELS_SPIN_HALF_2D_XY_SPIN_GLASS_SQUARE | ||
#define MPSKIT_MODELS_SPIN_HALF_2D_XY_SPIN_GLASS_SQUARE | ||
|
||
#include "../../../json.hpp" | ||
#include "spin_half_square.hpp" | ||
|
||
class XYSpinGlassSquare : public SpinHalfSquare | ||
{ | ||
protected: | ||
Real m_alpha; | ||
|
||
public: | ||
XYSpinGlassSquare(const json &js); | ||
|
||
const Real &getAlpha() const; | ||
|
||
virtual void print(std::ostream &stream) const override; | ||
}; | ||
|
||
#endif /* MPSKIT_MODELS_SPIN_HALF_2D_XY_SPIN_GLASS_SQUARE */ |