Skip to content

Commit

Permalink
Improve python bindings
Browse files Browse the repository at this point in the history
* fixed namespace package
* if csv option is present, the resulting python object now contains an entry with the resulting csv string

Signed-off-by: Lukas Burgholzer <lukas.burgholzer@jku.at>
  • Loading branch information
burgholzer committed Oct 19, 2020
1 parent 143ff2e commit e2d83e7
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion extern/pybind11
Submodule pybind11 updated 62 files
+169 −25 .github/workflows/ci.yml
+1 −2 .pre-commit-config.yaml
+48 −47 README.rst
+10 −10 docs/advanced/pycpp/numpy.rst
+20 −17 docs/benchmark.py
+4 −2 docs/changelog.rst
+134 −96 docs/conf.py
+7 −2 docs/index.rst
+2 −0 docs/limitations.rst
+6 −4 docs/release.rst
+40 −0 include/pybind11/detail/class.h
+1 −1 include/pybind11/detail/common.h
+43 −32 include/pybind11/detail/internals.h
+18 −4 include/pybind11/numpy.h
+1 −0 include/pybind11/pybind11.h
+1 −1 pybind11/_version.py
+1 −1 tests/CMakeLists.txt
+17 −9 tests/conftest.py
+4 −4 tests/requirements.txt
+12 −12 tests/test_buffers.cpp
+9 −9 tests/test_buffers.py
+85 −54 tests/test_builtin_casters.py
+39 −12 tests/test_call_policies.py
+21 −10 tests/test_callbacks.py
+23 −17 tests/test_chrono.py
+82 −36 tests/test_class.py
+16 −4 tests/test_copy_move.py
+36 −10 tests/test_custom_type_casters.py
+5 −5 tests/test_docstring_options.py
+182 −109 tests/test_eigen.py
+18 −10 tests/test_enum.py
+1 −1 tests/test_eval_call.py
+15 −8 tests/test_exceptions.py
+75 −35 tests/test_factory_constructors.py
+4 −1 tests/test_gil_scoped.py
+25 −22 tests/test_iostream.py
+2 −2 tests/test_kwargs_and_defaults.cpp
+70 −25 tests/test_kwargs_and_defaults.py
+40 −12 tests/test_local_bindings.py
+49 −30 tests/test_methods_and_attributes.py
+7 −3 tests/test_modules.py
+11 −6 tests/test_multiple_inheritance.py
+24 −24 tests/test_numpy_array.cpp
+140 −94 tests/test_numpy_array.py
+4 −4 tests/test_numpy_dtypes.cpp
+161 −96 tests/test_numpy_dtypes.py
+2 −2 tests/test_numpy_vectorize.cpp
+105 −44 tests/test_numpy_vectorize.py
+4 −1 tests/test_opaque_types.py
+17 −17 tests/test_operator_overloading.py
+1 −0 tests/test_pickling.py
+1 −1 tests/test_pytypes.cpp
+99 −45 tests/test_pytypes.py
+1 −1 tests/test_sequences_and_iterators.cpp
+19 −15 tests/test_sequences_and_iterators.py
+34 −15 tests/test_smart_ptr.py
+36 −22 tests/test_stl.py
+40 −34 tests/test_stl_binders.py
+11 −3 tests/test_tagbased_polymorphic.py
+44 −18 tests/test_virtual_functions.py
+1 −1 tools/FindPythonLibsNew.cmake
+1 −1 tools/pybind11Tools.cmake
23 changes: 14 additions & 9 deletions include/EquivalenceCheckingResults.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,21 +232,26 @@ namespace ec {
virtual std::ostream& printCSVEntry(std::ostream& out) {
if (error())
return out;
out << name1 << ";" << nqubits1 << ";" << ngates1 << ";" << name2 << ";" << nqubits2 << ";" << ngates2 << ";" << toString(expected) << ";" << toString(equivalence) << ";" << toString(method) << ";";
out << produceCSVEntry() << std::endl;
return out;
}
virtual std::string produceCSVEntry() {
if (error())
return "";
std::stringstream ss{};
ss << name1 << ";" << nqubits1 << ";" << ngates1 << ";" << name2 << ";" << nqubits2 << ";" << ngates2 << ";" << toString(expected) << ";" << toString(equivalence) << ";" << toString(method) << ";";
if (timeout) {
out << "TO";
ss << "TO";
} else {
out << time ;
ss << time ;
}
out << ";" << maxActive;
ss << ";" << maxActive;
if (nsims > 0) {
out << ";" << nsims;
ss << ";" << nsims;
} else {
out << ";-";
ss << ";-";
}

out << std::endl;
return out;
return ss.str();
}
};
}
Expand Down
5 changes: 3 additions & 2 deletions jkq/qcec/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
add_subdirectory("../../extern/pybind11" "extern/pybind11")
add_subdirectory("${PROJECT_SOURCE_DIR}/extern/pybind11" "extern/pybind11")
add_library(pybind11 ALIAS pybind11::pybind11)
add_subdirectory("../../extern/pybind11_json" "extern/pybind11_json")

add_subdirectory("${PROJECT_SOURCE_DIR}/extern/pybind11_json" "extern/pybind11_json")

pybind11_add_module(py${PROJECT_NAME} bindings.cpp EXCLUDE_FROM_ALL)
target_link_libraries(py${PROJECT_NAME} PUBLIC pybind11_json ${PROJECT_NAME})
6 changes: 5 additions & 1 deletion jkq/qcec/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ nl::json verify(const py::object& instance) {
return {"error", ss.str()};
}

return ec->results.produceJSON(config.printStatistics);
auto result = ec->results.produceJSON(config.printStatistics);
if (config.printCSV)
result["csv"] = ec->results.produceCSVEntry();

return result;
}

PYBIND11_MODULE(pyqcec, m) {
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import platform
import subprocess

from setuptools import setup, Extension, find_packages
from setuptools import setup, Extension, find_namespace_packages
from setuptools.command.build_ext import build_ext


Expand Down Expand Up @@ -74,7 +74,7 @@ def build_extension(self, ext):
ext_modules=[CMakeExtension('pyqcec')],
cmdclass=dict(build_ext=CMakeBuild),
zip_safe=False,
packages=find_packages(),
packages=find_namespace_packages(),
classifiers=[
'Development Status :: 4 - Beta',
"Programming Language :: Python :: 3",
Expand Down

0 comments on commit e2d83e7

Please sign in to comment.