Skip to content

Commit

Permalink
Fix status display for qubits with no effects
Browse files Browse the repository at this point in the history
It is confusing how the status display doesn't show qubits that don't
have any effects on them. To fix this, specify a qubit order for the
diagram, which allows us to force unused qubits to be included.
  • Loading branch information
losos0 committed Aug 29, 2023
1 parent f3b9cde commit 012bfe5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
10 changes: 9 additions & 1 deletion unitary/examples/quantum_rpg/qaracter.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,22 @@ def is_active(self) -> bool:
"""Returns True if the Qaracter is not down yet and there are HPs left to measure."""
return not self.is_down() and len(self.health_status) < self.level

def qar_sheet(self) -> str:
"""Generates a Unicode-art diagram of the qaracter's circuit."""
all_qubits = [
self.get_object_by_name(self.quantum_object_name(i)).qubit
for i in range(1, self.level + 1)
]
return self.circuit.to_text_diagram(qubit_order=all_qubits)

def qar_status(self) -> str:
"""Prints out the qaracter's name/class/level and circuit.
Used for the STATUS command.
"""
return (
f"{self.name}: Level {self.level} {self.class_name}"
f"\nQaracter sheet:\n{self.circuit}"
f"\nQaracter sheet:\n{self.qar_sheet()}"
)

def status_line(self) -> str:
Expand Down
2 changes: 1 addition & 1 deletion unitary/examples/quantum_rpg/xp_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def award_xp(
)
qar = eligible_party[qar_choice - 1]
print("Current qaracter sheet:", file=state.file)
print(qar.circuit, file=state.file)
print(qar.qar_sheet(), file=state.file)
qubit_list = list(qar.active_qubits())
qubit_choices = []
for qubit_num in range(num_qubits):
Expand Down
8 changes: 6 additions & 2 deletions unitary/examples/quantum_rpg/xp_utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ def test_award_xp():
Choose the qaracter to add the Superposition to:
1) wizard: Level 1 Analyst
Qaracter sheet:
wizard_1: ───
Current qaracter sheet:
wizard_1: ───
Choose qubit 0 for Superposition:
1) wizard_1
"""
Expand All @@ -83,9 +83,13 @@ def test_award_xp_multi_qubit_gate():
Choose the qaracter to add the Move to:
1) wizard: Level 2 Analyst
Qaracter sheet:
wizard_1: ───
wizard_2: ───
Current qaracter sheet:
wizard_1: ───
wizard_2: ───
Choose qubit 0 for Move:
1) wizard_1
2) wizard_2
Expand Down

0 comments on commit 012bfe5

Please sign in to comment.