1919#include < string>
2020#include < vector>
2121
22+ #include " circuit.h"
2223#include " gate.h"
2324#include " gate_appl.h"
2425#include " util.h"
@@ -174,6 +175,56 @@ struct QSimRunner final {
174175 static bool Run (const Parameter& param, const Factory& factory,
175176 const Circuit& circuit, State& state,
176177 std::vector<MeasurementResult>& measure_results) {
178+ StateSpace state_space = factory.CreateStateSpace ();
179+ Simulator simulator = factory.CreateSimulator ();
180+
181+ return Run (param, circuit, state_space, simulator, state, measure_results);
182+ }
183+
184+ /* *
185+ * Runs the given circuit and make the final state available to the caller,
186+ * discarding the result of any intermediate measurements in the circuit.
187+ * @param param Options for gate fusion, parallelism and logging.
188+ * @param factory Object to create simulators and state spaces.
189+ * @param circuit The circuit to be simulated.
190+ * @param state As an input parameter, this should contain the initial state
191+ * of the system. After a successful run, it will be populated with the
192+ * final state of the system.
193+ * @return True if the simulation completed successfully; false otherwise.
194+ */
195+ template <typename Circuit>
196+ static bool Run (const Parameter& param, const Factory& factory,
197+ const Circuit& circuit, State& state) {
198+ StateSpace state_space = factory.CreateStateSpace ();
199+ Simulator simulator = factory.CreateSimulator ();
200+
201+ std::vector<MeasurementResult> discarded_results;
202+
203+ return Run (
204+ param, circuit, state_space, simulator, state, discarded_results);
205+ }
206+
207+ /* *
208+ * Runs the given circuit and make the final state available to the caller,
209+ * recording the result of any intermediate measurements in the circuit.
210+ * @param param Options for gate fusion, parallelism and logging.
211+ * @param circuit The circuit to be simulated.
212+ * @param state_space StateSpace object required to perform measurements.
213+ * @param simulator Simulator object. Provides specific implementations for
214+ * applying gates.
215+ * @param state As an input parameter, this should contain the initial state
216+ * of the system. After a successful run, it will be populated with the
217+ * final state of the system.
218+ * @param measure_results As an input parameter, this should be empty.
219+ * After a successful run, this will contain all measurements results from
220+ * the run, ordered by time and qubit index.
221+ * @return True if the simulation completed successfully; false otherwise.
222+ */
223+ template <typename Circuit>
224+ static bool Run (const Parameter& param, const Circuit& circuit,
225+ const StateSpace& state_space, const Simulator& simulator,
226+ State& state,
227+ std::vector<MeasurementResult>& measure_results) {
177228 double t0 = 0.0 ;
178229 double t1 = 0.0 ;
179230
@@ -183,19 +234,18 @@ struct QSimRunner final {
183234
184235 RGen rgen (param.seed );
185236
186- StateSpace state_space = factory.CreateStateSpace ();
187- Simulator simulator = factory.CreateSimulator ();
188-
189237 if (param.verbosity > 1 ) {
190238 t1 = GetTime ();
191239 IO::messagef (" init time is %g seconds.\n " , t1 - t0);
192240 t0 = GetTime ();
193241 }
194242
195- auto fused_gates = Fuser::FuseGates (param, circuit. num_qubits ,
196- circuit. gates );
243+ using Gates = detail::Gates<Circuit>;
244+ const auto & gates = Gates::get ( circuit);
197245
198- if (fused_gates.size () == 0 && circuit.gates .size () > 0 ) {
246+ auto fused_gates = Fuser::FuseGates (param, state.num_qubits (), gates);
247+
248+ if (fused_gates.size () == 0 && gates.size () > 0 ) {
199249 return false ;
200250 }
201251
@@ -242,18 +292,23 @@ struct QSimRunner final {
242292 * Runs the given circuit and make the final state available to the caller,
243293 * discarding the result of any intermediate measurements in the circuit.
244294 * @param param Options for gate fusion, parallelism and logging.
245- * @param factory Object to create simulators and state spaces.
246295 * @param circuit The circuit to be simulated.
296+ * @param state_space StateSpace object required to perform measurements.
297+ * @param simulator Simulator object. Provides specific implementations for
298+ * applying gates.
247299 * @param state As an input parameter, this should contain the initial state
248300 * of the system. After a successful run, it will be populated with the
249301 * final state of the system.
250302 * @return True if the simulation completed successfully; false otherwise.
251303 */
252304 template <typename Circuit>
253- static bool Run (const Parameter& param, const Factory& factory,
254- const Circuit& circuit, State& state) {
305+ static bool Run (const Parameter& param, const Circuit& circuit,
306+ const StateSpace& state_space, const Simulator& simulator,
307+ State& state) {
255308 std::vector<MeasurementResult> discarded_results;
256- return Run (param, factory, circuit, state, discarded_results);
309+
310+ return Run (
311+ param, circuit, state_space, simulator, state, discarded_results);
257312 }
258313};
259314
0 commit comments