@@ -47,9 +47,18 @@ std::shared_ptr<BasicQuantumState> expand_wfn_helper(std::shared_ptr<BasicQuantu
4747 return (nqubits > max_num_bits / 2 ) ? std::shared_ptr<BasicQuantumState>(new QuantumState<max_num_bits>(old_sim)): expand_wfn_helper<max_num_bits / 2 >(old_sim, nqubits);
4848}
4949
50+ // Sparse simulator only stores non-zero coefficients of the quantum state.
51+ // It has good performance only when the number of non-zero coefficients is low.
52+ // If the number of non-zero coefficients is low, the number of qubits may be fairly large.
53+ // Sparse simulator employs hashtable structure (by Malte Skarupke) to store non-zero coefficients.
54+ // Keys are basis vectors represented by std::bitset<>.
55+ // Values are non-zero amplitudes represented by std::complex<RealType>.
56+ // Zero amplitudes are simply not stored.
57+ // Hashtable is reallocated and reconstructed on almost every gate.
58+ // Reallocation is saved for some gates that can be performed in one round.
5059class SparseSimulator
5160{
52- public:
61+ public:
5362
5463 std::set<std::string> operations_done;
5564
@@ -584,13 +593,16 @@ class SparseSimulator
584593 // as a phase/permutation gate
585594 // This means if an assert fails, it will fail
586595 // at some future point, not at the point of failure
587- #if NDEBUG
596+ #if defined( NDEBUG)
588597 if (isAllZ) {
589598 _queued_operations.push_back (operation (OP::Assert, qubits, result));
599+ // In release mode we queue Z assertion and return.
590600 return ;
591601 }
592602 #endif
593- // X or Y assertions require execution
603+ // X or Y assertions require immediate execution.
604+ // We also execute Z assertion immediately in debug mode
605+ // to provide feedback at the point of failure.
594606 _execute_queued_ops (qubits, OP::PermuteLarge);
595607 _quantum_state->Assert (axes, qubits, result);
596608 }
0 commit comments