Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into readout_sampling
Browse files Browse the repository at this point in the history
  • Loading branch information
hhorii committed Aug 1, 2019
2 parents 8079e41 + d58dae5 commit da06d65
Show file tree
Hide file tree
Showing 52 changed files with 3,451 additions and 1,556 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ Added
- Added support for conditional unitary, kraus, superop qobj instructions (\# 291)
- Add "validation_threshold" config parameter to Aer backends (\# 290)

- Noise model inserter module

Changed
-------

Expand All @@ -37,6 +39,8 @@ Fixed
-----
- Bug in handling parallelization in matrix_product_state.cpp (PR \#292)

- Added support for multiplication by coeff in tensor_network_state expectation value snapshots (PR \#294)


[0.2.3](https://github.com/Qiskit/qiskit-aer/compare/0.2.2...0.2.3) - 2019-07-11
===============================================================================
Expand Down
11 changes: 5 additions & 6 deletions contrib/standalone/qasm_simulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,14 @@ int main(int argc, char **argv) {
// Execute simulation
try {

// Initialize simulator
AER::Simulator::QasmController sim;

// Check for config
json_t config_all = qobj["config"];
// Check for command line config
// and if present add to qobj config
json_t& config_all = qobj["config"];
if (!config.empty())
config_all.update(config.begin(), config.end());

sim.set_config(config_all);
// Initialize simulator
AER::Simulator::QasmController sim;
auto result = sim.execute(qobj);
out << result.dump(4) << std::endl;

Expand Down
27 changes: 0 additions & 27 deletions qiskit/providers/aer/backends/qasm_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from .aerbackend import AerBackend
# pylint: disable=import-error
from .qasm_controller_wrapper import qasm_controller_execute
from ..aererror import AerError
from ..version import __version__

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -230,29 +229,3 @@ def _validate(self, qobj, backend_options, noise_model):
logger.warning(
'No measurements in circuit "%s": '
'count data will return all zeros.', name)
# Check qubits for statevector simulation
if not clifford and method != "extended_stabilizer":
n_qubits = experiment.config.n_qubits
max_qubits = self.configuration().n_qubits
if n_qubits > max_qubits:
system_memory = int(local_hardware_info()['memory'])
err_string = ('Number of qubits ({}) is greater than '
'maximum ({}) for "{}" (method=statevector) '
'with {} GB system memory')
err_string = err_string.format(n_qubits, max_qubits,
self.name(), system_memory)
if method != "automatic":
raise AerError(err_string + '.')

if n_qubits > 63:
raise AerError('{}, and has too many qubits to fall '
'back to the extended_stabilizer '
'method.'.format(err_string))
if not ch_supported:
raise AerError('{}, and contains instructions '
'not supported by the extended_etabilizer '
'method.'.format(err_string))
logger.info(
'The QasmSimulator will automatically '
'switch to the Extended Stabilizer backend, based on '
'the memory requirements.')
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ cdef extern from "simulators/qasm/qasm_controller.hpp" namespace "AER::Simulator
cdef cppclass QasmController:
QasmController() except +

cdef extern from "base/controller.hpp" namespace "AER":
cdef extern from "simulators/controller_execute.hpp" namespace "AER":
cdef string controller_execute[QasmController](string &qobj) except +


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ cdef extern from "simulators/statevector/statevector_controller.hpp" namespace "
cdef cppclass StatevectorController:
StatevectorController() except +

cdef extern from "base/controller.hpp" namespace "AER":
cdef extern from "simulators/controller_execute.hpp" namespace "AER":
cdef string controller_execute[StatevectorController](string &qobj) except +


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ cdef extern from "simulators/unitary/unitary_controller.hpp" namespace "AER::Sim
cdef cppclass UnitaryController:
UnitaryController() except +

cdef extern from "base/controller.hpp" namespace "AER":
cdef extern from "simulators/controller_execute.hpp" namespace "AER":
cdef string controller_execute[UnitaryController](string &qobj) except +


Expand Down
1 change: 1 addition & 0 deletions qiskit/providers/aer/noise/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@
from .noise_transformation import NoiseTransformer
from .noise_transformation import approximate_quantum_error
from .noise_transformation import approximate_noise_model
from .noise_model_inserter import insert_noise
51 changes: 51 additions & 0 deletions qiskit/providers/aer/noise/utils/noise_model_inserter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2019.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.
"""
Noise model inserter module
The goal of this module is to add QuantumError gates (Kraus gates) to a circuit
based on a given noise model. The resulting circuit cannot be ran on a quantum computer
but can be handled correctly by simulators
"""
import qiskit.compiler


def insert_noise(circuits, noise_model, transpile=False):
"""
This function gets a circuit and a noise model and returns a new circuit
with the noises from the noise model inserted as Kraus gates in the new circuit
Args:
circuits (QuantumCircuit or list[QuantumCircuit]): The circuits to add noises to
noise_model (NoiseModel): The noise model containing the errors to add
transpile (Boolean): Should the circuit be transpiled into the noise model basis gates
Returns:
QuantumCircuit: The new circuit with the added Kraus gates
"""
is_circuits_list = isinstance(circuits, (list, tuple))
circuits = circuits if is_circuits_list else [circuits]
result_circuits = []
errors = noise_model._default_quantum_errors.items()
error_dict = {name: qubit_dict for (name, qubit_dict) in errors}
for circuit in circuits:
if transpile:
transpiled_circuit = qiskit.compiler.transpile(circuit,
basis_gates=noise_model.basis_gates)
else:
transpiled_circuit = circuit
result_circuit = circuit.copy(name=transpiled_circuit.name + '_with_noise')
result_circuit.data = []
for inst, qargs, cargs in transpiled_circuit.data:
result_circuit.data.append((inst, qargs, cargs))
if inst.name in error_dict.keys():
error = error_dict[inst.name]
result_circuit.append(error.to_instruction(), qargs)
result_circuits.append(result_circuit)
return result_circuits if is_circuits_list else result_circuits[0]
Loading

0 comments on commit da06d65

Please sign in to comment.