Commit 4b6c8693 authored by Nguyen, Thien Minh's avatar Nguyen, Thien Minh
Browse files

Add compute action test



Signed-off-by: default avatarThien Nguyen <nguyentm@ornl.gov>
parent 6562b688
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -74,3 +74,10 @@ add_test (NAME qcor_python_jit_kernel_signature
set_tests_properties(qcor_python_jit_kernel_signature
  PROPERTIES ENVIRONMENT "PYTHONPATH=${CMAKE_INSTALL_PREFIX}:$ENV{PYTHONPATH}")

add_test (NAME qcor_python_compute_action
  COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_compute_action.py
  WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
set_tests_properties(qcor_python_compute_action
  PROPERTIES ENVIRONMENT "PYTHONPATH=${CMAKE_INSTALL_PREFIX}:$ENV{PYTHONPATH}")
 
 No newline at end of file
+26 −0
Original line number Diff line number Diff line
import faulthandler
faulthandler.enable()

import unittest
from qcor import *

class TestKernelJIT(unittest.TestCase):
  def test_compute_action(self):
    @qjit
    def test_compute_action1(q : qreg, x : float):
      with compute:
        X.ctrl(q[0], q[1])
        for i in range(3):
            H(q[i+1])
      with action:
        Rz(q[3], x)

    q = qalloc(5)
    comp0 = test_compute_action1.extract_composite(q, 1.2345)    
    print(comp0)
    # First and last instructions are CNOT's
    self.assertEqual(comp0.getInstruction(0).name(), "CNOT")  
    self.assertEqual(comp0.getInstruction(comp0.nInstructions() - 1).name(), "CNOT") 

if __name__ == '__main__':
  unittest.main()
 No newline at end of file