Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ stage_linux: &stage_linux
stage_osx: &stage_osx
<<: *stage_generic
os: osx
osx_image: xcode9.2
osx_image: xcode9.4
language: generic
python: 3.7
env:
Expand All @@ -90,14 +90,11 @@ stage_osx: &stage_osx
cd ../../..
python-build $PYTHON_VERSION ~/python-interpreters/$PYTHON_VERSION
fi
sudo pip2 install -U virtualenv pip setuptools
virtualenv --python ~/python-interpreters/$PYTHON_VERSION/bin/python venv
source venv/bin/activate
fi
before_script:
- |
if [ ! "$(ls -A .stestr)" ]; then
rm -rf .stestr
fi
# Build with Thrust OpenMP CPU backend
- python setup.py bdist_wheel -- -DAER_THRUST_BACKEND=OMP -- -j4
- pip install dist/qiskit_aer*whl
Expand Down
4 changes: 4 additions & 0 deletions cmake/compiler_utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ function(uncompress_muparsersx_lib)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64le")
set(MUPARSER_ARCH_POSTFIX ".ppc64le")
endif()
# Raspberry Pi (4)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "armv7l")
set(MUPARSER_ARCH_POSTFIX ".armv7l")
endif()
set(PLATFORM "linux")
endif()

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[build-system]
requires = ["setuptools", "wheel", "scikit-build", "cmake", "ninja", "pybind11>2.4"]
requires = ["setuptools", "wheel", "scikit-build", "cmake!=3.17.1,!=3.17.0", "ninja", "pybind11>2.4"]
2 changes: 1 addition & 1 deletion qiskit/providers/aer/VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.4.1
0.4.2
15 changes: 11 additions & 4 deletions qiskit/providers/aer/backends/qasm_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,9 @@ class QasmSimulator(AerBackend):
'coupling_map': None,
'basis_gates': [
'u1', 'u2', 'u3', 'cx', 'cz', 'id', 'x', 'y', 'z', 'h', 's', 'sdg',
't', 'tdg', 'swap', 'ccx', 'unitary', 'initialize', 'cu1', 'cu2',
'cu3', 'cswap', 'mcx', 'mcy', 'mcz', 'mcu1', 'mcu2', 'mcu3',
'mcswap', 'multiplexer', 'kraus', 'roerror'
't', 'tdg', 'swap', 'ccx', 'unitary', 'diagonal', 'initialize',
'cu1', 'cu2', 'cu3', 'cswap', 'mcx', 'mcy', 'mcz',
'mcu1', 'mcu2', 'mcu3', 'mcswap', 'multiplexer', 'kraus', 'roerror'
],
'gates': [{
'name': 'u1',
Expand Down Expand Up @@ -349,9 +349,16 @@ class QasmSimulator(AerBackend):
'name': 'unitary',
'parameters': ['matrix'],
'conditional': True,
'description': 'N-qubit arbitrary unitary gate. '
'description': 'N-qubit unitary gate. '
'The parameter is the N-qubit matrix to apply.',
'qasm_def': 'unitary(matrix) q1, q2,...'
}, {
'name': 'diagonal',
'parameters': ['diag_elements'],
'conditional': True,
'description': 'N-qubit diagonal unitary gate. The parameters are the'
' diagonal entries of the N-qubit matrix to apply.',
'qasm_def': 'TODO'
}, {
'name': 'initialize',
'parameters': ['vector'],
Expand Down
13 changes: 10 additions & 3 deletions qiskit/providers/aer/backends/statevector_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ class StatevectorSimulator(AerBackend):
'coupling_map': None,
'basis_gates': [
'u1', 'u2', 'u3', 'cx', 'cz', 'id', 'x', 'y', 'z', 'h', 's', 'sdg',
't', 'tdg', 'swap', 'ccx', 'unitary', 'initialize', 'cu1', 'cu2',
'cu3', 'cswap', 'mcx', 'mcy', 'mcz', 'mcu1', 'mcu2', 'mcu3',
'mcswap', 'multiplexer',
't', 'tdg', 'swap', 'ccx', 'unitary', 'diagonal', 'initialize',
'cu1', 'cu2', 'cu3', 'cswap', 'mcx', 'mcy', 'mcz',
'mcu1', 'mcu2', 'mcu3', 'mcswap', 'multiplexer',
],
'gates': [{
'name': 'u1',
Expand Down Expand Up @@ -207,6 +207,13 @@ class StatevectorSimulator(AerBackend):
'description': 'N-qubit arbitrary unitary gate. '
'The parameter is the N-qubit matrix to apply.',
'qasm_def': 'unitary(matrix) q1, q2,...'
}, {
'name': 'diagonal',
'parameters': ['diag_elements'],
'conditional': True,
'description': 'N-qubit diagonal unitary gate. The parameters are the'
' diagonal entries of the N-qubit matrix to apply.',
'qasm_def': 'TODO'
}, {
'name': 'initialize',
'parameters': ['vector'],
Expand Down
9 changes: 8 additions & 1 deletion qiskit/providers/aer/backends/unitary_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class UnitarySimulator(AerBackend):
'coupling_map': None,
'basis_gates': [
'u1', 'u2', 'u3', 'cx', 'cz', 'id', 'x', 'y', 'z', 'h', 's', 'sdg',
't', 'tdg', 'swap', 'ccx', 'unitary', 'cu1', 'cu2',
't', 'tdg', 'swap', 'ccx', 'unitary', 'diagonal', 'cu1', 'cu2',
'cu3', 'cswap', 'mcx', 'mcy', 'mcz', 'mcu1', 'mcu2', 'mcu3',
'mcswap', 'multiplexer',
],
Expand Down Expand Up @@ -214,6 +214,13 @@ class UnitarySimulator(AerBackend):
'description': 'N-qubit arbitrary unitary gate. '
'The parameter is the N-qubit matrix to apply.',
'qasm_def': 'unitary(matrix) q1, q2,...'
}, {
'name': 'diagonal',
'parameters': ['diag_elements'],
'conditional': True,
'description': 'N-qubit diagonal unitary gate. The parameters are the'
' diagonal entries of the N-qubit matrix to apply.',
'qasm_def': 'TODO'
}, {
'name': 'cu1',
'parameters': ['lam'],
Expand Down
56 changes: 29 additions & 27 deletions qiskit/providers/aer/noise/errors/quantum_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ class QuantumError:
"""

# pylint: disable=invalid-name
ATOL = ATOL_DEFAULT
RTOL = RTOL_DEFAULT
MAX_TOL = 1e-4
_ATOL_DEFAULT = ATOL_DEFAULT
_RTOL_DEFAULT = RTOL_DEFAULT
_MAX_TOL = 1e-4

def __init__(self,
noise_ops,
Expand Down Expand Up @@ -187,35 +187,37 @@ def copy(self):

@property
def atol(self):
"""The absolute tolerance parameter for float comparisons."""
return self.ATOL

@atol.setter
def atol(self, atol):
"""Set the absolute tolerance parameter for float comparisons."""
max_tol = self.MAX_TOL
if atol < 0:
raise NoiseError("Invalid atol: must be non-negative.")
if atol > max_tol:
raise NoiseError(
"Invalid atol: must be less than {}.".format(max_tol))
self.ATOL = atol
"""The default absolute tolerance parameter for float comparisons."""
return QuantumError._ATOL_DEFAULT

@property
def rtol(self):
"""The relative tolerance parameter for float comparisons."""
return self.RTOL

@rtol.setter
def rtol(self, rtol):
"""Set the relative tolerance parameter for float comparisons."""
max_tol = self.MAX_TOL
if rtol < 0:
raise NoiseError("Invalid rtol: must be non-negative.")
if rtol > max_tol:
return QuantumError._RTOL_DEFAULT

@classmethod
def set_atol(cls, value):
"""Set the class default absolute tolerance parameter for float comparisons."""
if value < 0:
raise NoiseError(
"Invalid atol ({}) must be non-negative.".format(value))
if value > cls._MAX_TOL:
raise NoiseError(
"Invalid atol ({}) must be less than {}.".format(
value, cls._MAX_TOL))
cls._ATOL_DEFAULT = value

@classmethod
def set_rtol(cls, value):
"""Set the class default relative tolerance parameter for float comparisons."""
if value < 0:
raise NoiseError(
"Invalid rtol ({}) must be non-negative.".format(value))
if value > cls._MAX_TOL:
raise NoiseError(
"Invalid rtol: must be less than {}.".format(max_tol))
self.RTOL = rtol
"Invalid rtol ({}) must be less than {}.".format(
value, cls._MAX_TOL))
cls._RTOL_DEFAULT = value

@property
def size(self):
Expand Down
56 changes: 29 additions & 27 deletions qiskit/providers/aer/noise/errors/readout_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ class ReadoutError:
Readout error class for Qiskit Aer noise model.
"""
# pylint: disable=invalid-name
ATOL = ATOL_DEFAULT
RTOL = RTOL_DEFAULT
MAX_TOL = 1e-4
_ATOL_DEFAULT = ATOL_DEFAULT
_RTOL_DEFAULT = RTOL_DEFAULT
_MAX_TOL = 1e-4

def __init__(self, probabilities, atol=ATOL_DEFAULT):
"""
Expand Down Expand Up @@ -112,35 +112,37 @@ def probabilities(self):

@property
def atol(self):
"""The absolute tolerance parameter for float comparisons."""
return self.ATOL

@atol.setter
def atol(self, atol):
"""Set the absolute tolerance parameter for float comparisons."""
max_tol = self.MAX_TOL
if atol < 0:
raise NoiseError("Invalid atol: must be non-negative.")
if atol > max_tol:
raise NoiseError(
"Invalid atol: must be less than {}.".format(max_tol))
self.ATOL = atol
"""The default absolute tolerance parameter for float comparisons."""
return ReadoutError._ATOL_DEFAULT

@property
def rtol(self):
"""The relative tolerance parameter for float comparisons."""
return self.RTOL

@rtol.setter
def rtol(self, rtol):
"""Set the relative tolerance parameter for float comparisons."""
max_tol = self.MAX_TOL
if rtol < 0:
raise NoiseError("Invalid rtol: must be non-negative.")
if rtol > max_tol:
return ReadoutError._RTOL_DEFAULT

@classmethod
def set_atol(cls, value):
"""Set the class default absolute tolerance parameter for float comparisons."""
if value < 0:
raise NoiseError(
"Invalid atol ({}) must be non-negative.".format(value))
if value > cls._MAX_TOL:
raise NoiseError(
"Invalid atol ({}) must be less than {}.".format(
value, cls._MAX_TOL))
cls._ATOL_DEFAULT = value

@classmethod
def set_rtol(cls, value):
"""Set the class default relative tolerance parameter for float comparisons."""
if value < 0:
raise NoiseError(
"Invalid rtol ({}) must be non-negative.".format(value))
if value > cls._MAX_TOL:
raise NoiseError(
"Invalid rtol: must be less than {}.".format(max_tol))
self.RTOL = rtol
"Invalid rtol ({}) must be less than {}.".format(
value, cls._MAX_TOL))
cls._RTOL_DEFAULT = value

def ideal(self):
"""Return True if current error object is an identity"""
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake
cmake!=3.17.1,!=3.17.0
scikit-build
cython
asv
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

setup_requirements = requirements + [
'scikit-build',
'cmake'
'cmake!=3.17,!=3.17.0'
]

if not hasattr(setuptools,
Expand Down
40 changes: 38 additions & 2 deletions src/framework/operations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "framework/types.hpp"
#include "framework/json.hpp"
#include "framework/utils.hpp"
#include "framework/linalg/almost_equal.hpp"

namespace AER {
namespace Operations {
Expand All @@ -36,7 +37,7 @@ enum class RegComparison {Equal, NotEqual, Less, LessEqual, Greater, GreaterEqua
// Enum class for operation types
enum class OpType {
gate, measure, reset, bfunc, barrier, snapshot,
matrix, multiplexer, kraus, superop, roerror, noise_switch, initialize
matrix, diagonal_matrix, multiplexer, kraus, superop, roerror, noise_switch, initialize
};

inline std::ostream& operator<<(std::ostream& stream, const OpType& type) {
Expand All @@ -60,7 +61,10 @@ inline std::ostream& operator<<(std::ostream& stream, const OpType& type) {
stream << "snapshot";
break;
case OpType::matrix:
stream << "matrix";
stream << "unitary";
break;
case OpType::diagonal_matrix:
stream << "diagonal";
break;
case OpType::multiplexer:
stream << "multiplexer";
Expand Down Expand Up @@ -561,6 +565,7 @@ Op json_to_op_snapshot_pauli(const json_t &js);

// Matrices
Op json_to_op_unitary(const json_t &js);
Op json_to_op_diagonal(const json_t &js);
Op json_to_op_superop(const json_t &js);
Op json_to_op_multiplexer(const json_t &js);
Op json_to_op_kraus(const json_t &js);
Expand Down Expand Up @@ -596,6 +601,8 @@ Op json_to_op(const json_t &js) {
// Arbitrary matrix gates
if (name == "unitary")
return json_to_op_unitary(js);
if (name == "diagonal" || name == "diag")
return json_to_op_diagonal(js);
if (name == "superop")
return json_to_op_superop(js);
// Snapshot
Expand Down Expand Up @@ -866,6 +873,35 @@ Op json_to_op_unitary(const json_t &js) {
return op;
}

Op json_to_op_diagonal(const json_t &js) {
Op op;
op.type = OpType::diagonal_matrix;
op.name = "diagonal";
JSON::get_value(op.qubits, "qubits", js);
JSON::get_value(op.params, "params", js);

// Validation
check_empty_qubits(op);
check_duplicate_qubits(op);
if (op.params.size() != 1ULL << op.qubits.size()) {
throw std::invalid_argument("\"diagonal\" matrix is wrong size.");
}
for (const auto val : op.params) {
if (!Linalg::almost_equal(std::abs(val), 1.0)) {
throw std::invalid_argument("\"diagonal\" matrix is not unitary.");
}
}

// Check for a label
std::string label;
JSON::get_value(label, "label", js);
op.string_params.push_back(label);

// Conditional
add_condtional(Allowed::Yes, op, js);
return op;
}

Op json_to_op_superop(const json_t &js) {
// Warning: we don't check superoperator is valid!
Op op;
Expand Down
Loading