Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 25 additions & 11 deletions Network/SimpleDisconnectedNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,8 @@ class SimpleDisconnectedNetwork : public INetwork<Time> {
nrThreads = 1;
else
#endif
if (((method == Simulators::SimulationType::kStatevector || method == Simulators::SimulationType::kPathIntegral) &&
if (((method == Simulators::SimulationType::kStatevector ||
method == Simulators::SimulationType::kPathIntegral) &&
!distCirc->HasOpsAfterMeasurements()) ||
simType == Simulators::SimulatorType::kQuestSim)
nrThreads = 1;
Expand Down Expand Up @@ -786,6 +787,11 @@ class SimpleDisconnectedNetwork : public INetwork<Time> {
auto optSim = ChooseBestSimulator(distCirc, shots, nrQubits, nrCbits,
nrCbits, simType, method, executed);

// Seed the executing simulator's terminal sampling RNG, if requested. The
// single-thread path uses optSim directly; in the multi-thread path each
// Clone() derives a distinct deterministic seed from this one.
if (optSim && !seed.empty()) optSim->Configure("seed", seed.c_str());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Job simulators stay unseeded

This only seeds optSim when ChooseBestSimulator() returns one. If no optimized simulator is selected, ExecuteJob creates its own simulator later and only forwards MPS-related options, so the configured seed is dropped and terminal sampling stays random for that execution path.

Prompt To Fix With AI
This is a comment left during a code review.
Path: Network/SimpleDisconnectedNetwork.h
Line: 793

Comment:
**Job simulators stay unseeded**

This only seeds `optSim` when `ChooseBestSimulator()` returns one. If no optimized simulator is selected, `ExecuteJob` creates its own simulator later and only forwards MPS-related options, so the configured seed is dropped and terminal sampling stays random for that execution path.

How can I resolve this? If you propose a fix, please make it concise.


lastSimulatorType = simType;
lastMethod = method;

Expand Down Expand Up @@ -1001,6 +1007,8 @@ class SimpleDisconnectedNetwork : public INetwork<Time> {
(std::string("1") == value || std::string("true") == value);
else if (std::string("max_simulators") == key)
maxSimulators = std::stoull(value);
else if (std::string("seed") == key)
seed = value;

if (simulator) simulator->Configure(key, value);
}
Expand Down Expand Up @@ -1898,8 +1906,10 @@ class SimpleDisconnectedNetwork : public INetwork<Time> {

cloned->SetMPSOptimizeSwaps(GetMPSOptimizeSwaps());

cloned->SetMPSOptimizationBondDimensionThreshold(GetMPSOptimizationBondDimensionThreshold());
cloned->SetMPSOptimizationQubitsNumberThreshold(GetMPSOptimizationQubitsNumberThreshold());
cloned->SetMPSOptimizationBondDimensionThreshold(
GetMPSOptimizationBondDimensionThreshold());
cloned->SetMPSOptimizationQubitsNumberThreshold(
GetMPSOptimizationQubitsNumberThreshold());

cloned->SetLookaheadDepth(GetLookaheadDepth());
cloned->SetLookaheadDepthWithHeuristic(GetLookaheadDepthWithHeuristic());
Expand Down Expand Up @@ -1989,9 +1999,8 @@ class SimpleDisconnectedNetwork : public INetwork<Time> {
simulatorTypes.emplace_back(Simulators::SimulatorType::kQCSim,
Simulators::SimulationType::kPauliPropagator);

if (OptimizationSimulatorExists(
Simulators::SimulatorType::kQCSim,
Simulators::SimulationType::kPathIntegral))
if (OptimizationSimulatorExists(Simulators::SimulatorType::kQCSim,
Simulators::SimulationType::kPathIntegral))
simulatorTypes.emplace_back(Simulators::SimulatorType::kQCSim,
Simulators::SimulationType::kPathIntegral);

Expand Down Expand Up @@ -2207,7 +2216,8 @@ class SimpleDisconnectedNetwork : public INetwork<Time> {
maxBondDim.empty() ? 0 : std::stoi(maxBondDim);

if (maxBondDim.empty() ||
static_cast<int>(mpsOptimizationBondDimensionThreshold) <= maxBondDimValue) {
static_cast<int>(mpsOptimizationBondDimensionThreshold) <=
maxBondDimValue) {
// need to be sure the circuit is correctly converted
dcirc->ConvertForCutting(); // convert the three qubit gates
auto layers = dcirc->ToMultipleQubitsLayersNoClone();
Expand Down Expand Up @@ -2245,8 +2255,9 @@ class SimpleDisconnectedNetwork : public INetwork<Time> {
}
avgTwoQubitGatesPerLayer /= layers.size();

int lookaheadVal = static_cast<int>(4. * avgTwoQubitGatesPerLayer);
if (lookaheadVal > 15) lookaheadVal = 15;
int lookaheadVal = static_cast<int>(4. *
avgTwoQubitGatesPerLayer); if (lookaheadVal > 15) lookaheadVal =
15;

lookaheadDepthLocal =
layers.size() < 8 || nrQubits <= 10 ? 0
Expand All @@ -2269,8 +2280,9 @@ class SimpleDisconnectedNetwork : public INetwork<Time> {
*/
lookaheadHeuristicDepthLocal =
layers.size() < 10 || nrQubits <= 10
? 0 : lookaheadDepthLocal - 2;

? 0
: lookaheadDepthLocal - 2;

if (lookaheadHeuristicDepthLocal < 0)
lookaheadHeuristicDepthLocal = 0;

Expand Down Expand Up @@ -2479,6 +2491,8 @@ class SimpleDisconnectedNetwork : public INetwork<Time> {
std::string maxBondDim;
std::string singularValueThreshold;
std::string mpsSample;
std::string seed; /**< User RNG seed for the executing simulator; empty means
non-deterministic (random) sampling. */
bool useDoublePrecision = false;

size_t maxSimulators = QC::QubitRegisterCalculator<>::
Expand Down
Loading
Loading