Skip to content

Commit

Permalink
Tempering update (#441)
Browse files Browse the repository at this point in the history
* added exchange_map parameter

* added part to output for tempering

* trying to output exchanges

* added exchange statistics to out-file regarding parallel tempering exchanges

* updated exchange statistics for parallel tempering

* changed to small letters for xyzqi etc. in tempering argument  in schema.yml file

* fixed 3 first comments in PR  #441

* update to tempering print out file

* modified move.h

* fixed missing bracket

* error fixed

* fixed errors with writing to exchange file for tempering

---------

Co-authored-by: IVinterbladh <[email protected]>
Co-authored-by: IVinterbladh <[email protected]>
  • Loading branch information
3 people authored Jul 18, 2024
1 parent 6a92a9e commit 2a09f79
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 7 deletions.
7 changes: 5 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@
"utility": "cpp",
"stop_token": "cpp",
"tensorsymmetry": "cpp",
"core": "cpp"
}
"core": "cpp",
"shared_mutex": "cpp",
"cfenv": "cpp"
},
"C_Cpp.errorSquiggles": "disabled"
}
3 changes: 3 additions & 0 deletions docs/_docs/moves.md
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,9 @@ Support for fluctuating number of particles, i.e.
grand canonical moves is currently untested and should be
considered experimental.

#Exchange statistics
In the output file, the acceptance and attempts of an exchange direction can be found under exchange in temper;moves. Next, the first tap under exchangempi gives which mpi box the outfile represents (ex. 0, 1,...). Under this number the tab exchanges all executed temper movements are listed. For each movement two placeholders are given, which represents the mpi's the tempering algorithm tries to switch. If the tempering move was not accepted, both the placeholders will be -1. When the tempering move is accepted do the placeholders contain the numbers of the interchanged mpi's. In faunus/examples/temper there is a notebook "temper\_exchange\_statistics.ipynb" illustrating how this aquired data can be used to study how the mpi's are exchanged.


## Volume Move

Expand Down
11 changes: 7 additions & 4 deletions docs/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -880,10 +880,13 @@ properties:
default: isotropic
format:
type: string
enum: [XYZQI, XYZQ, XYZ]
default: XYZQI
description: "Which particle properties to exchange (I=atom id, Q=charge)"

enum: [xyzqi, xyzq, xyz]
default: xyzqi
description: "Which particle properties to exchange (i=atom id, q=charge)"
file:
type: string
pattern: "(.*?)\\.(dat|dat.gz))$"
description: "file with exchange statistics from tempering"
additionalProperties: false
type: object

Expand Down
21 changes: 20 additions & 1 deletion 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 @@ -913,18 +913,37 @@ double ParallelTempering::bias([[maybe_unused]] Change& change, double uold, dou
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.0;
writeToFileStream();
}

void ParallelTempering::_from_json(const json& j)
{
exchange_particles.setFormat(j.value("format", MPI::ParticleBuffer::Format::XYZQI));
partner = createMPIPartnerPolicy(j.value("partner_policy", MPI::PartnerPolicy::ODDEVEN));
volume_scaling_method = j.value("volume_scale", Geometry::VolumeMethod::ISOTROPIC);

if (filename = j.value("file", ""s); !filename.empty()) {
filename = MPI::prefix + filename;
stream = IO::openCompressedOutputStream(filename, true); // throws if error
*stream << "# step exchange\n"s;
}
}

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

ParallelTempering::ParallelTempering(Space& spc, const MPI::Controller& mpi)
Expand Down
6 changes: 6 additions & 0 deletions src/move.h
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,7 @@ class ParallelTempering : public Move
Geometry::VolumeMethod volume_scaling_method =
Geometry::VolumeMethod::ISOTROPIC; //!< How to scale volumes
std::map<MPI::Partner::PartnerPair, Average<double>> acceptance_map; //!< Exchange statistics

Random slump; // static instance of Random (shared for all in ParallelTempering)
void _to_json(json& j) const override;
void _from_json(const json& j) override;
Expand All @@ -587,6 +588,11 @@ class ParallelTempering : public Move
double exchangeEnergy(double energy_change); //!< Exchange energy with partner
void exchangeState(Change& change); //!< Exchange positions, charges, volume etc.
void exchangeGroupSizes(Space::GroupVector& groups, int partner_rank);

std::string filename; //file name for exchange statistics
std::unique_ptr<std::ostream> stream; //log exchange statistics in 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 2a09f79

Please sign in to comment.