Skip to content
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

Add PyQrack backend option #274

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

WrathfulSpatula
Copy link

@WrathfulSpatula WrathfulSpatula commented Sep 7, 2021

Hi, I'm Dan Strano of the Unitary Fund, and lead developer of the high-performance, GPU-accelerated vm6502q/qrack quantum computer simulation framework. Last week, I wrapped our Qrack shared library interface in pure Python, to create PyQrack. Over the holiday weekend, I wrote back-end classes for both SimulaQron and Interlin-q. This pull request adds the PyQrack backend to SimulaQron, including unit tests.

The PyQrack back-end will transparently function somewhat like your stabilizer back-end, while PyQrack can still switch on-the-fly to full "Schrödinger method" "ket" simulation, without any in-depth knowledge or special configuration by users. Qrack internally identifies when it can run instructions as stabilizer, and simply maintains stabilizer representation for as long as it can, including in qubit subsets, if some separable qubit subsystems can maintain stabilizer representation while others can't. In fact, we "Schmidt decompose" our subsystems as well, treating identifiable separable subsystems as smaller "ket" simulations, with no special attention necessary from the user when acting entangling gates across separable subsystem boundaries. (This is inspired by work by Pednault and team, on Schmidt decomposition in the simulation of quantum circuits.) This adds significant overhead relative to the original CHP by Aaronson, for example, upon which our stabilizer "layer" is directly based, but Schmidt decomposition is intended to give a different set of advantages, in addition to our stabilizer layer.

I realize that it might be better if this back-end for SimulaQron stands on its own, in a separate plugin repo, or a fork. However, I hoped to start a discussion of that, here in this pull request. I'm interested in quantum network simulation as an alternative to Intel-QS type MPI-based "paging" parallelism for high-performance quantum computer simulation. Thank you for the awesome quantum network simulator, by the way!

@AckslD
Copy link
Member

AckslD commented Sep 9, 2021

Hi @WrathfulSpatula! I'm really happy to see a new backend for SimulaQron 🎉 I briefly looked at the code and looks very good to me. But I will tag @bvdvecht here since I'm no longer at QuTech and Bart has taken over the main responsibilities :) That being said I do still care a lot about SimulaQron so feel free to reach out it you have any issues/questions.

imo since SimulaQron doesn't have a full-fledge plugin system I would say that it makes sense to merge this into SimulaQron, in a similar way QuTip, ProjectQ etc is handled but will let @bvdvecht decide.

@bvdvecht
Copy link
Contributor

Sorry for the late response. I'm excited to see a new backend for SimulaQron!

The backend code and unit tests seem fine to me and I agree that it's good to just merge this into SimulaQron. Before doing that, it's probably good to make sure that the qrack or pyqrack (we should choose which name to use) backend is available from the command line (simulaqron set backend qrack).

With CQC being the main way of programming for SimulaQron at the moment, I also tried running some of the examples while having Qrack as the SimulaQron backend. Unfortunately it seems that applications with remote entanglement generation (e.g. teleportation) will crash; I think it has to do with accessing a qubit that is simulated on another node. I'm not sure however if this has to do with the Qrack backend itself, or that SimulaQron's implementation makes some assumptions about the backends that Qrack doesn't match, and in which case maybe the backend interface itself should be changed. Maybe @AckslD has an idea what's going on exactly?

@AckslD
Copy link
Member

AckslD commented Sep 21, 2021

@bvdvecht Do you have a traceback from the crash? :)

@WrathfulSpatula
Copy link
Author

By the way, we're still iterating the underlying Qrack API for a v6.2 release. ("PyQrack" is the name given to the Python binding layer over the shared library C interface, and this SimulaQron backend is specifically using the PyQrack layer.)

I notice, in my personal tests of PyQrack, we try to engage multiple OpenCL device parallelism by default, but platform interoperability can cause instability when multiple device parallelism might not even necessarily be desired. For example, my development machine has both an NVIDIA RTX 3080 and an Intel HD, with ICDs installed. PyQrack becomes unstable when both devices are visible to Qrack and the OpenCL environment, because either platform's buffer objects aren't recognized as proper, as a peer to the other platform's buffers, throwing CL_INVALID_MEM_OBJ under modest load.

I use VirtualCL for my experiments with Qrack clustering, and, if I use that virtualization layer to ban the Intel HD from my virtual platform, PyQrack is then stable. However, I'd like to add a native Qrack environment option for banning visible devices in the OpenCL environment, so that VirtualCL isn't necessary for this purpose. I could probably have that in PyQrack within a day or two.

I'm saying, configuring the PyQrack environment is still a little tricky. Does either machine have multiple OpenCL devices available, as reported by clinfo or equivalent? For example, it's common for many systems to have both an Intel HD and a NVIDIA card, like my primary system, or otherwise Intel CPU ICD alongside the Intel HD. Alternatively, if you have 0 OpenCL devices available on either system, it will work, but you might need PyQrack v0.4.3 or v0.4.4, as I was debugging this case just in the past day or two, (specifically on the Raspberry Pi 3 and RP4).

So, no OpenCL device is necessary at all, to run Qrack or PyQrack on a single node, at least with PyQrack v0.4.4. I'd expect, by Qrack's design, that different nodes could alternatively rely on the pure C++11 CPU simulation or the OpenCL-based simulation at the same time, but I'm having trouble on the networking side for my own testing, of getting two physical Linux machines I have to connect via SimulaQron.

@bvdvecht
Copy link
Contributor

@bvdvecht Do you have a traceback from the crash? :)

This is the output for the teleport app. The error says Cannot remove local qubit.

2021-09-22 10:41:55,059:DEBUG:CQC Alice: Command received
2021-09-22 10:41:55,059:DEBUG:CQC Alice got command header Command Header. Qubit ID: 1 Instruction: 2 Notify: False Block: True Action: False
2021-09-22 10:41:55,059:DEBUG:CQC Alice: Read XTRA Header: CQC Assign sub header. RefID=0
2021-09-22 10:41:55,059:DEBUG:CQC Alice: Executing command: Command Header. Qubit ID: 1 Instruction: 2 Notify: False Block: True Action: False
2021-09-22 10:41:55,060:DEBUG:CQC Alice: Measuring App ID 0 qubit id 1
2021-09-22 10:41:55,099:DEBUG:VIRTUAL NODE Alice: Measuring local qubit
2021-09-22 10:41:55,099:ERROR:VIRTUAL NODE Alice: Cannot remove local qubit. Error: 'No such qubit to remove'
2021-09-22 10:41:55,099:WARNING:CQC Alice: Measurement failed
Traceback (most recent call last):
  File "aliceTest.py", line 69, in <module>
    main()
  File "aliceTest.py", line 58, in main
    b = qA.measure()
  File "/home/bart/repos/qutech/simulaqron-public/CQC-Python/cqc/pythonLib/qubit.py", line 457, in measure
    return self._cqc.return_meas_outcome()
  File "/home/bart/repos/qutech/simulaqron-public/CQC-Python/cqc/pythonLib/cqc_connection.py", line 572, in return_meas_outcome
    msg = self.readMessage()
  File "/home/bart/repos/qutech/simulaqron-public/CQC-Python/cqc/pythonLib/cqc_connection.py", line 443, in readMessage
    self.check_error(currHeader)
  File "/home/bart/repos/qutech/simulaqron-public/CQC-Python/cqc/pythonLib/cqc_handler.py", line 874, in check_error
    self._errorHandler(hdr.tp)
  File "/home/bart/repos/qutech/simulaqron-public/CQC-Python/cqc/pythonLib/cqc_handler.py", line 880, in _errorHandler
    raise CQCGeneralError("General error")
cqc.pythonLib.util.CQCGeneralError: General error

If I change the teleport code of both Alice and Bob so there is literally only the createEPR and recvEPR calls and nothing else, then I got the following (full) log:

2021-09-22 10:47:12,910:DEBUG:CQC Bob: Initialized Protocol
2021-09-22 10:47:12,910:DEBUG:CQC Bob: Read CQC Header: CQC Header. Version: 2 Type: 1 App ID: 0 Length: 4
2021-09-22 10:47:12,910:DEBUG:CQC Alice: Read CQC Header: CQC Header. Version: 2 Type: 1 App ID: 0 Length: 12
2021-09-22 10:47:12,910:DEBUG:CQC Bob: Command received
2021-09-22 10:47:12,910:DEBUG:CQC Alice: Command received
2021-09-22 10:47:12,911:DEBUG:CQC Bob got command header Command Header. Qubit ID: 0 Instruction: 8 Notify: True Block: True Action: False
2021-09-22 10:47:12,911:DEBUG:CQC Bob: Executing command: Command Header. Qubit ID: 0 Instruction: 8 Notify: True Block: True Action: False
2021-09-22 10:47:12,911:DEBUG:CQC Alice got command header Command Header. Qubit ID: 0 Instruction: 7 Notify: True Block: True Action: False
2021-09-22 10:47:12,911:DEBUG:CQC Bob: Asking to receive for App ID 0
2021-09-22 10:47:12,911:DEBUG:CQC Alice: Read XTRA Header: Communication header. Remote App ID: 0 Remote Node: 2130706433 Remote Port: 8009 
2021-09-22 10:47:12,911:DEBUG:CQC Alice: Executing command: Command Header. Qubit ID: 0 Instruction: 7 Notify: True Block: True Action: False
2021-09-22 10:47:12,911:DEBUG:VIRTUAL NODE Bob: Trying to retrieve qubit for app id 0 from epr list
2021-09-22 10:47:12,912:DEBUG:VIRTUAL NODE Alice: Request to create new qubit.
2021-09-22 10:47:12,913:DEBUG:VIRTUAL NODE Alice: Local GETTING LOCK
2021-09-22 10:47:12,913:DEBUG:VIRTUAL NODE Alice: Local GOT LOCK
2021-09-22 10:47:12,913:DEBUG:VIRTUAL NODE Alice: Local GETTING LOCK
2021-09-22 10:47:12,913:DEBUG:VIRTUAL NODE Alice: Initializing new simulated register.
2021-09-22 10:47:12,913:DEBUG:VIRTUAL NODE Alice: Local RELEASE LOCK
2021-09-22 10:47:12,913:DEBUG:VIRTUAL NODE Alice: Local GOT LOCK
 No platforms found. Check OpenCL installation!
2021-09-22 10:47:12,914:INFO:QUANTUM Alice: Adding qubit number 0 to register 0
2021-09-22 10:47:12,914:DEBUG:VIRTUAL NODE Alice: Local RELEASE LOCK
2021-09-22 10:47:12,915:INFO:CQC Alice: Requested new qubit (0,1)
2021-09-22 10:47:12,916:DEBUG:VIRTUAL NODE Alice: Request to create new qubit.
2021-09-22 10:47:12,916:DEBUG:VIRTUAL NODE Alice: Local GETTING LOCK
2021-09-22 10:47:12,916:DEBUG:VIRTUAL NODE Alice: Local GOT LOCK
2021-09-22 10:47:12,917:DEBUG:VIRTUAL NODE Alice: Local GETTING LOCK
2021-09-22 10:47:12,917:DEBUG:VIRTUAL NODE Alice: Initializing new simulated register.
2021-09-22 10:47:12,917:DEBUG:VIRTUAL NODE Alice: Local RELEASE LOCK
2021-09-22 10:47:12,917:DEBUG:VIRTUAL NODE Alice: Local GOT LOCK
2021-09-22 10:47:12,918:INFO:QUANTUM Alice: Adding qubit number 0 to register 1
2021-09-22 10:47:12,918:DEBUG:VIRTUAL NODE Alice: Local RELEASE LOCK
2021-09-22 10:47:12,918:INFO:CQC Alice: Requested new qubit (0,2)
2021-09-22 10:47:12,919:DEBUG:CQC Alice: apply_H on App ID 0 to qubit id 1
2021-09-22 10:47:12,919:DEBUG:VIRTUAL NODE Alice: applying H to number 0
2021-09-22 10:47:12,920:DEBUG:CQC Alice: Applying cnot_onto to App ID 0 qubit id 1 target 2
2021-09-22 10:47:12,922:DEBUG:VIRTUAL NODE Alice: Doing 2 qubit gate name cnot_onto and local call remote_cnot_onto
2021-09-22 10:47:12,922:DEBUG:VIRTUAL NODE Alice: Local GETTING LOCK
2021-09-22 10:47:12,922:DEBUG:VIRTUAL NODE Alice: Local GOT LOCK
2021-09-22 10:47:12,923:DEBUG:VIRTUAL NODE Alice: 2qubit command demands register merge.
2021-09-22 10:47:12,923:DEBUG:VIRTUAL NODE Alice: Request to merge local register for qubits simNum 0 and simNum 1.
2021-09-22 10:47:12,923:DEBUG:VIRTUAL NODE Alice: Request to merge LOCKS PRESENT
2021-09-22 10:47:12,923:DEBUG:VIRTUAL NODE Alice: Request to merge local register: need merge
2021-09-22 10:47:12,923:DEBUG:VIRTUAL NODE Alice: Updating register 0 to 1.
2021-09-22 10:47:12,923:DEBUG:VIRTUAL NODE Alice: CNOT from 0 to 1
2021-09-22 10:47:12,924:DEBUG:VIRTUAL NODE Alice: Local RELEASE LOCK
2021-09-22 10:47:12,924:DEBUG:VIRTUAL NODE Alice: Local RELEASE LOCK
2021-09-22 10:47:12,926:DEBUG:VIRTUAL NODE Alice: Request to send qubit sim Num 1 to Bob.
2021-09-22 10:47:12,926:DEBUG:VIRTUAL NODE Alice: Local GETTING LOCK
2021-09-22 10:47:12,926:DEBUG:VIRTUAL NODE Alice: Local GOT LOCK
2021-09-22 10:47:12,926:DEBUG:VIRTUAL NODE Alice: Sending qubit simulated locally
2021-09-22 10:47:12,927:DEBUG:VIRTUAL NODE Bob: Request to add qubit from Alice.
2021-09-22 10:47:12,928:DEBUG:VIRTUAL NODE Bob: Local GETTING LOCK
2021-09-22 10:47:12,928:DEBUG:VIRTUAL NODE Bob: Local GOT LOCK
2021-09-22 10:47:12,928:DEBUG:VIRTUAL NODE Bob: Local RELEASE LOCK
2021-09-22 10:47:12,929:DEBUG:VIRTUAL NODE Alice: Local RELEASE LOCK
2021-09-22 10:47:12,930:DEBUG:VIRTUAL NODE Bob: Added a qubit for app id 0 to epr list
2021-09-22 10:47:12,933:DEBUG:CQC Alice: Sent App ID 0 half a EPR pair as qubit id 2 to Bob
2021-09-22 10:47:12,933:DEBUG:CQC Alice: Notify Extra Qubit header. qubit id: 1 
2021-09-22 10:47:12,933:DEBUG:CQC Alice: Entanglement information A: (2130706433, 8005, 0) B: (2130706433, 8009, 0) Entanglement ID: 0 Timestamp: 1632300432 Time of Goodness: 1632300432 Goodness: 0 Directionality Flag: 1
2021-09-22 10:47:12,933:DEBUG:CQC Alice: EPR Pair ID 0 qubit id 0
2021-09-22 10:47:12,934:DEBUG:CQC Alice: Command successful, sent done.
2021-09-22 10:47:12,936:DEBUG:CQC Alice: Read CQC Header: CQC Header. Version: 2 Type: 1 App ID: 0 Length: 4
2021-09-22 10:47:12,937:DEBUG:CQC Alice: Command received
2021-09-22 10:47:12,937:DEBUG:CQC Alice got command header Command Header. Qubit ID: 1 Instruction: 23 Notify: True Block: True Action: False
2021-09-22 10:47:12,938:DEBUG:CQC Alice: Executing command: Command Header. Qubit ID: 1 Instruction: 23 Notify: True Block: True Action: False
2021-09-22 10:47:12,938:DEBUG:CQC Alice: Releasing App ID 0 qubit id 1
2021-09-22 10:47:12,979:DEBUG:VIRTUAL NODE Alice: Measuring local qubit
2021-09-22 10:47:12,979:DEBUG:VIRTUAL NODE Alice: Local GETTING LOCK
2021-09-22 10:47:12,979:DEBUG:VIRTUAL NODE Alice: Local GOT LOCK
2021-09-22 10:47:12,979:DEBUG:VIRTUAL NODE Alice: Local RELEASE LOCK
2021-09-22 10:47:12,980:DEBUG:CQC Alice: Command successful, sent done.
2021-09-22 10:47:13,013:DEBUG:VIRTUAL NODE Bob: Trying to retrieve qubit for app id 0 from epr list
2021-09-22 10:47:13,013:DEBUG:VIRTUAL NODE Bob: Returning qubit for app id 0 from epr list
2021-09-22 10:47:13,013:DEBUG:CQC Bob: Qubit received for app_id 0
2021-09-22 10:47:13,014:DEBUG:CQC Bob: Extra Qubit header. qubit id: 1 
2021-09-22 10:47:13,014:DEBUG:CQC Bob: Entanglement information A: (2130706433, 8009, 0) B: (2130706433, 8005, 0) Entanglement ID: 0 Timestamp: 1632300432 Time of Goodness: 1632300432 Goodness: 0 Directionality Flag: 2
2021-09-22 10:47:13,015:DEBUG:CQC Bob: EPR Pair ID 0 qubit id 0
2021-09-22 10:47:13,015:DEBUG:CQC Bob: Command successful, sent done.
2021-09-22 10:47:13,016:DEBUG:CQC Bob: Read CQC Header: CQC Header. Version: 2 Type: 1 App ID: 0 Length: 4
2021-09-22 10:47:13,017:DEBUG:CQC Bob: Command received
2021-09-22 10:47:13,017:DEBUG:CQC Bob got command header Command Header. Qubit ID: 1 Instruction: 23 Notify: True Block: True Action: False
2021-09-22 10:47:13,018:DEBUG:CQC Bob: Executing command: Command Header. Qubit ID: 1 Instruction: 23 Notify: True Block: True Action: False
2021-09-22 10:47:13,018:DEBUG:CQC Bob: Releasing App ID 0 qubit id 1
2021-09-22 10:47:13,031:DEBUG:VIRTUAL NODE Bob: Measuring remote qubit at Alice.
2021-09-22 10:47:13,034:ERROR:VIRTUAL NODE Bob: Cannot remove remote qubit. Error: 'No such qubit to remove'
2021-09-22 10:47:13,035:DEBUG:CQC Bob: Release failed
Traceback (most recent call last):
  File "bobTest.py", line 66, in <module>
    main()
  File "bobTest.py", line 43, in main
    qB = Bob.recvEPR()
  File "/home/bart/repos/qutech/simulaqron-public/CQC-Python/cqc/pythonLib/cqc_handler.py", line 164, in __exit__
    self.close(release_qubits=True)
  File "/home/bart/repos/qutech/simulaqron-public/CQC-Python/cqc/pythonLib/cqc_connection.py", line 230, in close
    super().close()
  File "/home/bart/repos/qutech/simulaqron-public/CQC-Python/cqc/pythonLib/cqc_handler.py", line 396, in close
    q.release()
  File "/home/bart/repos/qutech/simulaqron-public/CQC-Python/cqc/pythonLib/qubit.py", line 493, in release
    self._cqc.put_command(
  File "/home/bart/repos/qutech/simulaqron-public/CQC-Python/cqc/pythonLib/cqc_handler.py", line 277, in put_command
    message = self.readMessage()
  File "/home/bart/repos/qutech/simulaqron-public/CQC-Python/cqc/pythonLib/cqc_connection.py", line 443, in readMessage
    self.check_error(currHeader)
  File "/home/bart/repos/qutech/simulaqron-public/CQC-Python/cqc/pythonLib/cqc_handler.py", line 874, in check_error
    self._errorHandler(hdr.tp)
  File "/home/bart/repos/qutech/simulaqron-public/CQC-Python/cqc/pythonLib/cqc_handler.py", line 880, in _errorHandler
    raise CQCGeneralError("General error")
cqc.pythonLib.util.CQCGeneralError: General error

So there is this No platforms found. Check OpenCL installation! message, but I'm not sure if this is the whole story. Most of the quantum operations seem to be executed fine, except for measuring the remote qubit (Cannot remove remote qubit).

@WrathfulSpatula
Copy link
Author

WrathfulSpatula commented Sep 22, 2021

No platforms found. Check OpenCL installation! is definitely a recognizable Qrack warning. However, at least by PyQrack v0.4.4 (or with the head commit on Qrack's main branch, if building and installing the C++ library from scratch,) I'd expect that this now falls back to pure C++11 CPU simulation, whenever 0 OpenCL devices are present, as the message indicates. This has been tested on (Raspberry Pi 3 and 4) ARMv7 Linux platforms with 0 devices, by v0.4.4, though it should work on any platform.

I'm guessing, that's not the problem. It's likely in the limitations of my support for the SimulaQron backend API, or a mistake I made in indexing or labeling backend instance qubits. I'll have time experiment, tonight, if I can recreate your example.

@WrathfulSpatula
Copy link
Author

Brief update: I didn't realize there was a switch for backend type, in the teleport example. PyQrack encourages a native-quantum-hardware-like interface that can't directly query amplitudes, but, if I least add the conditional branch to say PyQrack won't do that, the teleport example works for me locally. I'm not sure exactly what code I should be testing, if not that example in 574a9f0.

@AckslD
Copy link
Member

AckslD commented Sep 25, 2021

@WrathfulSpatula The teleport example @bvdvecht refers to is here and not the one in this repo. The ones here using the native mode which was basically only used in the development phase. However the intended way to interact with simulaqron it throught the CQC interface where there are modules in python, c, rust and others to more easily write applications.

@WrathfulSpatula
Copy link
Author

@AckslD Thank you for directing me to the right example. This probably doesn't help you folks much, but that example runs fine on my local machine with PyQrack as the backend simulator. (Honestly, to be sure that SimulaQron was actually using my configuration files with pyqrack selected, I tried removing "Bob" from the network definition, and that prevented the creation of a "Bob" node in that example, so it looks like my local configuration with pyqrack backend is being used.)

If that's the case, I'm guessing there's a problem with the compatibility of the Qrack binary's build options and your machine. Even though all binaries are built with OpenCL support, it should be from v0.4.4 of PyQrack on that systems with 0 OpenCL devices will automatically fall back to CPU-only simulation. I've tested this several times in the course of the past few days with two models of Raspberry Pi, 3 and 4.

If there is at least one OpenCL device on the system, you might want to delete the ~/.qrack directory, in your user home directory, location depending on system. This is where pre-compiled OpenCL programs specific to the system's OpenCL devices are stored. However, unless you used the qrack_cl_precompile utility at some point, this directory and its content probably don't even exist on your system.

This would surprise me, but it's possible your CPU doesn't have the RDRAND instruction. By default, Qrack uses this (on-chip hardware RNG) x86_64 instruction for random number generation. Hopefully, if the instruction isn't present, Qrack should fall back to (software-based) Mersenne Twister. However, the detection process for software fall-back could go wrong, depending on the system implementation. If this were actually the case, users would be expected to build Qrack from source, to support PyQrack, with -DENABLE_RDRAND=OFF in the CMake build options.

Running into the RDRAND case would be a first for me, and I hope I'm not misleading you with it. But, the point is, for a system with 0 OpenCL devices, and any kind of architecture that I might consider exotic, users would generally build Qrack from source to provide a binary for PyQrack. Also, we're pure C++11 standard, (established in 2011,) we have 0 dependencies besides optional OpenCL, and we've tested builds on systems including Android and iOS, so your system is supported, in all likelihood, by careful design of the Qrack framework, but you still might need a custom binary build, if I can help in any way.

@bvdvecht
Copy link
Contributor

Thanks for the pointers. I actually installed OpenCL now on my system (Ubuntu 20.04). (clinfo tells me that number of platforms is 1). Still I'm getting errors when running the teleport example from CQC-Python. What I do exactly is:

cd CQC-Python/examples/pythonLib/teleport
simulaqron set log-level 10
simulaqron set backend pyqrack
simulaqron start
./run.sh

after which I get the following:

2021-09-27 18:02:14,428:DEBUG:CQC Bob: Read CQC Header: CQC Header. Version: 2 Type: 1 App ID: 0 Length: 4
2021-09-27 18:02:14,428:DEBUG:CQC Bob: Command received
2021-09-27 18:02:14,429:DEBUG:CQC Bob got command header Command Header. Qubit ID: 0 Instruction: 8 Notify: True Block: True Action: False
2021-09-27 18:02:14,429:DEBUG:CQC Bob: Executing command: Command Header. Qubit ID: 0 Instruction: 8 Notify: True Block: True Action: False
2021-09-27 18:02:14,429:DEBUG:CQC Bob: Asking to receive for App ID 0
2021-09-27 18:02:14,429:DEBUG:VIRTUAL NODE Bob: Trying to retrieve qubit for app id 0 from epr list
2021-09-27 18:02:14,433:DEBUG:CQC Alice: Initialized Protocol
2021-09-27 18:02:14,433:DEBUG:CQC Alice: Read CQC Header: CQC Header. Version: 2 Type: 1 App ID: 0 Length: 12
2021-09-27 18:02:14,433:DEBUG:CQC Alice: Command received
2021-09-27 18:02:14,434:DEBUG:CQC Alice got command header Command Header. Qubit ID: 0 Instruction: 7 Notify: True Block: True Action: False
2021-09-27 18:02:14,434:DEBUG:CQC Alice: Read XTRA Header: Communication header. Remote App ID: 0 Remote Node: 2130706433 Remote Port: 8004 
2021-09-27 18:02:14,434:DEBUG:CQC Alice: Executing command: Command Header. Qubit ID: 0 Instruction: 7 Notify: True Block: True Action: False
2021-09-27 18:02:14,435:DEBUG:VIRTUAL NODE Alice: Request to create new qubit.
2021-09-27 18:02:14,435:DEBUG:VIRTUAL NODE Alice: Local GETTING LOCK
2021-09-27 18:02:14,435:DEBUG:VIRTUAL NODE Alice: Local GOT LOCK
2021-09-27 18:02:14,435:DEBUG:VIRTUAL NODE Alice: Local GETTING LOCK
2021-09-27 18:02:14,435:DEBUG:VIRTUAL NODE Alice: Initializing new simulated register.
2021-09-27 18:02:14,435:DEBUG:VIRTUAL NODE Alice: Local RELEASE LOCK
2021-09-27 18:02:14,435:DEBUG:VIRTUAL NODE Alice: Local GOT LOCK
2021-09-27 18:02:14,531:DEBUG:VIRTUAL NODE Bob: Trying to retrieve qubit for app id 0 from epr list
2021-09-27 18:02:14,633:DEBUG:VIRTUAL NODE Bob: Trying to retrieve qubit for app id 0 from epr list
2021-09-27 18:02:14,736:DEBUG:VIRTUAL NODE Bob: Trying to retrieve qubit for app id 0 from epr list
2021-09-27 18:02:14,837:DEBUG:VIRTUAL NODE Bob: Trying to retrieve qubit for app id 0 from epr list
2021-09-27 18:02:14,939:DEBUG:VIRTUAL NODE Bob: Trying to retrieve qubit for app id 0 from epr list
Device #0, Built JIT.
2021-09-27 18:02:15,040:DEBUG:VIRTUAL NODE Bob: Trying to retrieve qubit for app id 0 from epr list
2021-09-27 18:02:15,141:DEBUG:VIRTUAL NODE Bob: Trying to retrieve qubit for app id 0 from epr list
2021-09-27 18:02:15,242:DEBUG:VIRTUAL NODE Bob: Trying to retrieve qubit for app id 0 from epr list
2021-09-27 18:02:15,343:DEBUG:VIRTUAL NODE Bob: Trying to retrieve qubit for app id 0 from epr list
2021-09-27 18:02:15,444:DEBUG:VIRTUAL NODE Bob: Trying to retrieve qubit for app id 0 from epr list
2021-09-27 18:02:15,545:DEBUG:VIRTUAL NODE Bob: Trying to retrieve qubit for app id 0 from epr list
2021-09-27 18:02:15,646:DEBUG:VIRTUAL NODE Bob: Trying to retrieve qubit for app id 0 from epr list
2021-09-27 18:02:15,747:DEBUG:VIRTUAL NODE Bob: Trying to retrieve qubit for app id 0 from epr list
2021-09-27 18:02:15,848:DEBUG:VIRTUAL NODE Bob: Trying to retrieve qubit for app id 0 from epr list
2021-09-27 18:02:15,949:DEBUG:VIRTUAL NODE Bob: Trying to retrieve qubit for app id 0 from epr list
2021-09-27 18:02:16,050:DEBUG:VIRTUAL NODE Bob: Trying to retrieve qubit for app id 0 from epr list
2021-09-27 18:02:16,151:DEBUG:VIRTUAL NODE Bob: Trying to retrieve qubit for app id 0 from epr list
2021-09-27 18:02:16,252:DEBUG:VIRTUAL NODE Bob: Trying to retrieve qubit for app id 0 from epr list
2021-09-27 18:02:16,353:DEBUG:VIRTUAL NODE Bob: Trying to retrieve qubit for app id 0 from epr list
Default platform: Intel(R) OpenCL HD Graphics
Default device: Intel(R) Gen9 HD Graphics NEO
OpenCL device #0: Intel(R) Gen9 HD Graphics NEO
2021-09-27 18:02:16,358:INFO:QUANTUM Alice: Adding qubit number 0 to register 0
2021-09-27 18:02:16,358:DEBUG:VIRTUAL NODE Alice: Local RELEASE LOCK
2021-09-27 18:02:16,359:INFO:CQC Alice: Requested new qubit (0,1)
2021-09-27 18:02:16,360:DEBUG:VIRTUAL NODE Alice: Request to create new qubit.
2021-09-27 18:02:16,360:DEBUG:VIRTUAL NODE Alice: Local GETTING LOCK
2021-09-27 18:02:16,361:DEBUG:VIRTUAL NODE Alice: Local GOT LOCK
2021-09-27 18:02:16,361:DEBUG:VIRTUAL NODE Alice: Local GETTING LOCK
2021-09-27 18:02:16,362:DEBUG:VIRTUAL NODE Alice: Initializing new simulated register.
2021-09-27 18:02:16,362:DEBUG:VIRTUAL NODE Alice: Local RELEASE LOCK
2021-09-27 18:02:16,362:DEBUG:VIRTUAL NODE Alice: Local GOT LOCK
2021-09-27 18:02:16,362:INFO:QUANTUM Alice: Adding qubit number 0 to register 1
2021-09-27 18:02:16,362:DEBUG:VIRTUAL NODE Alice: Local RELEASE LOCK
2021-09-27 18:02:16,363:INFO:CQC Alice: Requested new qubit (0,2)
2021-09-27 18:02:16,363:DEBUG:CQC Alice: apply_H on App ID 0 to qubit id 1
2021-09-27 18:02:16,364:DEBUG:VIRTUAL NODE Alice: applying H to number 0
2021-09-27 18:02:16,365:DEBUG:CQC Alice: Applying cnot_onto to App ID 0 qubit id 1 target 2
2021-09-27 18:02:16,366:DEBUG:VIRTUAL NODE Alice: Doing 2 qubit gate name cnot_onto and local call remote_cnot_onto
2021-09-27 18:02:16,366:DEBUG:VIRTUAL NODE Alice: Local GETTING LOCK
2021-09-27 18:02:16,366:DEBUG:VIRTUAL NODE Alice: Local GOT LOCK
2021-09-27 18:02:16,367:DEBUG:VIRTUAL NODE Alice: 2qubit command demands register merge.
2021-09-27 18:02:16,367:DEBUG:VIRTUAL NODE Alice: Request to merge local register for qubits simNum 0 and simNum 1.
2021-09-27 18:02:16,367:DEBUG:VIRTUAL NODE Alice: Request to merge LOCKS PRESENT
2021-09-27 18:02:16,367:DEBUG:VIRTUAL NODE Alice: Request to merge local register: need merge
2021-09-27 18:02:16,367:DEBUG:VIRTUAL NODE Alice: Updating register 0 to 1.
2021-09-27 18:02:16,368:DEBUG:VIRTUAL NODE Alice: CNOT from 0 to 1
2021-09-27 18:02:16,368:DEBUG:VIRTUAL NODE Alice: Local RELEASE LOCK
2021-09-27 18:02:16,368:DEBUG:VIRTUAL NODE Alice: Local RELEASE LOCK
2021-09-27 18:02:16,372:DEBUG:VIRTUAL NODE Alice: Request to send qubit sim Num 1 to Bob.
2021-09-27 18:02:16,372:DEBUG:VIRTUAL NODE Alice: Local GETTING LOCK
2021-09-27 18:02:16,372:DEBUG:VIRTUAL NODE Alice: Local GOT LOCK
2021-09-27 18:02:16,373:DEBUG:VIRTUAL NODE Alice: Sending qubit simulated locally
2021-09-27 18:02:16,373:DEBUG:VIRTUAL NODE Bob: Request to add qubit from Alice.
2021-09-27 18:02:16,374:DEBUG:VIRTUAL NODE Bob: Local GETTING LOCK
2021-09-27 18:02:16,374:DEBUG:VIRTUAL NODE Bob: Local GOT LOCK
2021-09-27 18:02:16,374:DEBUG:VIRTUAL NODE Bob: Local RELEASE LOCK
2021-09-27 18:02:16,374:DEBUG:VIRTUAL NODE Alice: Local RELEASE LOCK
2021-09-27 18:02:16,375:DEBUG:VIRTUAL NODE Bob: Added a qubit for app id 0 to epr list
2021-09-27 18:02:16,376:DEBUG:CQC Alice: Sent App ID 0 half a EPR pair as qubit id 2 to Bob
2021-09-27 18:02:16,377:DEBUG:CQC Alice: Notify Extra Qubit header. qubit id: 1 
2021-09-27 18:02:16,377:DEBUG:CQC Alice: Entanglement information A: (2130706433, 8001, 0) B: (2130706433, 8004, 0) Entanglement ID: 0 Timestamp: 1632758536 Time of Goodness: 1632758536 Goodness: 0 Directionality Flag: 1
2021-09-27 18:02:16,377:DEBUG:CQC Alice: EPR Pair ID 0 qubit id 0
2021-09-27 18:02:16,377:DEBUG:CQC Alice: Command successful, sent done.
2021-09-27 18:02:16,378:DEBUG:CQC Alice: Read CQC Header: CQC Header. Version: 2 Type: 1 App ID: 0 Length: 4
2021-09-27 18:02:16,379:DEBUG:CQC Alice: Command received
2021-09-27 18:02:16,379:DEBUG:CQC Alice got command header Command Header. Qubit ID: 0 Instruction: 1 Notify: True Block: True Action: False
2021-09-27 18:02:16,381:DEBUG:CQC Alice: Executing command: Command Header. Qubit ID: 0 Instruction: 1 Notify: True Block: True Action: False
2021-09-27 18:02:16,382:DEBUG:VIRTUAL NODE Alice: Request to create new qubit.
2021-09-27 18:02:16,382:DEBUG:VIRTUAL NODE Alice: Local GETTING LOCK
2021-09-27 18:02:16,382:DEBUG:VIRTUAL NODE Alice: Local GOT LOCK
2021-09-27 18:02:16,383:DEBUG:VIRTUAL NODE Alice: Local GETTING LOCK
2021-09-27 18:02:16,383:DEBUG:VIRTUAL NODE Alice: Initializing new simulated register.
2021-09-27 18:02:16,383:DEBUG:VIRTUAL NODE Alice: Local RELEASE LOCK
2021-09-27 18:02:16,383:DEBUG:VIRTUAL NODE Alice: Local GOT LOCK
2021-09-27 18:02:16,383:INFO:QUANTUM Alice: Adding qubit number 0 to register 2
2021-09-27 18:02:16,383:DEBUG:VIRTUAL NODE Alice: Local RELEASE LOCK
2021-09-27 18:02:16,384:INFO:CQC Alice: Requested new qubit (0,2)
2021-09-27 18:02:16,384:INFO:CQC Alice: Extra Qubit header. qubit id: 2 
2021-09-27 18:02:16,385:DEBUG:CQC Alice: Command successful, sent done.
2021-09-27 18:02:16,386:DEBUG:CQC Alice: Read CQC Header: CQC Header. Version: 2 Type: 1 App ID: 0 Length: 4
2021-09-27 18:02:16,386:DEBUG:CQC Alice: Command received
2021-09-27 18:02:16,386:DEBUG:CQC Alice got command header Command Header. Qubit ID: 2 Instruction: 17 Notify: True Block: True Action: False
2021-09-27 18:02:16,387:DEBUG:CQC Alice: Executing command: Command Header. Qubit ID: 2 Instruction: 17 Notify: True Block: True Action: False
2021-09-27 18:02:16,387:DEBUG:CQC Alice: apply_H on App ID 0 to qubit id 2
2021-09-27 18:02:16,388:DEBUG:VIRTUAL NODE Alice: applying H to number 0
2021-09-27 18:02:16,388:DEBUG:CQC Alice: Command successful, sent done.
2021-09-27 18:02:16,389:DEBUG:CQC Alice: Read CQC Header: CQC Header. Version: 2 Type: 1 App ID: 0 Length: 6
2021-09-27 18:02:16,389:DEBUG:CQC Alice: Command received
2021-09-27 18:02:16,389:DEBUG:CQC Alice got command header Command Header. Qubit ID: 2 Instruction: 20 Notify: True Block: True Action: False
2021-09-27 18:02:16,390:DEBUG:CQC Alice: Read XTRA Header: Extra Qubit header. qubit id: 1 
2021-09-27 18:02:16,390:DEBUG:CQC Alice: Executing command: Command Header. Qubit ID: 2 Instruction: 20 Notify: True Block: True Action: False
2021-09-27 18:02:16,390:DEBUG:CQC Alice: Applying cnot_onto to App ID 0 qubit id 2 target 1
2021-09-27 18:02:16,391:DEBUG:VIRTUAL NODE Alice: Doing 2 qubit gate name cnot_onto and local call remote_cnot_onto
2021-09-27 18:02:16,391:DEBUG:VIRTUAL NODE Alice: Local GETTING LOCK
2021-09-27 18:02:16,391:DEBUG:VIRTUAL NODE Alice: Local GOT LOCK
2021-09-27 18:02:16,392:DEBUG:VIRTUAL NODE Alice: 2qubit command demands register merge.
2021-09-27 18:02:16,392:DEBUG:VIRTUAL NODE Alice: Request to merge local register for qubits simNum 2 and simNum 0.
2021-09-27 18:02:16,392:DEBUG:VIRTUAL NODE Alice: Request to merge LOCKS PRESENT
2021-09-27 18:02:16,392:DEBUG:VIRTUAL NODE Alice: Request to merge local register: need merge
2021-09-27 18:02:16,393:DEBUG:VIRTUAL NODE Alice: Updating register 0 to 1.
2021-09-27 18:02:16,393:DEBUG:VIRTUAL NODE Alice: Updating register 1 to 2.
2021-09-27 18:02:16,394:DEBUG:VIRTUAL NODE Alice: CNOT from 0 to 1
2021-09-27 18:02:16,394:DEBUG:VIRTUAL NODE Alice: Local RELEASE LOCK
2021-09-27 18:02:16,395:DEBUG:VIRTUAL NODE Alice: Local RELEASE LOCK
2021-09-27 18:02:16,396:DEBUG:CQC Alice: Command successful, sent done.
2021-09-27 18:02:16,397:DEBUG:CQC Alice: Read CQC Header: CQC Header. Version: 2 Type: 1 App ID: 0 Length: 4
2021-09-27 18:02:16,397:DEBUG:CQC Alice: Command received
2021-09-27 18:02:16,397:DEBUG:CQC Alice got command header Command Header. Qubit ID: 2 Instruction: 17 Notify: True Block: True Action: False
2021-09-27 18:02:16,397:DEBUG:CQC Alice: Executing command: Command Header. Qubit ID: 2 Instruction: 17 Notify: True Block: True Action: False
2021-09-27 18:02:16,397:DEBUG:CQC Alice: apply_H on App ID 0 to qubit id 2
2021-09-27 18:02:16,398:DEBUG:VIRTUAL NODE Alice: applying H to number 0
2021-09-27 18:02:16,415:DEBUG:CQC Alice: Command successful, sent done.
2021-09-27 18:02:16,416:DEBUG:CQC Alice: Read CQC Header: CQC Header. Version: 2 Type: 1 App ID: 0 Length: 8
2021-09-27 18:02:16,416:DEBUG:CQC Alice: Command received
2021-09-27 18:02:16,416:DEBUG:CQC Alice got command header Command Header. Qubit ID: 2 Instruction: 2 Notify: False Block: True Action: False
2021-09-27 18:02:16,416:DEBUG:CQC Alice: Read XTRA Header: CQC Assign sub header. RefID=0
2021-09-27 18:02:16,416:DEBUG:CQC Alice: Executing command: Command Header. Qubit ID: 2 Instruction: 2 Notify: False Block: True Action: False
2021-09-27 18:02:16,416:DEBUG:CQC Alice: Measuring App ID 0 qubit id 2
2021-09-27 18:02:16,417:DEBUG:VIRTUAL NODE Alice: Measuring local qubit
2021-09-27 18:02:16,418:DEBUG:VIRTUAL NODE Alice: Local GETTING LOCK
2021-09-27 18:02:16,418:DEBUG:VIRTUAL NODE Alice: Local GOT LOCK
2021-09-27 18:02:16,419:DEBUG:VIRTUAL NODE Alice: Local RELEASE LOCK
2021-09-27 18:02:16,420:DEBUG:CQC Alice: Measured outcome 1
2021-09-27 18:02:16,421:DEBUG:CQC Alice: Notify Measurement Outcome header. measurement outcome: 1 
2021-09-27 18:02:16,422:DEBUG:CQC Alice: Read CQC Header: CQC Header. Version: 2 Type: 1 App ID: 0 Length: 8
2021-09-27 18:02:16,422:DEBUG:CQC Alice: Command received
2021-09-27 18:02:16,422:DEBUG:CQC Alice got command header Command Header. Qubit ID: 1 Instruction: 2 Notify: False Block: True Action: False
2021-09-27 18:02:16,422:DEBUG:CQC Alice: Read XTRA Header: CQC Assign sub header. RefID=0
2021-09-27 18:02:16,422:DEBUG:CQC Alice: Executing command: Command Header. Qubit ID: 1 Instruction: 2 Notify: False Block: True Action: False
2021-09-27 18:02:16,422:DEBUG:CQC Alice: Measuring App ID 0 qubit id 1
2021-09-27 18:02:16,454:DEBUG:VIRTUAL NODE Bob: Trying to retrieve qubit for app id 0 from epr list
2021-09-27 18:02:16,454:DEBUG:VIRTUAL NODE Bob: Returning qubit for app id 0 from epr list
2021-09-27 18:02:16,455:DEBUG:CQC Bob: Qubit received for app_id 0
2021-09-27 18:02:16,455:DEBUG:CQC Bob: Extra Qubit header. qubit id: 1 
2021-09-27 18:02:16,456:DEBUG:CQC Bob: Entanglement information A: (2130706433, 8004, 0) B: (2130706433, 8001, 0) Entanglement ID: 0 Timestamp: 1632758536 Time of Goodness: 1632758536 Goodness: 0 Directionality Flag: 2
2021-09-27 18:02:16,456:DEBUG:CQC Bob: EPR Pair ID 0 qubit id 0
2021-09-27 18:02:16,456:DEBUG:CQC Bob: Command successful, sent done.
2021-09-27 18:02:16,462:DEBUG:VIRTUAL NODE Alice: Measuring local qubit
2021-09-27 18:02:16,463:ERROR:VIRTUAL NODE Alice: Cannot remove local qubit. Error: 'No such qubit to remove'
2021-09-27 18:02:16,463:WARNING:CQC Alice: Measurement failed
Traceback (most recent call last):
  File "aliceTest.py", line 69, in <module>
    main()
  File "aliceTest.py", line 58, in main
    b = qA.measure()
  File "/home/bart/repos/qutech/simulaqron-public/CQC-Python/cqc/pythonLib/qubit.py", line 457, in measure
    return self._cqc.return_meas_outcome()
  File "/home/bart/repos/qutech/simulaqron-public/CQC-Python/cqc/pythonLib/cqc_connection.py", line 572, in return_meas_outcome
    msg = self.readMessage()
  File "/home/bart/repos/qutech/simulaqron-public/CQC-Python/cqc/pythonLib/cqc_connection.py", line 443, in readMessage
    self.check_error(currHeader)
  File "/home/bart/repos/qutech/simulaqron-public/CQC-Python/cqc/pythonLib/cqc_handler.py", line 874, in check_error
    self._errorHandler(hdr.tp)
  File "/home/bart/repos/qutech/simulaqron-public/CQC-Python/cqc/pythonLib/cqc_handler.py", line 880, in _errorHandler
    raise CQCGeneralError("General error")
cqc.pythonLib.util.CQCGeneralError: General error

@AckslD If you have the time, I would be interested in seeing whether you are able to run this example with the pyqrack backend.

@WrathfulSpatula
Copy link
Author

@bvdvecht I actually hadn't added the CLI backend option for pyqrack, but it looks like you might have made that change in your local copy. ed356ca adds it. As a sanity check, if I type your exact commands as above, I don't even see the logs, and I'm not sure if that's a problem on my end, but run.sh exits without exception.

@WrathfulSpatula
Copy link
Author

I just updated this to fix the conflicts with upstream work. Is there anything I can furnish, to help here? Occasionally, certain systems will benefit from a custom source build of the underlying C++ Qrack libraries, depending on hardware capabilities, and I wasn't sure if that might have been the case in the original tests we previously discussed, but most consumer systems should be fine with just default PyPi-distributed PyQrack, particularly by version v0.8.2, if you upgrade.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants