-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
C++ Simulator Refactor #386
Conversation
255d024
to
616826f
Compare
616826f
to
3a2dbde
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ready to merge! I think @chriseclectic still needs to update the branch with a fix for the SDK to find the simulator into the build dir.
src/qasm-simulator-cpp/src/Makefile
Outdated
WARNINGS = -pedantic -Wall -Wextra -Wfloat-equal -Wundef -Wcast-align -Wwrite-strings -Wmissing-declarations -Wredundant-decls -Wshadow -Woverloaded-virtual | ||
OPT = -O3 -march=native -ffast-math | ||
# Install exe into pip location for backends | ||
OUTPUT_DIR = ../../../qiskit/backends |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"out of source compilation" is a very common practice, where the results of a build are created in an isolated and separated from the sources directory. I'd recommend set the OUTPUT_DIR to ../../../out
We only use qiskit/backeds/
as a workaround when packaging for distributing with pip, but this is going to disappear once we have the library interface for the simulator ready (it will end-up being a library so installed with the rest of the native libraries).
src/qasm-simulator-cpp/src/Makefile
Outdated
$(CC) $(CPPFLAGS) $(DEFINES) -o ${OUTPUT_DIR}/qasm_simulator_cpp main.o $(LIBS) | ||
|
||
sim_debug: main.o | ||
$(CC) -g $(CPPFLAGS) $(DEFINES) -o ${OUTPUT_DIR}/qasm_simulator_cpp_debug main.o $(LIBS) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that we have Release and Debug builds, I'd suggest using ${OUTPUT_DIR}/Release/
and ${OUTPUT_DIR}/Debug/
so there's no need to rename the executable.
if (n > 0) | ||
omp_threads = n; | ||
}; | ||
inline void set_omp_threshold(int_t n) { | ||
inline void set_omp_threshold(int n) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like uint32_t (or uint8_t?) might be a better type.
Backend backend = circ.config; | ||
Backend backend; | ||
backend.set_config(circ.config); | ||
backend.attach_noise(circ.noise); | ||
|
||
// Set RNG Seed | ||
uint_t rng_seed = (circ.rng_seed < 0) ? std::random_device()() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is always false, as circ.rng_seed is initialized to -1 in Circuit.hpp but never changed again. Not a big deal probably, mentioning just in case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, by default it will do this, but it can be override at runtime from the seed
setting in the input file
@atilag @ajavadia Only a couple of things left to do:
|
For the travis issue - can you make the tests that require an instance of the simulator to be skipped? This is currently the behaviour in master, and I believe we should have the same approach until we reach the point where the simulator is guaranteed to be available in all platforms and environments. The first stage of travis ("lint and pure python test") does not build the non-python code in purpose - skipping the tests would make it pass (and then proceed with the full testing suit on the second stage 🤞 ). |
{ | ||
if (JSON_UNLIKELY(not j.is_string())) | ||
{ | ||
JSON_THROW(type_error::create(302, "type must be string, but is " + std::string(j.type_name()))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chriseclectic The JSON parser used here expects all identifiers for QuantumRegister, ClassicalRegister, QuantumCircuit to be strings. However, in #308 supporting non-string identifiers was introduced. Is it possible to allow that here?
I realize that it may be hard, in which case we can skip it for now. The reason I came across this was in the context of allowing interchangeability of simulators. There are 3 tests in test_identifiers.py
which will pass with the python simulator but not the c++ simulator. All 3 are named test_add_circuit
.
Can we take the chance to reintroduce the travis osx builds before merging (basically, uncommenting the changes done at #374? They were disabled as travis was having issues during those days that seem to be recovered by now. |
Yeah, I got it. |
@atilag I've added everything I need for the merge |
- Updated modified JSON library to version 3.1.1 - Encapsulated multi-partite qubit state vector updates in a QubitVector class - Added TensorIndex class used for indexing in the QubitVector class. - Reworked ideal_backend and qubit_backend to use QubitVector methods - merged sampleshots_engine into vector_engine - removed ability to display final and saved quantum states - added “snapshot” instruction and added ability to display snapshots of quantum state - added basic cpp test file for qubit_vector class - Added auto check to makefile for GCC7 compiler on macOS
- added string simulator input/output - Fixed compile bugs on linux - changed snapshot map to use int key instead of unsigned long long key - allowed sample shots to compute probability vector in place to save memory
…erialisation of clifford snapshots
cmake build needs updating for new directory / exe file name
renamed _local_qiskit_simulator.py to _local_qasm_simulator_cpp.py
* Makefile: output build directory changed * Makefile fixes for out-of-source compilation
If the binary is not found, then the test will skip in stage1, on later stages, there's a build step that will make travis fail if something is wrong.
* new dependencies target (make depend) for the qasm-simulator-cpp (cherry picked from commit 3b25390) * changed to executable and bug fix (cherry picked from commit ce8be89) * assume yes for automatic pkg install (cherry picked from commit 2cd7607) * -march not supported on ppc64le. Use -mcpu instead (cherry picked from commit 7cdab8f) * bugfix (cherry picked from commit 831692e)
Increase shots to fix failing test cleaning up some simulator variable names
0a3a299
to
93b3092
Compare
I rebased against master and squashed a few commits |
C++ Simulator Refactor
This PR is a rebase of the C++ code changes from PR #351, with the python code changes for backend renaming to be split into a seperate PR.
Description
tensor_index.hpp
) for multi-partite qubit vector indexingqubit_vector.hpp
) for multi-partite qubit vector algebraQubitVector
class and methods instead ofstd::vector
.save
command (usesnapshot
instead)snapshot
instead)src/qasm-simulator-cpp
, renamed executable toqasm_simulator_cpp
.Motivation and Context
This refactor fixes some bugs in the C++ simulator, includes unit tests, and allows for easier linking of the simulator later to make libraries (such as with cython).
How Has This Been Tested?
All current tests pass
New tests (both python unit tests and direct C++ tests) have been added for the simulator
Types of changes
Checklist: