diff --git a/qiskit_aer/backends/aer_compiler.py b/qiskit_aer/backends/aer_compiler.py index cb17330123..5d04ee3574 100644 --- a/qiskit_aer/backends/aer_compiler.py +++ b/qiskit_aer/backends/aer_compiler.py @@ -337,17 +337,13 @@ def compile_circuit(circuits, basis_gates=None, optypes=None): def generate_aer_config( - circuits: List[QuantumCircuit], - backend_options: Options, - default_options: Options = None, - **run_options, + circuits: List[QuantumCircuit], backend_options: Options, **run_options ) -> AerConfig: """generates a configuration to run simulation. Args: circuits: circuit(s) to be converted backend_options: backend options - default_options: default options run_options: run options Returns: @@ -355,7 +351,9 @@ def generate_aer_config( """ num_qubits = max(circuit.num_qubits for circuit in circuits) memory_slots = max(circuit.num_clbits for circuit in circuits) - default_options = default_options if default_options is not None else {} + from . import AerSimulator # prevent circular import + + default_options = AerSimulator._default_options() config = AerConfig() config.memory_slots = memory_slots diff --git a/qiskit_aer/backends/aer_simulator.py b/qiskit_aer/backends/aer_simulator.py index db601d6546..aeb83dec7f 100644 --- a/qiskit_aer/backends/aer_simulator.py +++ b/qiskit_aer/backends/aer_simulator.py @@ -668,6 +668,7 @@ def __init__(self, configuration=None, properties=None, provider=None, **backend @classmethod def _default_options(cls): + # Must be equivalent to AER::Config::__AER_SIMULATOR_DEFAULTS return Options( # Global options shots=1024, diff --git a/qiskit_aer/backends/aerbackend.py b/qiskit_aer/backends/aerbackend.py index 34163413bc..4ff9a3d6ed 100644 --- a/qiskit_aer/backends/aerbackend.py +++ b/qiskit_aer/backends/aerbackend.py @@ -79,9 +79,6 @@ def __init__( if backend_options is not None: self.set_options(**backend_options) - # Set default option to identify diffs - self._system_default_options = self._default_options() - def _convert_circuit_binds(self, circuit, binds): parameterizations = [] for index, instruction in enumerate(circuit.data): @@ -233,9 +230,7 @@ def _run_circuits(self, circuits, parameter_binds, **run_options): circuits, noise_model = self._compile(circuits, **run_options) if parameter_binds: run_options["parameterizations"] = self._convert_binds(circuits, parameter_binds) - config = generate_aer_config( - circuits, self.options, self._system_default_options, **run_options - ) + config = generate_aer_config(circuits, self.options, **run_options) # Submit job job_id = str(uuid.uuid4()) diff --git a/src/framework/config.hpp b/src/framework/config.hpp index 0fd48c9889..cfea766878 100644 --- a/src/framework/config.hpp +++ b/src/framework/config.hpp @@ -70,6 +70,8 @@ struct Config { using pos_t = std::pair; using exp_params_t = std::vector>>; + const static json_t __AER_SIMULATOR_DEFAULTS; + uint_t shots = 1024; std::string method = "automatic"; std::string device = "CPU"; @@ -91,19 +93,24 @@ struct Config { json_t options; + bool _check_option(const json_t &js, const std::string &key) const { + return js.find(key) != js.end() && !js[key].is_null(); + } + bool check_option(const std::string &key) const { // returns false if the value is 'null' - if (options.find(key) != options.end() && !options[key].is_null()) + if (_check_option(options, key) || + _check_option(__AER_SIMULATOR_DEFAULTS, key)) return true; else return false; } template - bool get_option(T &var, const std::string &key) const { - if (check_option(key)) { + bool _get_option(const json_t &js, T &var, const std::string &key) const { + if (_check_option(js, key)) { try { - var = options[key].get(); + var = js[key].get(); return true; } catch (std::exception &e) { throw std::invalid_argument( @@ -114,6 +121,12 @@ struct Config { } } + template + bool get_option(T &var, const std::string &key) const { + return _get_option(options, var, key) || + _get_option(__AER_SIMULATOR_DEFAULTS, var, key); + } + void clear() { shots = 1024; method = "automatic"; @@ -164,6 +177,65 @@ struct Config { } }; +const json_t Config::__AER_SIMULATOR_DEFAULTS = { + {"shots", 1024}, + {"method", "automatic"}, + {"device", "CPU"}, + {"precision", "double"}, + {"executor", nullptr}, + {"max_job_size", nullptr}, + {"max_shot_size", nullptr}, + {"enable_truncation", true}, + {"zero_threshold", 1e-10}, + {"validation_threshold", nullptr}, + {"max_parallel_threads", nullptr}, + {"max_parallel_experiments", nullptr}, + {"max_parallel_shots", nullptr}, + {"max_memory_mb", nullptr}, + {"fusion_enable", true}, + {"fusion_verbose", false}, + {"fusion_max_qubit", nullptr}, + {"fusion_threshold", nullptr}, + {"accept_distributed_results", nullptr}, + {"memory", nullptr}, + {"noise_model", nullptr}, + {"seed_simulator", nullptr}, + + {"cuStateVec_enable", false}, + + {"blocking_qubits", nullptr}, + {"blocking_enable", false}, + {"chunk_swap_buffer_qubits", nullptr}, + + {"batched_shots_gpu", false}, + {"batched_shots_gpu_max_qubits", 16}, + {"num_threads_per_device", 1}, + + {"statevector_parallel_threshold", 14}, + {"statevector_sample_measure_opt", 10}, + + {"stabilizer_max_snapshot_probabilities", 32}, + + {"extended_stabilizer_sampling_method", "resampled_metropolis"}, + {"extended_stabilizer_metropolis_mixing_time", 5000}, + {"extended_stabilizer_approximation_error", 0.05}, + {"extended_stabilizer_norm_estimation_samples", 100}, + {"extended_stabilizer_norm_estimation_repetitions", 3}, + {"extended_stabilizer_parallel_threshold", 100}, + {"extended_stabilizer_probabilities_snapshot_samples", 3000}, + + {"matrix_product_state_truncation_threshold", 1e-16}, + {"matrix_product_state_max_bond_dimension", nullptr}, + {"mps_sample_measure_algorithm", "mps_heuristic"}, + {"mps_log_data", false}, + {"mps_swap_direction", "mps_swap_left"}, + {"chop_threshold", 1e-8}, + {"mps_parallel_threshold", 14}, + {"mps_omp_threads", 1}, + + {"tensor_network_num_sampling_qubits", 10}, + {"use_cuTensorNet_autotuning", false}}; + // Json conversion function inline void from_json(const json_t &js, Config &config) { get_value(config.shots, "shots", js); diff --git a/src/simulators/statevector/statevector_state.hpp b/src/simulators/statevector/statevector_state.hpp index d69b039c6b..4c4258345c 100644 --- a/src/simulators/statevector/statevector_state.hpp +++ b/src/simulators/statevector/statevector_state.hpp @@ -560,7 +560,7 @@ void State::set_config(const Config &config) { // Set the sample measure indexing size int index_size; - if (config.get_option(index_size, "statevector_parallel_threshold")) { + if (config.get_option(index_size, "statevector_sample_measure_opt")) { for (int_t i = 0; i < BaseState::qregs_.size(); i++) BaseState::qregs_[i].set_sample_measure_index_size(index_size); }