Skip to content

Commit

Permalink
fixed errors with writing to exchange file for tempering
Browse files Browse the repository at this point in the history
  • Loading branch information
IVinterbladh committed Jul 18, 2024
1 parent b8a6939 commit bd33c8f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
15 changes: 8 additions & 7 deletions src/move.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ void ParallelTempering::_move(Change& change)
}
partner->generate(mpi.world, slump);
if (partner->rank.has_value()) {
exchangeState(change);
exchangeState(change);
}
}

Expand Down Expand Up @@ -914,13 +914,15 @@ void ParallelTempering::_accept([[maybe_unused]] Change& change)
{
acceptance_map[partner->getPair(mpi.world)] += 1.0;
exchange = partner->rank.value();
writeToFileStream();

}

void ParallelTempering::_reject([[maybe_unused]] Change& change)
{
acceptance_map[partner->getPair(mpi.world)] += 0.0;
//exchange = -1;
exchange = -1.0;
writeToFileStream();
}

void ParallelTempering::_from_json(const json& j)
Expand All @@ -932,16 +934,15 @@ void ParallelTempering::_from_json(const json& j)
if (filename = j.value("file", ""s); !filename.empty()) {
filename = MPI::prefix + filename;
stream = IO::openCompressedOutputStream(filename, true); // throws if error
*stream << "# exchange\n"s;
*stream << "# step exchange\n"s;
}
}

void ParallelTempering::writeToFileStream(Change& change) const
void ParallelTempering::writeToFileStream() const
{
if (stream) {
// file to disk?
*stream << fmt::format("{:.6E}\n", exchange);
*stream << "\n"; // trailing newline
// file to disk?:
*stream << fmt::format("{:d} {:.6E}\n", number_of_attempted_moves , exchange);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/move.h
Original file line number Diff line number Diff line change
Expand Up @@ -591,8 +591,8 @@ class ParallelTempering : public Move

std::string filename; //file name for exchange statistics
std::unique_ptr<std::ostream> stream; //log exchange statistics in file
double exchange = 0 ; // if no exchange, this is 0
void writeToFileStream(double exchange) const; //!< Write exchange statistics to file
double exchange; // if no exchange, this is 0
void writeToFileStream() const; //!< Write exchange statistics to file

public:
explicit ParallelTempering(Space& spc, const MPI::Controller& mpi);
Expand Down

0 comments on commit bd33c8f

Please sign in to comment.