Skip to content

Commit

Permalink
support single precision in state vector simulator (Qiskit#286)
Browse files Browse the repository at this point in the history
  • Loading branch information
hhorii authored and chriseclectic committed Jul 25, 2019
1 parent a98e58a commit 9c7ae8f
Show file tree
Hide file tree
Showing 5 changed files with 248 additions and 198 deletions.
43 changes: 36 additions & 7 deletions src/simulators/qasm/qasm_controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ class QasmController : public Base::Controller {
tensor_network
};

// Simulation precision
enum class Precision {
double_precision,
single_precision
};

//-----------------------------------------------------------------------
// Base class abstract method override
//-----------------------------------------------------------------------
Expand Down Expand Up @@ -233,9 +239,12 @@ class QasmController : public Base::Controller {
//-----------------------------------------------------------------------
size_t required_memory_mb(const Circuit& circ) const override;

// Simulation method
// Simulation method
Method simulation_method_ = Method::automatic;

// Simulation precision
Precision simulation_precision_ = Precision::double_precision;

// Qubit threshold for running circuit optimizations
uint_t circuit_opt_ideal_threshold_ = 5;
uint_t circuit_opt_noise_threshold_ = 12;
Expand Down Expand Up @@ -293,6 +302,16 @@ void QasmController::set_config(const json_t &config) {
}
}

std::string precision;
if (JSON::get_value(precision, "precision", config)) {
if (precision == "double") {
simulation_precision_ = Precision::double_precision;
} else if (precision == "single") {
simulation_precision_ = Precision::single_precision;
}
}


// Check for circuit optimization threshold
JSON::get_value(circuit_opt_ideal_threshold_,
"optimize_ideal_threshold", config);
Expand Down Expand Up @@ -343,12 +362,22 @@ OutputData QasmController::run_circuit(const Circuit &circ,

switch (simulation_method(circ)) {
case Method::statevector:
// Statevector simulation
return run_circuit_helper<Statevector::State<>>(
circ,
shots,
rng_seed,
initial_statevector_); // allow custom initial state

if (simulation_precision_ == Precision::double_precision) {
// Statevector simulation
return run_circuit_helper<Statevector::State<QV::QubitVector<double>>>(
circ,
shots,
rng_seed,
initial_statevector_); // allow custom initial state
} else {
// Statevector simulation
return run_circuit_helper<Statevector::State<QV::QubitVector<float>>>(
circ,
shots,
rng_seed,
initial_statevector_); // allow custom initial state
}
case Method::stabilizer:
// Stabilizer simulation
// TODO: Stabilizer doesn't yet support custom state initialization
Expand Down
Loading

0 comments on commit 9c7ae8f

Please sign in to comment.