Skip to content

Commit

Permalink
Merge pull request #269 from atilag/stable-0.4.7-fix-cpp-sim
Browse files Browse the repository at this point in the history
  • Loading branch information
atilag authored Jan 26, 2018
2 parents 87a995b + 77f3a22 commit d8318b4
Show file tree
Hide file tree
Showing 11 changed files with 317 additions and 174 deletions.
2 changes: 2 additions & 0 deletions pypi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ echo -n "Clobbering build..."
rm -rf qiskit.egg-info build dist
echo -e "[OK]"

export USER_FLAGS="-static"
echo "Setting USER_FLAGS env variable for C++ compilation to: $USER_FLAGS"
echo -n "Building distributable package..."
# Let's build the wheel package
python setup.py sdist bdist_wheel -p manylinux1_x86_64 &>> $self.log
Expand Down
2 changes: 1 addition & 1 deletion qiskit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@
from ._result import Result
from ._util import _check_ibmqe_version

__version__ = '0.4.6'
__version__ = '0.4.7'

_check_ibmqe_version()
26 changes: 16 additions & 10 deletions qiskit/backends/_qiskit_cpp_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ def run(qobj, executable):
for result in cresult['result']:
if result['success'] is True:
__parse_sim_data(result['data'])
if 'noise_params' in result:
__parse_noise_params(result['noise_params'])
return cresult

except FileNotFoundError:
Expand Down Expand Up @@ -208,26 +210,31 @@ def __parse_json_complex_single(val):

def __parse_json_complex(val):
if isinstance(val, list):
return np.array([__parse_json_complex_single(j)
for j in val])
return np.array([__parse_json_complex_single(j) for j in val])
elif isinstance(val, dict):
return {i: __parse_json_complex_single(j)
for i, j in val.items()}
return {i: __parse_json_complex_single(j) for i, j in val.items()}
return val


def __parse_noise_params(noise):
if isinstance(noise, dict):
for key, val in noise:
if 'U_error' in val:
tmp = np.array([__parse_json_complex(row)
for row in val['U_error']])
noise[key]['U_error'] = tmp


def __parse_sim_data(data):
if 'quantum_states' in data:
tmp = [__parse_json_complex(psi)
for psi in data['quantum_states']]
tmp = [__parse_json_complex(psi) for psi in data['quantum_states']]
data['quantum_states'] = tmp
if 'density_matrix' in data:
tmp = np.array([__parse_json_complex(row)
for row in data['density_matrix']])
data['density_matrix'] = tmp
if 'inner_products' in data:
tmp = [__parse_json_complex(ips)
for ips in data['inner_products']]
tmp = [__parse_json_complex(ips) for ips in data['inner_products']]
data['inner_products'] = tmp
if 'saved_quantum_states' in data:
for j in range(len(data['saved_quantum_states'])):
Expand All @@ -240,7 +247,6 @@ def __parse_sim_data(data):
for j in range(len(data['saved_density_matrix'])):
tmp = {}
for key, val in data['saved_density_matrix'][j].items():
val = np.array([__parse_json_complex(row)
for row in val])
val = np.array([__parse_json_complex(row) for row in val])
tmp[int(key)] = val
data['saved_density_matrix'][j] = tmp
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def compile():

setup(
name="qiskit",
version="0.4.6",
version="0.4.7",
description="Software for developing quantum computing programs",
long_description="""QISKit is a software development kit for writing
quantum computing experiments, programs, and applications. Works with
Expand Down
280 changes: 140 additions & 140 deletions src/cpp-simulator/README.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/cpp-simulator/src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ OUTPUT_DIR = ../../../out
# Check if compiler is Apple LLVM and doesn't support OpenMP
APPLELLVM = $(shell ${CC} --version | grep ^Apple)
ifeq ($(APPLELLVM),)
CPPFLAGS = -std=c++14 -fopenmp $(OPT) $(INCLUDE) $(WARNINGS)
CPPFLAGS = $(USER_FLAGS) -std=c++14 -fopenmp $(OPT) $(INCLUDE) $(WARNINGS)
else
CPPFLAGS = -std=c++14 $(OPT) $(INCLUDE) $(WARNINGS)
CPPFLAGS = $(USER_FLAGS) -std=c++14 $(OPT) $(INCLUDE) $(WARNINGS)
endif

# BLAS distribution to use (change to use OpenBLAS or MKL for example)
Expand Down
4 changes: 2 additions & 2 deletions src/cpp-simulator/src/backends/ideal_backend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -688,8 +688,8 @@ void IdealBackend::qc_measure_reset(const uint_t qubit,
for (uint_t k2 = 0; k2 < end2; k2++) {
const auto i0 = k1 | k2;
const auto i1 = i0 | end2;
qreg[i0] = renorm * qreg[i1];
qreg[i1] = 0;
qreg[i1] = renorm * qreg[i0];
qreg[i0] = 0;
}
}
} else { // Measurement outcome was 0
Expand Down
10 changes: 6 additions & 4 deletions src/cpp-simulator/src/backends/noise_models.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -650,10 +650,11 @@ inline void from_json(const json_t &js, QubitNoise &noise) {
g = load_gate_error(n, 1, js);

// Check for special gate params
if (n == "x90") {
if (n == "X90") {
double theta = 0., omega = 0.;
const json_t &jsg = js[n];
JSON::get_value(theta, "amp_error", jsg);
JSON::get_value(theta, "amp_error", jsg); // legacy key (use calibration_error)
JSON::get_value(theta, "calibration_error", jsg);
JSON::get_value(omega, "detuning_error", jsg);

if (theta > 0. || theta < 0. || omega > 0. || omega < 0.) {
Expand Down Expand Up @@ -693,7 +694,8 @@ inline void from_json(const json_t &js, QubitNoise &noise) {

double theta = 0., omega = 0.;
const json_t &jsg = js[n];
JSON::get_value(theta, "amp_error", jsg);
JSON::get_value(theta, "amp_error", jsg); // legacy key (use calibration_error)
JSON::get_value(theta, "calibration_error", jsg);
JSON::get_value(omega, "zz_error", jsg);

if (theta > 0. || theta < 0. || omega > 0. || omega < 0.) {
Expand All @@ -709,7 +711,7 @@ inline void from_json(const json_t &js, QubitNoise &noise) {

// CR gate noise
double b = sqrt(1. + omega * omega);
double a = b * (M_PI / 4. + theta);
double a = 0.5 * b * (M_PI / 2. + theta);
double c = 1. / (sqrt(2.) * b);
U_CNOT_noise(0, 0) = c * (b * cos(a) + sin(a));
U_CNOT_noise(1, 3) = U_CNOT_noise(0, 0);
Expand Down
28 changes: 14 additions & 14 deletions src/cpp-simulator/src/utilities/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,24 +161,24 @@ class MultiPartiteIndex {
* Eg: qs_srt = {0, 1, 2}
*/
template <size_t N>
uint_t index0(const std::array<uint_t, N> qs_srt, const uint_t k) const;
uint_t index0(const std::array<uint_t, N> &qs_srt, const uint_t k) const;

/**
* This function does not require the qubits to be sorted, but takes as input
* the result from index0, and applies the index for the qubits in the order
* specified by qs.
*/
template <size_t N>
std::array<uint_t, 1ULL << N> indexes(const std::array<uint_t, N> qs,
const std::array<uint_t, N> qs_srt,
std::array<uint_t, 1ULL << N> indexes(const std::array<uint_t, N> &qs,
const std::array<uint_t, N> &qs_srt,
const uint_t k) const;

std::array<uint_t, 4> indexes(const std::array<uint_t, 2> qs,
const std::array<uint_t, 2> qs_srt,
std::array<uint_t, 4> indexes(const std::array<uint_t, 2> &qs,
const std::array<uint_t, 2> &qs_srt,
const uint_t k) const;

std::array<uint_t, 2> indexes(const std::array<uint_t, 1> qs,
const std::array<uint_t, 1> qs_srt,
std::array<uint_t, 2> indexes(const std::array<uint_t, 1> &qs,
const std::array<uint_t, 1> &qs_srt,
const uint_t k) const;
};

Expand Down Expand Up @@ -326,7 +326,7 @@ void from_json(const json_t &js, Clifford &clif);
//------------------------------------------------------------------------------

template <size_t N>
uint_t MultiPartiteIndex::index0(const std::array<uint_t, N> qs_srt,
uint_t MultiPartiteIndex::index0(const std::array<uint_t, N> &qs_srt,
const uint_t k) const {
uint_t lowbits = 0, mask = 0;
for (size_t j = 0; j < N; j++) {
Expand All @@ -341,8 +341,8 @@ uint_t MultiPartiteIndex::index0(const std::array<uint_t, N> qs_srt,

template <size_t N>
std::array<uint_t, 1ULL << N>
MultiPartiteIndex::indexes(const std::array<uint_t, N> qs,
const std::array<uint_t, N> qs_srt,
MultiPartiteIndex::indexes(const std::array<uint_t, N> &qs,
const std::array<uint_t, N> &qs_srt,
const uint_t k) const {
std::array<uint_t, 1ULL << N> ret;
ret[0] = index0<N>(qs_srt, k);
Expand All @@ -356,8 +356,8 @@ MultiPartiteIndex::indexes(const std::array<uint_t, N> qs,
}

std::array<uint_t, 2>
MultiPartiteIndex::indexes(const std::array<uint_t, 1> qs,
const std::array<uint_t, 1> qs_srt,
MultiPartiteIndex::indexes(const std::array<uint_t, 1> &qs,
const std::array<uint_t, 1> &qs_srt,
const uint_t k) const {
std::array<uint_t, 2> ret;
ret[0] = index0(qs_srt, k);
Expand All @@ -366,8 +366,8 @@ MultiPartiteIndex::indexes(const std::array<uint_t, 1> qs,
}

std::array<uint_t, 4>
MultiPartiteIndex::indexes(const std::array<uint_t, 2> qs,
const std::array<uint_t, 2> qs_srt,
MultiPartiteIndex::indexes(const std::array<uint_t, 2> &qs,
const std::array<uint_t, 2> &qs_srt,
const uint_t k) const {
std::array<uint_t, 4> ret;
ret[0] = index0(qs_srt, k);
Expand Down
72 changes: 72 additions & 0 deletions src/cpp-simulator/test/inputs/reset_error.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"id": "test_reset_error",
"config": {
"shots": 100,
"seed": 1,
"data": ["probabilities"]
},
"circuits": [
{
"name": "reset_in0_out0",
"config": {"noise_params": {"reset_error": [1, 0]}},
"compiled_circuit": {
"header": {
"clbit_labels": [],
"number_of_clbits": 0,
"number_of_qubits": 1,
"qubit_labels": [["q", 0]]
},
"operations": [
{"name": "reset", "qubits": [0]}
]
}
},
{
"name": "reset_in1_out0",
"config": {"noise_params": {"reset_error": [1, 0]}},
"compiled_circuit": {
"header": {
"clbit_labels": [],
"number_of_clbits": 0,
"number_of_qubits": 1,
"qubit_labels": [["q", 0]]
},
"operations": [
{"name": "x", "qubits": [0]},
{"name": "reset", "qubits": [0]}
]
}
},
{
"name": "reset_in0_out1",
"config": {"noise_params": {"reset_error": [0, 1]}},
"compiled_circuit": {
"header": {
"clbit_labels": [],
"number_of_clbits": 0,
"number_of_qubits": 1,
"qubit_labels": [["q", 0]]
},
"operations": [
{"name": "reset", "qubits": [0]}
]
}
},
{
"name": "reset_in1_out1",
"config": {"noise_params": {"reset_error": [0, 1]}},
"compiled_circuit": {
"header": {
"clbit_labels": [],
"number_of_clbits": 0,
"number_of_qubits": 1,
"qubit_labels": [["q", 0]]
},
"operations": [
{"name": "x", "qubits": [0]},
{"name": "reset", "qubits": [0]}
]
}
}
]
}
61 changes: 61 additions & 0 deletions src/cpp-simulator/test/refs/reset_error.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"backend": "local_qiskit_simulator",
"id": "test_reset_error",
"result": [{
"data": {
"probabilities": [1.0, 0.0],
"time_taken": 0.000582
},
"name": "reset_in0_out0",
"noise_params": null,
"seed": 1,
"shots": 100,
"status": "DONE",
"success": true,
"threads_shot": 4
}, {
"data": {
"probabilities": [1.0, 0.0],
"time_taken": 0.000255
},
"name": "reset_in1_out0",
"noise_params": null,
"seed": 1,
"shots": 100,
"status": "DONE",
"success": true,
"threads_shot": 4
}, {
"data": {
"probabilities": [0.0, 1.0],
"time_taken": 0.000231
},
"name": "reset_in0_out1",
"noise_params": {
"reset_error": [0.0, 1.0]
},
"seed": 1,
"shots": 100,
"status": "DONE",
"success": true,
"threads_shot": 4
}, {
"data": {
"probabilities": [0.0, 1.0],
"time_taken": 0.000306
},
"name": "reset_in1_out1",
"noise_params": {
"reset_error": [0.0, 1.0]
},
"seed": 1,
"shots": 100,
"status": "DONE",
"success": true,
"threads_shot": 4
}],
"simulator": "qubit",
"status": "COMPLETED",
"success": true,
"time_taken": 0.00142
}

0 comments on commit d8318b4

Please sign in to comment.