Skip to content

Commit

Permalink
Merge branch 'main' into PR-prob-meas
Browse files Browse the repository at this point in the history
  • Loading branch information
Patataman authored Aug 26, 2023
2 parents 4bf2f06 + ada56a3 commit 4f8c22a
Show file tree
Hide file tree
Showing 72 changed files with 11,208 additions and 6,652 deletions.
18 changes: 13 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,15 @@
cmake_minimum_required(VERSION 3.8 FATAL_ERROR)
file(STRINGS "qiskit_aer/VERSION.txt" VERSION_NUM)

# Add CUDA to the project if needed.
set(EXTRA_LANGUAGES "")
if(AER_THRUST_BACKEND STREQUAL "CUDA")
list(APPEND EXTRA_LANGUAGES CUDA)
endif()

include(CheckLanguage)
project(qasm_simulator VERSION ${VERSION_NUM} LANGUAGES CXX C)
project(qasm_simulator VERSION ${VERSION_NUM} LANGUAGES CXX C ${EXTRA_LANGUAGES} )


list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_SOURCE_DIR}/cmake)
Expand Down Expand Up @@ -284,7 +291,7 @@ if(AER_THRUST_SUPPORTED)
set(CMAKE_CUDA_RUNTIME_LIBRARY None)


set(CUDA_NVCC_FLAGS "${AER_CUDA_ARCH_FLAGS_EXPAND} -DAER_THRUST_CUDA -I${AER_SIMULATOR_CPP_SRC_DIR} -isystem ${AER_SIMULATOR_CPP_SRC_DIR}/third-party/headers -use_fast_math --expt-extended-lambda")
set(CUDA_NVCC_FLAGS "${AER_CUDA_ARCH_FLAGS_EXPAND} -DAER_THRUST_GPU -DAER_THRUST_CUDA -I${AER_SIMULATOR_CPP_SRC_DIR} -isystem ${AER_SIMULATOR_CPP_SRC_DIR}/third-party/headers -use_fast_math --expt-extended-lambda")
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -I${PYTHON_SITE_PATH}/cuquantum/include")
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -I${PYTHON_SITE_PATH}/cutensor/include")
set(THRUST_DEPENDANT_LIBS "${THRUST_DEPENDANT_LIBS} -Wl,--disable-new-dtags")
Expand All @@ -311,7 +318,7 @@ if(AER_THRUST_SUPPORTED)
string(STRIP ${CUDA_NVCC_FLAGS} CUDA_NVCC_FLAGS)
string(STRIP ${THRUST_DEPENDANT_LIBS} THRUST_DEPENDANT_LIBS)
else()
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} ${AER_CUDA_ARCH_FLAGS_EXPAND} -DAER_THRUST_CUDA -I${AER_SIMULATOR_CPP_SRC_DIR} -isystem ${AER_SIMULATOR_CPP_SRC_DIR}/third-party/headers -use_fast_math --expt-extended-lambda")
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} ${AER_CUDA_ARCH_FLAGS_EXPAND} -DAER_THRUST_GPU -DAER_THRUST_CUDA -I${AER_SIMULATOR_CPP_SRC_DIR} -isystem ${AER_SIMULATOR_CPP_SRC_DIR}/third-party/headers -use_fast_math --expt-extended-lambda")

set(AER_COMPILER_DEFINITIONS ${AER_COMPILER_DEFINITIONS} THRUST_DEVICE_SYSTEM=THRUST_DEVICE_SYSTEM_CUDA)
set(THRUST_DEPENDANT_LIBS "-L${CUDA_TOOLKIT_ROOT_DIR}/lib64")
Expand Down Expand Up @@ -455,7 +462,6 @@ else() # Standalone build
LINK_FLAGS ${AER_LINKER_FLAGS}
RUNTIME_OUTPUT_DIRECTORY_DEBUG Debug
RUNTIME_OUTPUT_DIRECTORY_RELEASE Release)
enable_language(CUDA)
endfunction()

function(build_cpu target src_file is_exec)
Expand Down Expand Up @@ -519,7 +525,9 @@ else() # Standalone build
if(BUILD_TESTS AND NOT AER_MPI)
add_executable(test_libaer "${PROJECT_SOURCE_DIR}/test/runtime/runtime_sample.c")
target_include_directories(test_libaer PUBLIC "${PROJECT_SOURCE_DIR}/contrib/runtime/")
set_target_properties(test_libaer PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE bin)
# AER_LINKER_FLAGS carry eventual OpenMP linking flags.
set_target_properties(test_libaer PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE bin
LINK_FLAGS ${AER_LINKER_FLAGS})
target_link_libraries(test_libaer PRIVATE ${AER_LIBRARIES})
target_link_libraries(test_libaer PRIVATE aer)
add_test(NAME aer_runtime_test COMMAND bin/test_libaer)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Now you're set up and ready to check out some of the other examples from our
## Authors and Citation

Qiskit Aer is the work of [many people](https://github.com/Qiskit/qiskit-aer/graphs/contributors) who contribute
to the project at different levels. If you use Qiskit, please cite as per the included [BibTeX file](https://github.com/Qiskit/qiskit/blob/master/Qiskit.bib).
to the project at different levels. If you use Qiskit, please cite as per the included [BibTeX file](https://github.com/Qiskit/qiskit-terra/blob/main/CITATION.bib).

## License

Expand Down
3 changes: 3 additions & 0 deletions qiskit_aer/backends/aer_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,8 @@ def compile_circuit(circuits, basis_gates=None, optypes=None):
"chunk_swap_buffer_qubits": (int, np.integer),
"batched_shots_gpu": (bool, np.bool_),
"batched_shots_gpu_max_qubits": (int, np.integer),
"shot_branching_enable": (bool, np.bool_),
"shot_branching_sampling_enable": (bool, np.bool_),
"num_threads_per_device": (int, np.integer),
"statevector_parallel_threshold": (int, np.integer),
"statevector_sample_measure_opt": (int, np.integer),
Expand All @@ -488,6 +490,7 @@ def compile_circuit(circuits, basis_gates=None, optypes=None):
"use_cuTensorNet_autotuning": (bool, np.bool_),
"parameterizations": (list),
"fusion_parallelization_threshold": (int, np.integer),
"target_gpus": (list),
}


Expand Down
31 changes: 31 additions & 0 deletions qiskit_aer/backends/aer_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ class AerSimulator(AerBackend):
If AerSimulator is built with cuStateVec support, cuStateVec APIs are enabled
by setting ``cuStateVec_enable=True``.
* ``target_gpus`` (list): List of GPU's IDs starting from 0 sets
the target GPUs used for the simulation.
If this option is not specified, all the available GPUs are used for
chunks/shots distribution.
**Additional Backend Options**
Expand Down Expand Up @@ -287,6 +291,30 @@ class AerSimulator(AerBackend):
threads per GPU. This parameter is used to optimize Pauli noise
simulation with multiple-GPUs (Default: 1).
* ``shot_branching_enable`` (bool): This option enables/disables
applying shot-branching technique to speed up multi-shots of dynamic
circutis simulations or circuits simulations with noise models.
(Default: False).
Starting from single state shared with multiple shots and
state will be branched dynamically at runtime.
This option can decrease runs of shots if there will be less branches
than number of total shots.
This option is available for ``"statevector"``, ``"density_matrix"``
and ``"tensor_network"``.
* ``shot_branching_sampling_enable`` (bool): This option enables/disables
applying sampling measure if the input circuit has all the measure
operations at the end of the circuit. (Default: False).
Because measure operation branches state into 2 states, it is not
efficient to apply branching for measure.
Sampling measure improves speed to get counts for multiple-shots
sharing the same state.
Note that the counts obtained by sampling measure may not be as same as
the counts calculated by multiple measure operations,
becuase sampling measure takes only one randome number per shot.
This option is available for ``"statevector"``, ``"density_matrix"``
and ``"tensor_network"``.
* ``accept_distributed_results`` (bool): This option enables storing
results independently in each process (Default: None).
Expand Down Expand Up @@ -709,6 +737,9 @@ def _default_options(cls):
batched_shots_gpu=False,
batched_shots_gpu_max_qubits=16,
num_threads_per_device=1,
# multi-shot branching
shot_branching_enable=False,
shot_branching_sampling_enable=False,
# statevector options
statevector_parallel_threshold=14,
statevector_sample_measure_opt=10,
Expand Down
1 change: 1 addition & 0 deletions qiskit_aer/backends/backend_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@
"swap",
"delay",
"pauli",
"ecr",
]
),
"extended_stabilizer": sorted(
Expand Down
1 change: 1 addition & 0 deletions qiskit_aer/backends/qasm_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,7 @@ def _method_basis_gates(self):
"swap",
"delay",
"pauli",
"ecr",
]
)
if method == "extended_stabilizer":
Expand Down
20 changes: 17 additions & 3 deletions qiskit_aer/backends/wrappers/aer_controller_binding.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ void bind_aer_controller(MODULE m) {
[](Config &config, uint_t val) {
config.num_threads_per_device.value(val);
});
// # multi-shot branching
aer_config.def_readwrite("shot_branching_enable",
&Config::shot_branching_enable);
aer_config.def_readwrite("shot_branching_sampling_enable",
&Config::shot_branching_sampling_enable);
// # statevector options
aer_config.def_readwrite("statevector_parallel_threshold",
&Config::statevector_parallel_threshold);
Expand Down Expand Up @@ -403,6 +408,10 @@ void bind_aer_controller(MODULE m) {
[](Config &config, uint_t val) {
config.extended_stabilizer_norm_estimation_default_samples.value(val);
});
aer_config.def_property(
"target_gpus",
[](const Config &config) { return config.target_gpus.val; },
[](Config &config, reg_t val) { config.target_gpus.value(val); });

aer_config.def(py::pickle(
[](const AER::Config &config) {
Expand Down Expand Up @@ -488,12 +497,14 @@ void bind_aer_controller(MODULE m) {
write_value(77, config.unitary_parallel_threshold),
write_value(78, config.memory_blocking_bits),
write_value(
79,
config.extended_stabilizer_norm_estimation_default_samples));
79, config.extended_stabilizer_norm_estimation_default_samples),
write_value(80, config.shot_branching_enable),
write_value(81, config.shot_branching_sampling_enable),
write_value(82, config.target_gpus));
},
[](py::tuple t) {
AER::Config config;
if (t.size() != 79)
if (t.size() != 82)
throw std::runtime_error("Invalid serialization format.");

read_value(t, 0, config.shots);
Expand Down Expand Up @@ -580,6 +591,9 @@ void bind_aer_controller(MODULE m) {
read_value(t, 78, config.memory_blocking_bits);
read_value(t, 79,
config.extended_stabilizer_norm_estimation_default_samples);
read_value(t, 80, config.shot_branching_enable);
read_value(t, 81, config.shot_branching_sampling_enable);
read_value(t, 82, config.target_gpus);
return config;
}));
}
Expand Down
4 changes: 3 additions & 1 deletion qiskit_aer/noise/device/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,10 @@ def _device_thermal_relaxation_error(

def _truncate_t2_value(t1, t2):
"""Return t2 value truncated to 2 * t1 (for t2 > 2 * t1)"""
if t1 is None or t2 is None:
if t1 is None:
return t2
elif t2 is None:
return 2 * t1
return min(t2, 2 * t1)


Expand Down
2 changes: 1 addition & 1 deletion qiskit_aer/quantum_info/states/aer_densitymatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def from_label(cls, label):

@staticmethod
def from_int(i, dims):
size = np.product(dims)
size = np.prod(dims)
state = np.zeros((size, size), dtype=complex)
state[i, i] = 1.0
return AerDensityMatrix(state, dims=dims)
Expand Down
2 changes: 1 addition & 1 deletion qiskit_aer/quantum_info/states/aer_statevector.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def from_label(cls, label):

@staticmethod
def from_int(i, dims):
size = np.product(dims)
size = np.prod(dims)
state = np.zeros(size, dtype=complex)
state[i] = 1.0
return AerStatevector(state, dims=dims)
30 changes: 30 additions & 0 deletions releasenotes/notes/add_executor-a03f2d23cf6f4ca9.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
features:
- |
This release restructures ``State`` classes.
Adding circuit executor classes that runs a circuit and manages multiple
states for multi-shots simulations or multi-chunk simulations for large
number of qubits.
Previously ``StateChunk`` class manages multiple chunks for multi-shots or
multi-chunk simulations but now ``State`` class only has one state
and all the parallelization codes are moved to ``Executor`` classes.
Now all ``State`` classes are independent from parallelization.
Also some of the functions in ``Aer::Controller`` class are moved to
``CircuitExecutor::Executor`` class.
- |
Shot-branching technique that accelerates dynamic circuits simulations
is implemented with restructured ``Executor`` classes.
Shot-branching is currently applicable to statevector density_matrix
and tensor_network methods.
Shot-branching provides dynamic distribution of multi-shots
by branching states when applying dynamic operations
(measure, reset, initialize, noises)
By default ``shot_branching_enable`` is disabled.
And by setting ``shot_branching_sampling_enable``, final measures will be
done by sampling measure that will speed up to get counts for multiple shots
sharing the same state.
- |
A new option ``target_gpus`` is added to select GPUs used for the
simulation. A list of target GPU's ID is passed for example
``target_gpus=[0, 2]`` select 2 GPUs to be used.
Without this option, all the available GPUs are used.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
fixes:
- |
``measure`` in libaer.so wrongly read classical memory by assuming
opposite ordering of its indices. This fix corrects the assumed ordering.
This change affects only libaer.so and not python applications.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
features:
- |
Enable 2-qubit gate ECR for aer_stabilizer_simulator. Refer to
`#1883 <https://github.com/Qiskit/qiskit-aer/issues/1883` for more
details.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
fixes:
- |
Fixed a bug where :meth:`~.NoiseModel.from_backend` raises an error when
a backend reports no T2 value (while it reports T1 value) for a qubit,
which was an oversight in the previous fix on None handling:
`#1818 <https://github.com/Qiskit/qiskit-aer/issues/1818>`__.
Fixed `#1896 <https://github.com/Qiskit/qiskit-aer/issues/1896>`__.
Loading

0 comments on commit 4f8c22a

Please sign in to comment.