Skip to content

Commit

Permalink
[minor] delete logging in tutorial/chapter6; update comments; change …
Browse files Browse the repository at this point in the history
…id to identity in Reservation
  • Loading branch information
caitaozhan committed Aug 26, 2024
1 parent 920ede1 commit 02d4241
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 20 deletions.
11 changes: 2 additions & 9 deletions docs/source/tutorial/chapter6/custom_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def start(self):
event = Event(now + PERIOD, process)
self.node.timeline.schedule(event)

def get_reserve_res(self, reservation: "Reservation", result: bool):
def get_reservation_result(self, reservation: "Reservation", result: bool):
if result:
print("Reservation approved at time", self.node.timeline.now() * 1e-12)
else:
Expand Down Expand Up @@ -84,13 +84,6 @@ def get_memory(self, info):
tl.stop_time = PERIOD * NUM_PERIODS
tl.show_progress = False

log.set_logger(__name__, tl, log_filename)
log.set_logger_level('DEBUG')

modules = ['timeline', 'network_manager', 'resource_manager', 'generation', 'swapping', 'rule_manager']
for module in modules:
log.track_module(module)

start_node_name = "end1"
end_node_name = "end2"
node1 = node2 = None
Expand All @@ -104,7 +97,7 @@ def get_memory(self, info):
memory_size = 1
target_fidelity = 0.6
app = PeriodicApp(node1, end_node_name, memory_size, target_fidelity)
reset_app = ResetApp(node2, start_node_name, memory_size, target_fidelity)
reset_app = ResetApp(node2, start_node_name, target_fidelity)

tl.init()
app.start()
Expand Down
2 changes: 1 addition & 1 deletion sequence/entanglement_management/generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def set_others(self, protocol: str, node: str, memories: List[str]) -> None:
self.primary = self.owner.name > self.remote_node_name

def start(self) -> None:
"""Method to start "one round" in the entanglement generation protocol (two rounds in total, double heralded).
"""Method to start "one round" in the entanglement generation protocol (there are two rounds in Barrett-Kok).
Will start negotiations with other protocol (if primary).
Expand Down
20 changes: 10 additions & 10 deletions sequence/network_management/reservation.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ def __init__(self, owner: "QuantumRouter", name: str, memory_array_name: str):
self.accepted_reservations = []

def push(self, responder: str, start_time: int, end_time: int, memory_size: int, target_fidelity: float,
entanglement_number: int = 1, id: int = 0):
entanglement_number: int = 1, identity: int = 0):
"""Method to receive reservation requests from higher level protocol.
Will evaluate request and determine if node can meet it.
Expand All @@ -349,12 +349,12 @@ def push(self, responder: str, start_time: int, end_time: int, memory_size: int,
memory_size (int): number of memories to be entangled.
target_fidelity (float): desired fidelity of entanglement.
entanglement_number (int): the number of entanglement the request ask for.
id (int): the ID of the request.
identity (int): the ID of the request.
Side Effects:
May push/pop to lower/upper attached protocols (or network manager).
"""

reservation = Reservation(self.owner.name, responder, start_time, end_time, memory_size, target_fidelity, entanglement_number, id)
reservation = Reservation(self.owner.name, responder, start_time, end_time, memory_size, target_fidelity, entanglement_number, identity)
if self.schedule(reservation):
msg = ResourceReservationMessage(RSVPMsgType.REQUEST, self.name, reservation)
qcap = QCap(self.owner.name)
Expand Down Expand Up @@ -596,11 +596,11 @@ class Reservation:
memory_size (int): number of entangled memory pairs requested.
path (list): a list of router names from the source to destination
entanglement_number (int): the number of entanglement pair that the request ask for.
id (int): the ID of a request.
identity (int): the ID of a request.
"""

def __init__(self, initiator: str, responder: str, start_time: int,
end_time: int, memory_size: int, fidelity: float, entanglement_number: int = 1, id: int = 0):
end_time: int, memory_size: int, fidelity: float, entanglement_number: int = 1, identity: int = 0):
"""Constructor for the reservation class.
Args:
Expand All @@ -611,7 +611,7 @@ def __init__(self, initiator: str, responder: str, start_time: int,
memory_size (int): number of entangled memories requested.
fidelity (float): desired fidelity of entanglement.
entanglement_number (int): the number of entanglement the request ask for.
id (int): the ID of a request
identity (int): the ID of a request
"""

self.initiator = initiator
Expand All @@ -621,14 +621,14 @@ def __init__(self, initiator: str, responder: str, start_time: int,
self.memory_size = memory_size
self.fidelity = fidelity
self.entanglement_number = entanglement_number
self.id = id
self.identity = identity
self.path = []
assert self.start_time < self.end_time
assert self.memory_size > 0

def __str__(self) -> str:
s = "|initiator={}; responder={}; start_time={:,}; end_time={:,}; memory_size={}; target_fidelity={}; entanglement_number={}; id={}|".format(
self.initiator, self.responder, int(self.start_time), int(self.end_time), self.memory_size, self.fidelity, self.entanglement_number, self.id)
s = "|initiator={}; responder={}; start_time={:,}; end_time={:,}; memory_size={}; target_fidelity={}; entanglement_number={}; identity={}|".format(
self.initiator, self.responder, int(self.start_time), int(self.end_time), self.memory_size, self.fidelity, self.entanglement_number, self.identity)
return s

def __repr__(self) -> str:
Expand All @@ -646,7 +646,7 @@ def __eq__(self, other: "Reservation") -> bool:
other.fidelity == self.fidelity

def __lt__(self, other: "Reservation") -> bool:
return self.id < other.id
return self.identity < other.identity

def __hash__(self):
return hash((self.initiator, self.responder, self.start_time, self.end_time, self.memory_size, self.fidelity))
Expand Down

0 comments on commit 02d4241

Please # to comment.