Skip to content

Commit

Permalink
sync js
Browse files Browse the repository at this point in the history
  • Loading branch information
Strilanc committed Aug 19, 2023
1 parent 37b8c6f commit a840b1b
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 16 deletions.
11 changes: 0 additions & 11 deletions glue/javascript/common.js.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,6 @@

using namespace stim;

static bool shared_rng_initialized;
static std::mt19937_64 shared_rng;

std::mt19937_64 &JS_BIND_SHARED_RNG() {
if (!shared_rng_initialized) {
shared_rng = externally_seeded_rng();
shared_rng_initialized = true;
}
return shared_rng;
}

uint32_t js_val_to_uint32_t(const emscripten::val &val) {
double v = val.as<double>();
double f = floor(v);
Expand Down
2 changes: 0 additions & 2 deletions glue/javascript/common.js.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

#include "stim/probability_util.h"

std::mt19937_64 &JS_BIND_SHARED_RNG();

template <typename T>
emscripten::val vec_to_js_array(const std::vector<T> &items) {
emscripten::val result = emscripten::val::array();
Expand Down
3 changes: 2 additions & 1 deletion glue/javascript/pauli_string.js.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ ExposedPauliString::ExposedPauliString(const emscripten::val &arg) : pauli_strin
}

ExposedPauliString ExposedPauliString::random(size_t n) {
return ExposedPauliString(PauliString<stim::MAX_BITWORD_WIDTH>::random(n, JS_BIND_SHARED_RNG()));
auto rng = externally_seeded_rng();
return ExposedPauliString(PauliString<stim::MAX_BITWORD_WIDTH>::random(n, rng));
}

ExposedPauliString ExposedPauliString::times(const ExposedPauliString &other) const {
Expand Down
3 changes: 2 additions & 1 deletion glue/javascript/tableau.js.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ ExposedTableau::ExposedTableau(int n) : tableau(n) {
}

ExposedTableau ExposedTableau::random(int n) {
return ExposedTableau(Tableau<MAX_BITWORD_WIDTH>::random(n, JS_BIND_SHARED_RNG()));
auto rng = externally_seeded_rng();
return ExposedTableau(Tableau<MAX_BITWORD_WIDTH>::random(n, rng));
}

ExposedTableau ExposedTableau::from_named_gate(const std::string &name) {
Expand Down
2 changes: 1 addition & 1 deletion glue/javascript/tableau_simulator.js.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ static JsCircuitInstruction args_to_target_pairs(TableauSimulator<MAX_BITWORD_WI
return result;
}

ExposedTableauSimulator::ExposedTableauSimulator() : sim(JS_BIND_SHARED_RNG(), 0) {
ExposedTableauSimulator::ExposedTableauSimulator() : sim(externally_seeded_rng(), 0) {
}

bool ExposedTableauSimulator::measure(size_t target) {
Expand Down

0 comments on commit a840b1b

Please sign in to comment.