Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor ghz_Circuits Error Handling and Update Random Generator in mirror_circuits #2529

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mitiq/benchmarks/ghz_circuits.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def generate_ghz_circuit(
"""
if n_qubits <= 0:
raise ValueError(
"Cannot prepare a GHZ circuit with {} qubits", n_qubits
f"Cannot prepare a GHZ circuit with {n_qubits} qubits"
)

qubits = cirq.LineQubit.range(n_qubits)
Expand Down
16 changes: 8 additions & 8 deletions mitiq/benchmarks/mirror_circuits.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


def random_paulis(
connectivity_graph: nx.Graph, random_state: random.RandomState
connectivity_graph: nx.Graph, random_state: random.Generator
) -> cirq.Circuit:
"""Returns a circuit with randomly selected Pauli gates on each qubit.

Expand All @@ -33,15 +33,15 @@ def random_paulis(
random.
"""
return cirq.Circuit(
paulis[random_state.randint(len(paulis))](cirq.LineQubit(x))
paulis[random_state.integers(len(paulis))](cirq.LineQubit(x))
for x in connectivity_graph.nodes
)


def edge_grab(
two_qubit_gate_prob: float,
connectivity_graph: nx.Graph,
random_state: random.RandomState,
random_state: random.Generator,
) -> nx.Graph:
"""
Args:
Expand All @@ -63,7 +63,7 @@ def edge_grab(
final_edges.add_nodes_from(connectivity_graph)

while connectivity_graph.edges:
num = random_state.randint(connectivity_graph.size())
num = random_state.integers(connectivity_graph.size())
edges = list(connectivity_graph.edges)
curr_edge = edges[num]
candidate_edges.add_edge(*curr_edge)
Expand All @@ -77,7 +77,7 @@ def edge_grab(

def random_cliffords(
connectivity_graph: nx.Graph,
random_state: random.RandomState,
random_state: random.Generator,
two_qubit_gate: cirq.Gate = cirq.CNOT,
) -> cirq.Circuit:
"""
Expand Down Expand Up @@ -105,7 +105,7 @@ def random_cliffords(


def random_single_cliffords(
connectivity_graph: nx.Graph, random_state: random.RandomState
connectivity_graph: nx.Graph, random_state: random.Generator
) -> cirq.Circuit:
"""
Args:
Expand All @@ -119,7 +119,7 @@ def random_single_cliffords(
"""
gates: List[cirq.Operation] = []
for qubit in connectivity_graph.nodes:
num = random_state.randint(len(cliffords))
num = random_state.integers(len(cliffords))
for clifford_gate in cliffords[num]:
gates.append(clifford_gate(cirq.LineQubit(qubit)))
return cirq.Circuit(gates)
Expand Down Expand Up @@ -164,7 +164,7 @@ def generate_mirror_circuit(
)
two_qubit_gate = supported_two_qubit_gates[two_qubit_gate_name]

random_state = random.RandomState(seed)
random_state = random.default_rng(seed)

single_qubit_cliffords = random_single_cliffords(
connectivity_graph, random_state=random_state
Expand Down
Loading