Esempio n. 1
0
 def test_qmor(self):
     """
     Tests whether qmor is the same
     as 2 qor gates
     """
     a = qbool(self.qlcass, prob=0.7)
     b = qbool(self.qclass, prob=0.4)
     c = qbool(self.qclass, prob=0.9)
     control = [b, c]
     result = a.qmor(control)
     self.assertListEqual(control, [b, c])
     other = a.qmor(b).qmor(c)
     result.measure()
     other.measure()
     counts = self.qclass.get_counts()
     resultCounts = result.extract_counts(counts)
     otherCounts = other.extract_counts()
     toTest = []
     for k, v in resultCounts.items():
         try:
             otherVal = otherCounts[k]
             toTest.append((v, otherVal))
         except KeyError:
             toTest.append((v, 0))
     self.assertTrue(kinda_close_tuples(toTest))
Esempio n. 2
0
 def test_free(self):
     """
     Tests whether free returns the qubit
     """
     a = qbool(self.qclass, prob=0.7)
     b = qbool(self.qclass, prob=0.35)
     c = a.qand(b)
     c.iqand(a, b)
     before = self.qclass.bitsLeft
     c.free()
     self.assertEqual(self.qclass.bitsLeft, before + 1)
Esempio n. 3
0
 def test_qif(self):
     """
     Tests whether qif works properly
     """
     a = qbool(self.qclass, prob=0.5)
     b = qbool(self.qclass, prob=0.5)
     c = a.qif(b)
     c.measure()
     counts = self.qclass.get_counts()
     counts = c.extract_counts(counts)
     self.assertTrue([(counts[True], 0.75), (counts[False], 0.25)])
Esempio n. 4
0
 def test_qnand(self):
     """
     Tests the qnand on 2 independent qbools
     """
     a = qbool(self.qclass, prob=0.5)
     b = qbool(self.qclass, prob=0.5)
     c = a.qnand(b)
     c.measure()
     counts = self.qclass.get_counts()
     counts = c.extract_counts(counts)
     self.assertTrue([(counts[True], 0.75), (counts[False], 0.25)])
Esempio n. 5
0
 def test_qor(self):
     """
     Tests whether qor properly ors 
     independent qbools
     """
     a = qbool(self.qclass, prob=0.5)
     b = qbool(self.qclass, prob=0.5)
     c = a.qor(b)
     c.measure()
     counts = self.qclass.get_counts()
     counts = c.extract_counts(counts)
     self.assertTrue([(counts[True], 0.75), (counts[False], 0.25)])
Esempio n. 6
0
 def test_iqif(self):
     """
     Tests whether iqif actually inverts qif
     """
     a = qbool(self.qclass, prob=0.7)
     b = qbool(self.qclass, prob=0.35)
     c = a.qif(b)
     c.iqif(a, b)
     c.measure()
     counts = self.qclass.get_counts()
     counts = c.extract_counts(counts)
     self.assertRaises(
         KeyError,
         counts[True])  #Tests that True is not in the possibilities
     self.assertTrue(False in counts.keys())
Esempio n. 7
0
 def tests_qxor_vs_qiff(self):
     """
     Tests whether qxor is equivalent to 
     not qiff
     """
     a = qbool(self.qclass, prob=0.5)
     b = qbool(self.qclass, prob=0.5)
     c = a.qxor(b)
     d = a.qiff(b)
     c.measure()
     d.measure()
     counts = self.qclass.get_counts()
     ccounts = c.extract_counts(counts)
     dcounts = d.extract_counts(counts)
     self.assertEqual(ccounts[True], dcounts[False])
     self.assertEqual(ccounts[False], dcounts[True])
Esempio n. 8
0
 def test_qnand_vs_qand(self):
     """
     Tests whether qand and qnand are
     opposites
     """
     a = qbool(self.qclass, prob=0.5)
     b = qbool(self.qclass, prob=0.5)
     c = a.qnand(b)
     d = a.qand(b)
     c.measure()
     d.measure()
     counts = self.qclass.get_counts()
     ccounts = c.extract_counts(counts)
     dcounts = d.extract_counts(counts)
     self.assertEqual(ccounts[True], dcounts[False])
     self.assertEqual(ccounts[False], dcounts[True])
Esempio n. 9
0
 def test_qor_entangled(self):
     a = qbool(self.qclass, prob=0.5)
     b = a.entangle()
     c = a.qor(b)
     c.measure()
     counts = self.qclass.get_counts()
     counts = c.extract_counts(counts)
     self.assertTrue([(counts[False], 0.5), (counts[True], 0.5)])
Esempio n. 10
0
 def test_init(self):
     """
     Tests whether initial value is properly assigned
     """
     base = qbool(self.qclass, initial=True)
     base.measure()
     result = self.qclass.get_result()
     self.assertTrue(base.extract_result())
Esempio n. 11
0
 def test_base_is_false(self):
     """
     Tests whether qbool properly initializes to 
     false with no initial value
     """
     base = qbool(self.qclass)
     base.measure()
     result = self.qclass.get_result()
     self.assertFalse(base.extract_result())
Esempio n. 12
0
 def test_qand_entangled(self):
     """
     Tests whether qand properly ands entangled
     qbools
     """
     a = qbool(self.qclass, prob=0.5)
     b = a.entangle()
     c = a.qand(b)
     c.measure()
     counts = self.qclass.get_counts()
     counts = c.extract_counts(counts)
     self.assertTrue([(counts[False], 0.5), (counts[True], 0.5)])
Esempio n. 13
0
 def test_prob(self):
     """
     Tests whether a qbool initialized 
     with a certain probability actually measures close to said prob
     """
     base = qbool(self.qclass, prob=0.75)
     base.measure()
     counts = self.qclass.get_counts()
     counts = base.extract_counts(counts)
     self.assertTrue(
         kinda_close_tuples([(counts[True] / 1024, 0.75),
                             (counts[False] / 1024, 0.25)]))
Esempio n. 14
0
 def test_prob_not(self):
     """
     Tests whether qnot properly
     nots a superposition
     """
     base = qbool(self.qclass, prob=0.75)
     base.qnot()
     base.measure()
     counts = self.qclass.get_counts()
     counts = base.extract_counts(counts)
     self.assertTrue(
         kinda_close_tuples([(counts[True] / 1024, 0.25),
                             (counts[False] / 1024, 0.75)]))
Esempio n. 15
0
 def test_entangle(self):
     """
     Tests whether an entangled qbool works 
     """
     base = qbool(self.qclass, prob=0.5)
     entangled = base.entangle()
     base.measure()
     entangled.measure()
     counts = self.qclass.get_counts()
     baseCounts = base.extract_counts(counts)
     entangledCounts = entangled.extract_counts(counts)
     self.assertEqual(baseCounts[False], entangledCounts[False])
     self.assertEqual(baseCounts[True], entangledCounts[True])