mirror of https://github.com/Qiskit/qiskit.git
Updated makefile to install to qiskit/backends, fix error in JSON deserialisation of clifford snapshots
This commit is contained in:
parent
bc4e077935
commit
16486e1bbc
4
Makefile
4
Makefile
|
@ -54,8 +54,8 @@ doc:
|
|||
done
|
||||
|
||||
sim:
|
||||
make -C src/cpp-simulator/src clean
|
||||
make -C src/cpp-simulator/src
|
||||
make -C src/qiskit-simulator/src clean
|
||||
make -C src/qiskit-simulator/src
|
||||
|
||||
coverage_erase:
|
||||
coverage erase
|
||||
|
|
|
@ -55,12 +55,13 @@ class QISKitCppSimulator(BaseBackend):
|
|||
if not configuration:
|
||||
self._configuration = {
|
||||
'name': 'local_qiskit_simulator',
|
||||
'url': 'https://github.com/QISKit/qiskit-sdk-py/src/cpp-simulator',
|
||||
'url': 'https://github.com/QISKit/qiskit-sdk-py/src/qiskit-simulator',
|
||||
'simulator': True,
|
||||
'local': True,
|
||||
'description': 'A C++ realistic noise simulator for qobj files',
|
||||
'coupling_map': 'all-to-all',
|
||||
"basis_gates": 'u1,u2,u3,cx,id,x,y,z,h,s,sdg,t,tdg,rzz,snapshot,wait,noise,save,load',
|
||||
"basis_gates": 'u1,u2,u3,cx,id,x,y,z,h,s,sdg,t,tdg,rzz' +
|
||||
'snapshot,wait,noise,save,load'
|
||||
}
|
||||
|
||||
# Try to use the default executable if not specified.
|
||||
|
@ -94,7 +95,7 @@ class CliffordCppSimulator(BaseBackend):
|
|||
if not configuration:
|
||||
self._configuration = {
|
||||
'name': 'local_clifford_simulator',
|
||||
'url': 'https://github.com/QISKit/qiskit-sdk-py/src/cpp-simulator',
|
||||
'url': 'https://github.com/QISKit/qiskit-sdk-py/src/qiskit-simulator',
|
||||
'simulator': True,
|
||||
'local': True,
|
||||
'description': 'A C++ Clifford simulator with approximate noise',
|
||||
|
@ -159,15 +160,16 @@ class QASMSimulatorDecoder(json.JSONDecoder):
|
|||
def object_hook(self, obj):
|
||||
for key in ['U_error', 'density_matrix']:
|
||||
# JSON is a complex matrix
|
||||
if key in obj:
|
||||
if key in obj and isinstance(obj[key], list):
|
||||
tmp = np.array(obj[key])
|
||||
obj[key] = tmp[::, ::, 0] + 1j * tmp[::, ::, 1]
|
||||
for key in ['quantum_state', 'inner_products']:
|
||||
# JSON is a list of complex vectors
|
||||
if key in obj:
|
||||
for j in range(len(obj[key])):
|
||||
tmp = np.array(obj[key][j])
|
||||
obj[key][j] = tmp[::, 0] + 1j * tmp[::, 1]
|
||||
if isinstance(obj[key][j], list):
|
||||
tmp = np.array(obj[key][j])
|
||||
obj[key][j] = tmp[::, 0] + 1j * tmp[::, 1]
|
||||
return obj
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# pylint: disable=invalid-name
|
||||
|
||||
# Copyright 2017 IBM RESEARCH. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# =============================================================================
|
||||
|
||||
"""
|
||||
local_qiskit_simulator command to snapshot the quantum state.
|
||||
"""
|
||||
from qiskit import CompositeGate
|
||||
from qiskit import Gate
|
||||
from qiskit import QuantumCircuit
|
||||
from qiskit._instructionset import InstructionSet
|
||||
from qiskit._quantumregister import QuantumRegister
|
||||
from qiskit.qasm import _node as node
|
||||
|
||||
|
||||
class SnapshotGate(Gate):
|
||||
"""Simulator snapshot operation."""
|
||||
|
||||
def __init__(self, m, qubit, circ=None):
|
||||
"""Create new snapshot gate."""
|
||||
super().__init__("snapshot", [m], [qubit], circ)
|
||||
|
||||
def qasm(self):
|
||||
"""Return OPENQASM string."""
|
||||
qubit = self.arg[0]
|
||||
m = self.param[0]
|
||||
return self._qasmif("snapshot(%d) %s[%d];" % (m,
|
||||
qubit[0].name,
|
||||
qubit[1]))
|
||||
|
||||
def inverse(self):
|
||||
"""Invert this gate."""
|
||||
return self # self-inverse
|
||||
|
||||
def reapply(self, circ):
|
||||
"""Reapply this gate to corresponding qubits in circ."""
|
||||
self._modifiers(circ.snapshot(self.param[0], self.arg[0]))
|
||||
|
||||
|
||||
def snapshot(self, m, q):
|
||||
"""Cache the quantum state of local_qiskit_simulator."""
|
||||
if isinstance(q, QuantumRegister):
|
||||
gs = InstructionSet()
|
||||
for j in range(q.size):
|
||||
gs.add(self.snapshot(m, (q, j)))
|
||||
return gs
|
||||
self._check_qubit(q)
|
||||
return self._attach(SnapshotGate(m, q, self))
|
||||
|
||||
|
||||
# Add to QuantumCircuit and CompositeGate classes
|
||||
QuantumCircuit.snapshot = snapshot
|
||||
CompositeGate.snapshot = snapshot
|
||||
|
||||
|
||||
# cache quantum state (identity)
|
||||
QuantumCircuit.definitions["snapshot"] = {
|
||||
"print": True,
|
||||
"opaque": False,
|
||||
"n_args": 1,
|
||||
"n_bits": 1,
|
||||
"args": ["m"],
|
||||
"bits": ["a"],
|
||||
# gate snapshot(m) a { }
|
||||
"body": node.GateBody([])
|
||||
}
|
|
@ -1,7 +1,8 @@
|
|||
INCLUDE = -I./ -I./backends -I./engines -I./utilities -I./third-party -I./third-party/headers
|
||||
WARNINGS = -pedantic -Wall -Wextra -Wfloat-equal -Wundef -Wcast-align -Wwrite-strings -Wmissing-declarations -Wredundant-decls -Wshadow -Woverloaded-virtual
|
||||
OPT = -O3 -march=native -ffast-math
|
||||
OUTPUT_DIR = ../../../out
|
||||
# Install exe into pip location for backends
|
||||
OUTPUT_DIR = ../../../qiskit/backends
|
||||
|
||||
CC = g++
|
||||
|
||||
|
@ -31,25 +32,22 @@ LIBS = -lpthread $(LIB_BLAS)
|
|||
|
||||
.SUFFIXES:.cpp .cc .o .c
|
||||
.cpp.o:
|
||||
${CC} -c ${CPPFLAGS} ${DEFINES} -o ${OUTPUT_DIR}/$@ $<
|
||||
${CC} -c ${CPPFLAGS} ${DEFINES} -o $@ $<
|
||||
.cc.o:
|
||||
${CC} -c ${CPPFLAGS} ${DEFINES} -o ${OUTPUT_DIR}/$@ $<
|
||||
${CC} -c ${CPPFLAGS} ${DEFINES} -o $@ $<
|
||||
.c.o:
|
||||
${CC} -c ${CPPFLAGS} ${DEFINES} -o ${OUTPUT_DIR}/$@ $<
|
||||
${CC} -c ${CPPFLAGS} ${DEFINES} -o $@ $<
|
||||
|
||||
|
||||
all: directories sim
|
||||
debug: directories sim_debug
|
||||
|
||||
directories:
|
||||
mkdir -p $(OUTPUT_DIR)
|
||||
all: sim
|
||||
debug: sim_debug
|
||||
|
||||
sim: main.o
|
||||
$(CC) $(CPPFLAGS) $(DEFINES) -o ${OUTPUT_DIR}/qiskit_simulator ${OUTPUT_DIR}/main.o $(LIBS)
|
||||
$(CC) $(CPPFLAGS) $(DEFINES) -o ${OUTPUT_DIR}/qasm_simulator_cpp main.o $(LIBS)
|
||||
|
||||
sim_debug: main.o
|
||||
$(CC) -g $(CPPFLAGS) $(DEFINES) -o ${OUTPUT_DIR}/qiskit_simulator_debug ${OUTPUT_DIR}/main.o $(LIBS)
|
||||
$(CC) -g $(CPPFLAGS) $(DEFINES) -o ${OUTPUT_DIR}/qasm_simulator_cpp_debug main.o $(LIBS)
|
||||
|
||||
clean:
|
||||
rm -rf $(OUTPUT_DIR)
|
||||
rm -rf ${OUTPUT_DIR}/qasm_simulator_cpp main.o
|
||||
|
||||
|
|
Loading…
Reference in New Issue