-
Notifications
You must be signed in to change notification settings - Fork 368
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #542 from chriseclectic/openpulse-sim-rebase
Add PulseSimulator feature branch to master
- Loading branch information
Showing
96 changed files
with
15,503 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "src/third-party/headers/muparserx"] | ||
path = src/third-party/headers/muparserx | ||
url = https://github.com/beltoforion/muparserx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
find_package(PythonExtensions REQUIRED) | ||
find_package(Cython REQUIRED) | ||
find_package(PythonLibs REQUIRED) | ||
find_package(NumPy REQUIRED) | ||
|
||
# Variables for input user data: | ||
# | ||
# CYTHON_USER_INCLUDE_DIRS: | ||
# - For Cython modules that need to import some header file not in the paths, example: | ||
# set(CYTHON_USER_INCLUDE_DIRS "/opt/my/include") | ||
# CYTHON_USER_LIB_DIRS: | ||
# - For Cython modules that need to link with external libs, example: | ||
# set(CYTHON_USER_LIB_DIRS "/opt/my/lib") | ||
# CYTHON_INSTALL_DIR: | ||
# - Where to install the resulting shared libraries | ||
# set(CYTHON_INSTALL_DIR "/opt/my/lib") | ||
|
||
|
||
# Set default values | ||
set(CYTHON_USER_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}) | ||
unset(CYTHON_USER_LIB_DIRS) | ||
set(CYTHON_INSTALL_DIR "qiskit/providers/aer/backends") | ||
|
||
function(add_cython_module module) | ||
add_cython_target(${module} ${module}.pyx CXX) | ||
add_library(${module} MODULE ${module} ${ARGV1}) | ||
set_target_properties(${module} PROPERTIES | ||
LINKER_LANGUAGE CXX | ||
CXX_STANDARD 14) | ||
|
||
if(APPLE) | ||
set_target_properties(${module} PROPERTIES | ||
LINK_FLAGS ${AER_LINKER_FLAGS}) | ||
endif() | ||
|
||
# We only need to pass the linter once, as the codebase is the same for | ||
# all controllers | ||
# add_linter(target) | ||
target_include_directories(${module} | ||
PRIVATE ${AER_SIMULATOR_CPP_SRC_DIR} | ||
PRIVATE ${AER_SIMULATOR_CPP_EXTERNAL_LIBS} | ||
PRIVATE ${PYTHON_INCLUDE_DIRS} | ||
PRIVATE ${NumPy_INCLUDE_DIRS} | ||
PRIVATE ${CYTHON_USER_INCLUDE_DIRS}) | ||
|
||
target_link_libraries(${module} | ||
${AER_LIBRARIES} | ||
${PYTHON_LIBRARIES} | ||
${CYTHON_USER_LIB_DIRS}) | ||
|
||
python_extension_module(${module} | ||
FORWARD_DECL_MODULES_VAR fdecl_module_list) | ||
|
||
python_modules_header(modules | ||
FORWARD_DECL_MODULES_LIST ${fdecl_module_list}) | ||
|
||
include_directories(${modules_INCLUDE_DIRS}) | ||
# TODO Where to put the target files | ||
install(TARGETS ${module} LIBRARY DESTINATION ${CYTHON_INSTALL_DIR}) | ||
endfunction() |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
# This code is part of Qiskit. | ||
# | ||
# (C) Copyright IBM 2018, 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. | ||
# pylint: disable=arguments-differ, missing-return-type-doc | ||
|
||
""" | ||
Qiskit Aer OpenPulse simulator backend. | ||
""" | ||
|
||
import uuid | ||
import time | ||
import datetime | ||
import logging | ||
from numpy import inf | ||
from qiskit.result import Result | ||
from qiskit.providers.models import BackendConfiguration, PulseDefaults | ||
from .aerbackend import AerBackend | ||
from ..aerjob import AerJob | ||
from ..version import __version__ | ||
from ..openpulse.qobj.digest import digest_pulse_obj | ||
from ..openpulse.solver.opsolve import opsolve | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class PulseSimulator(AerBackend): | ||
"""Aer OpenPulse simulator | ||
""" | ||
DEFAULT_CONFIGURATION = { | ||
'backend_name': 'pulse_simulator', | ||
'backend_version': __version__, | ||
'n_qubits': 20, | ||
'coupling_map': None, | ||
'url': 'https://github.com/Qiskit/qiskit-aer', | ||
'simulator': True, | ||
'meas_levels': [0, 1, 2], | ||
'local': True, | ||
'conditional': True, | ||
'open_pulse': True, | ||
'memory': False, | ||
'max_shots': 10**6, | ||
'description': 'A pulse-based Hamiltonian simulator', | ||
'gates': [], | ||
'basis_gates': [] | ||
} | ||
|
||
def __init__(self, configuration=None, provider=None): | ||
|
||
# purpose of defaults is to pass assemble checks | ||
self._defaults = PulseDefaults(qubit_freq_est=[inf], | ||
meas_freq_est=[inf], | ||
buffer=0, | ||
cmd_def=[], | ||
pulse_library=[]) | ||
super().__init__(self, | ||
BackendConfiguration.from_dict(self.DEFAULT_CONFIGURATION), | ||
provider=provider) | ||
|
||
def run(self, qobj, | ||
system_model, | ||
backend_options=None, | ||
validate=False): | ||
"""Run a qobj on the backend.""" | ||
# Submit job | ||
job_id = str(uuid.uuid4()) | ||
aer_job = AerJob(self, job_id, self._run_job, qobj, system_model, | ||
backend_options, validate) | ||
aer_job.submit() | ||
return aer_job | ||
|
||
def _run_job(self, job_id, qobj, | ||
system_model, | ||
backend_options, | ||
validate): | ||
"""Run a qobj job""" | ||
start = time.time() | ||
if validate: | ||
self._validate(qobj, backend_options, noise_model=None) | ||
# Send to solver | ||
openpulse_system = digest_pulse_obj(qobj, system_model, backend_options) | ||
results = opsolve(openpulse_system) | ||
end = time.time() | ||
return self._format_results(job_id, results, end - start, qobj.qobj_id) | ||
|
||
def _format_results(self, job_id, results, time_taken, qobj_id): | ||
"""Construct Result object from simulator output.""" | ||
# Add result metadata | ||
output = {} | ||
output['qobj_id'] = qobj_id | ||
output['results'] = results | ||
output['success'] = True | ||
output["job_id"] = job_id | ||
output["date"] = datetime.datetime.now().isoformat() | ||
output["backend_name"] = self.name() | ||
output["backend_version"] = self.configuration().backend_version | ||
output["time_taken"] = time_taken | ||
return Result.from_dict(output) | ||
|
||
def defaults(self): | ||
"""Return defaults. | ||
Returns: | ||
PulseDefaults: object for passing assemble. | ||
""" | ||
return self._defaults |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.