コード例 #1
0
        def collapse(outcome, normalization):
            if outcome:
                not_outcome = 0
            else:
                not_outcome = 1

            q = LifoQueue()
            q.put(
                (self.root, 0)
            )  # Second part of tuple is the current qubit ( depth ). Starts q_0

            while q.qsize() != 0:
                (node, depth) = q.get()
                if (depth < qubit):
                    for i in [0, 1]:
                        q.add((node.conns(i), depth + 1))
                else:
                    node.conns[
                        not_outcome] = None  #Why are these touples again? Isn't that kind of annoying
                    node.weights[not_outcome] = 0
                    node.weights[outcome] /= normalization
コード例 #2
0
'''from collections import deque

deque_1 = deque()
deque_1.append(0)
deque_1.append(1)
deque_1.append(2) ##<--------- This will be the last in

print(deque_1)
print(deque_1.pop())''' ##<------- Last in will be the first out LIFO = Stack

### 3rd Way: Using the LifoQueue which is used for concurrency too

from queue import LifoQueue
lifoqueue = LifoQueue()

lifoqueue.add(1)
lifoqueue.add(2)
lifoqueue.add(3)  ## <---- Last in

print(lifoqueue)
print(lifoqueue.get())  ##<----- Last in will be first out

#import heapq
##heapq.heappush
##heapq.heappop

## from queue import PriorityQueue
## pq = PriorityQueue()
## pq.put()
## pq.get()