Skip to content

Commit

Permalink
Merge branch 'master' into automate-wheel-build
Browse files Browse the repository at this point in the history
  • Loading branch information
mtreinish authored Oct 24, 2019
2 parents d0169bf + 03fee0f commit 4ca6424
Show file tree
Hide file tree
Showing 66 changed files with 2,345 additions and 1,480 deletions.
42 changes: 39 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,57 @@ Changelog](http://keepachangelog.com/en/1.0.0/).
> - **Fixed**: for any bug fixes.
> - **Security**: in case of vulnerabilities.
[UNRELEASED](https://github.com/Qiskit/qiskit-aer/compare/0.3.0...HEAD)
[UNRELEASED](https://github.com/Qiskit/qiskit-aer/compare/0.3.2...HEAD)
=======================================================================

Added
-----

Changed
-------

Removed
-------

Fixed
-----


[0.3.2](https://github.com/Qiskit/qiskit-aer/compare/0.3.1...0.3.2) - 2019-10-16
===============================================================================

Added
-----

Changed
-------

Removed
-------

Fixed
-----
- Fix sdist to always attempt to build (\#401)



[0.3.1](https://github.com/Qiskit/qiskit-aer/compare/0.3.0...0.3.1) - 2019-10-15
===============================================================================


Added
-----
- Added tests for the Fredkin gate (#357)
- Added tests for the cu1 gate (#360)
- Added tests for statevector and stabilizer snapshots (\#355)
- Added tests for density matrix snapshot (\#374)
- Added tests for probabilities snapshot (\#380)
- Added support for reset() in MPS simulation method (\#393)
- Added tests for matrix and Pauli expectation value snapshot (\#386)

Changed
-------
- Changes signature of SnapshotExpectationValue extension and the way qubit position parameters are parsed in expectation_value_matrix qobj instructions (\#386)
- Change signature of SnapshotProbabilities extension (\#380)
- Change signature of SnapshotDensityMatrix extension (\#374)
- Stabilizer snapshot returns stabilizer instead of full Clifford table (\#355)
Expand All @@ -37,8 +75,6 @@ Changed
- Update device noise model to use gate_length (\#352)
- Refactoring code and introducing floating point comparison func (\#338)



Removed
-------

Expand Down
2 changes: 1 addition & 1 deletion contrib/standalone/qasm_simulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ int main(int argc, char **argv) {
// Initialize simulator
AER::Simulator::QasmController sim;
auto result = sim.execute(qobj);
out << result.dump(4) << std::endl;
out << result.json().dump(4) << std::endl;

// Check if execution was successful.
bool success = false;
Expand Down
2 changes: 1 addition & 1 deletion qiskit/providers/aer/VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.3.0
0.4.0
11 changes: 0 additions & 11 deletions qiskit/providers/aer/backends/aerbackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,17 +161,6 @@ def _validate_controller_output(self, output):
if output:
logger.error('Output: %s', output)
raise AerError("simulation terminated without returning valid output.")
# Check results
# TODO: Once https://github.com/Qiskit/qiskit-terra/issues/1023
# is merged this should be updated to deal with errors using
# the Result object methods
if not output.get("success", False):
# Check for error message in the failed circuit
for res in output.get('results', []):
if not res.get('success', False):
raise AerError(res.get("status", None))
# If no error was found check for error message at qobj level
raise AerError(output.get("status", None))

def _validate(self, qobj, backend_options, noise_model):
"""Validate the qobj, backend_options, noise_model for the backend"""
Expand Down
143 changes: 99 additions & 44 deletions qiskit/providers/aer/extensions/snapshot_expectation_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,72 +13,127 @@
"""
Simulator command to snapshot internal simulator representation.
"""

import math
import numpy
from qiskit import QuantumCircuit
from qiskit.circuit import Instruction
from qiskit.extensions.exceptions import ExtensionError
from qiskit.quantum_info.operators import Pauli, Operator
from qiskit.providers.aer.extensions import Snapshot


class SnapshotExpectationValue(Snapshot):
"""Snapshot instruction for supported methods of Qasm simulator."""

def __init__(self,
label,
op,
pauli=True,
variance=False,
num_qubits=0,
num_clbits=0,
params=None):

num_qubits = len(op)

if pauli:
if variance:
super().__init__(label,
'expectation_value_pauli_with_variance',
num_qubits,
num_clbits,
params)
else:
super().__init__(label,
'expectation_value_pauli',
num_qubits,
num_clbits,
params)
def __init__(self, label, op, single_shot=False, variance=False):
"""Create a probability snapshot instruction.
Args:
label (str): the snapshot label.
op (Operator): operator to snapshot.
single_shot (bool): return list for each shot rather than average [Default: False]
variance (bool): compute variance of probabilities [Default: False]
Raises:
ExtensionError: if snapshot is invalid.
"""
pauli_op = self._format_pauli_op(op)
if pauli_op:
# Pauli expectation value
snapshot_type = 'expectation_value_pauli'
params = pauli_op
num_qubits = len(params[0][1])
else:
if variance:
super().__init__(label, 'expectation_value_matrix_with_variance', num_qubits,
num_clbits, params)
snapshot_type = 'expectation_value_matrix'
mat = self._format_single_matrix(op)
if mat is not None:
num_qubits = int(math.log2(len(mat)))
if mat.shape != (2 ** num_qubits, 2 ** num_qubits):
raise ExtensionError("Snapshot Operator is invalid.")
qubits = list(range(num_qubits))
params = [[1., [[qubits, mat]]]]
else:
super().__init__(label, 'expectation_value_matrix', num_qubits, num_clbits, params)
# If op doesn't match the previous cases we try passing
# in the op as raw params
params = op
num_qubits = 0
for _, pair in params:
num_qubits = max(num_qubits, *pair[0])

# HACK: we wrap param list in numpy array to make it validate
# in terra
params = [numpy.array(elt, dtype=object) for elt in params]

if single_shot:
snapshot_type += '_single_shot'
elif variance:
snapshot_type += '_with_variance'
super().__init__(label,
snapshot_type=snapshot_type,
num_qubits=num_qubits,
params=params)

@staticmethod
def _format_single_matrix(op):
"""Format op into Matrix op, return None if not Pauli op"""
# This can be specified as list [[coeff, Pauli], ... ]
if isinstance(op, numpy.ndarray):
return op
if isinstance(op, (Instruction, QuantumCircuit)):
return Operator(op).data
if hasattr(op, 'to_operator'):
return op.to_operator().data
return None

@staticmethod
def _format_pauli_op(op):
"""Format op into Pauli op, return None if not Pauli op"""
# This can be specified as list [[coeff, Pauli], ... ]
if isinstance(op, Pauli):
return [[1., op.to_label()]]
if not isinstance(op, (list, tuple)):
return None
pauli_op = []
for pair in op:
if len(pair) != 2:
return None
coeff = complex(pair[0])
pauli = pair[1]
if isinstance(pauli, Pauli):
pauli_op.append([coeff, pauli.to_label()])
elif isinstance(pair[1], str):
pauli_op.append([coeff, pauli])
else:
return None
return pauli_op


def snapshot_expectation_value(self, label, op, qubits,
single_shot=False,
variance=False):
"""Take a snapshot of expectation value <O> of an Operator.
def snapshot_expectation_value(self,
label,
op,
qubits=None,
params=None):
"""Take a snapshot of expectation value <M> of some Operator M.
Works on all qubits, and prevents reordering (like barrier).
Args:
label (str): a snapshot label to report the result
op (Operator): operator to snapshot
qubits (list or None): the qubits to apply snapshot to [Default: None].
params (list or None): the parameters for snapshot_type [Default: None].
qubits (list): the qubits to snapshot.
single_shot (bool): return list for each shot rather than average [Default: False]
variance (bool): compute variance of probabilities [Default: False]
Returns:
QuantumCircuit: with attached command
QuantumCircuit: with attached instruction.
Raises:
ExtensionError: malformed command
ExtensionError: if snapshot is invalid.
"""

snapshot_register = Snapshot.define_snapshot_register(self, label, qubits)

return self.append(
SnapshotExpectationValue(
label,
op,
params=params), snapshot_register)
SnapshotExpectationValue(label, op,
single_shot=single_shot,
variance=variance),
snapshot_register)


QuantumCircuit.snapshot_expectation_value = snapshot_expectation_value
16 changes: 6 additions & 10 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import os
try:
from skbuild import setup
dummy_install = False
except:
print(""" WARNING
=======
scikit-build package is needed to build Aer sources.
Please, install scikit-build and reinstall Aer:
pip install -I qiskit-aer """)
from setuptools import setup
dummy_install = True
except ImportError:
import subprocess
subprocess.call([sys.executable, '-m', 'pip', 'install', 'scikit-build'])
from skbuild import setup
from setuptools import find_packages

requirements = [
Expand All @@ -36,7 +31,7 @@ def find_qiskit_aer_packages():
setup(
name='qiskit-aer',
version=VERSION,
packages=find_qiskit_aer_packages() if not dummy_install else [],
packages=find_qiskit_aer_packages(),
cmake_source_dir='.',
description="Qiskit Aer - High performance simulators for Qiskit",
url="https://github.com/Qiskit/qiskit-aer",
Expand All @@ -57,6 +52,7 @@ def find_qiskit_aer_packages():
"Topic :: Scientific/Engineering",
],
install_requires=requirements,
setup_requires=['scikit-build', 'cmake', 'Cython'],
include_package_data=True,
cmake_args=["-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.9"],
keywords="qiskit aer simulator quantum addon backend",
Expand Down
Loading

0 comments on commit 4ca6424

Please sign in to comment.