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

Using QPP to set the connectivity for unit test



Added vector<pair> to list of supported type variants.

Signed-off-by: default avatarThien Nguyen <nguyentm@ornl.gov>
parent 917ed0d9
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -81,7 +81,9 @@ class KernelArgDictToHeterogeneousMap {
// Add type name to this list to support receiving from Python.
using PyHeterogeneousMapTypes =
    xacc::Variant<bool, int, double, std::string, std::vector<int>,
                  std::shared_ptr<qcor::Optimizer>, std::vector<double>, std::vector<std::vector<double>>>;
                  std::vector<std::pair<int, int>>,
                  std::shared_ptr<qcor::Optimizer>, std::vector<double>,
                  std::vector<std::vector<double>>>;
using PyHeterogeneousMap = std::map<std::string, PyHeterogeneousMapTypes>;

// Helper to convert a Python *dict* (as a map of variants) into a native
+12 −13
Original line number Diff line number Diff line
@@ -23,19 +23,18 @@ class TestKernelJIT(unittest.TestCase):
        self.assertTrue(len(placement_names) > 0)   
        print(placement_names)

    # Don't run this test since it requires remote IBM access.
    # def test_placement(self):
    #     @qjit
    #     def test2(q : qreg):
    #         CX(q[0], q[3])
        
    #     set_qpu('ibm:ibmqx2')
    #     set_placement('swap-shortest-path')
    #     q = qalloc(5)
    #     comp = test2.extract_composite(q)
    #     print(comp)
    #     # This becomes 1 SWAP + 1 CNOT => 4 CNOT's
    #     self.assertEqual(comp.nInstructions(), 4)    
    def test_placement(self):
        @qjit
        def test2(q : qreg):
            CX(q[0], q[3])
        # Define a connectivity topology
        set_qpu('qpp', { 'connectivity': [[0,1], [0,2], [1,2], [2,3], [2,4], [3,4]] })
        set_placement('swap-shortest-path')
        q = qalloc(5)
        comp = test2.extract_composite(q)
        print(comp)
        # This becomes 1 SWAP + 1 CNOT => 4 CNOT's
        self.assertEqual(comp.nInstructions(), 4)    

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