# Path: qflexcirq/ordering/order_circuit_simulation.py
# def powerset(iterable):
#     def __init__(self, nodes):
#     def dim(self):
#     def add_op(self, op):
#     def swap_nodes(self, old_nodes, new_nodes):
#     def get_remote_bonds(self):
#     def get_remote_nodes(self):
#     def get_cost(self):
#     def __hash__(self):
#     def __eq__(self, other):
#     def __repr__(self):
#     def __str__(self):
#     def __init__(self, qubits):
#     def rank(self):
#     def add_bond(self, bond):
#     def remove_bond(self, bond):
#     def __hash__(self):
#     def __eq__(self, other):
#     def __init__(self, qubits):
#     def create_node(self, qubits):
#     def add_bond(self, qubits, op):
#     def update_bonds(self, bonds):
#     def contract(self, bond):
# def create_ordering_data(
#     contraction_steps: Iterable[cirq.ops.raw_types.Operation],
#     qubit_names: Iterable[int], qubit_order: Tuple[cirq.ops.raw_types.Qid,
#                                                    ...]):
# def get_steps_for_graph(g: Graph):
# def match_fidelity(target_fidelity: float, cuts: Dict[frozenset, int]):
# def circuit_to_ordering(
#     circuit: cirq.circuits.Circuit,
#     qubit_names: Iterable[int] = None,
#     qubit_order_method: cirq.ops.QubitOrderOrList = cirq.ops.QubitOrder.DEFAULT,
#     max_cuts: int = 2,
#     fidelity: float = 1.0):
# class Bond:
# class Node:
# class Graph:


import random
import cirq
import pytest
import sys
from qflexcirq.ordering import order_circuit_simulation as order_lib


def test_max_cuts_negative_fails():
    """Tests the circuit-to-ordering conversion."""
    qubits = [cirq.GridQubit(0, 0), cirq.GridQubit(0, 1)]
    size = 4
    for x in range(size):
        qubits.append([cirq.GridQubit(x, y) for y in range(size)])

    moments = (cirq.Moment([cirq.CZ(qubits[0], qubits[1])]),
               cirq.Moment([cirq.CZ(qubits[0], qubits[1])]))
    circuit = cirq.Circuit(moments)

    # max_cuts cannot be less than zero.
    with pytest.raises(ValueError):
        order_lib.circuit_to_ordering(circuit=circuit, max_cuts=-1)


def test_max_cuts_zero_succeeds():
    """Tests the circuit-to-ordering conversion."""
    qubits = [cirq.GridQubit(0, 0), cirq.GridQubit(0, 1)]
    size = 4
    for x in range(size):
        qubits.append([cirq.GridQubit(x, y) for y in range(size)])

    moments = (cirq.Moment([cirq.CZ(qubits[0], qubits[1])]),
               cirq.Moment([cirq.CZ(qubits[0], qubits[1])]))
    circuit = cirq.Circuit(moments)

    # max_cuts of zero will generate an ordering.

# Path: qflexcirq/ordering/order_circuit_simulation.py
# def powerset(iterable):
#     def __init__(self, nodes):
#     def dim(self):
#     def add_op(self, op):
#     def swap_nodes(self, old_nodes, new_nodes):
#     def get_remote_bonds(self):
#     def get_remote_nodes(self):
#     def get_cost(self):
#     def __hash__(self):
#     def __eq__(self, other):
#     def __repr__(self):
#     def __str__(self):
#     def __init__(self, qubits):
#     def rank(self):
#     def add_bond(self, bond):
#     def remove_bond(self, bond):
#     def __hash__(self):
#     def __eq__(self, other):
#     def __init__(self, qubits):
#     def create_node(self, qubits):
#     def add_bond(self, qubits, op):
#     def update_bonds(self, bonds):
#     def contract(self, bond):
# def create_ordering_data(
#     contraction_steps: Iterable[cirq.ops.raw_types.Operation],
#     qubit_names: Iterable[int], qubit_order: Tuple[cirq.ops.raw_types.Qid,
#                                                    ...]):
# def get_steps_for_graph(g: Graph):
# def match_fidelity(target_fidelity: float, cuts: Dict[frozenset, int]):
# def circuit_to_ordering(
#     circuit: cirq.circuits.Circuit,
#     qubit_names: Iterable[int] = None,
#     qubit_order_method: cirq.ops.QubitOrderOrList = cirq.ops.QubitOrder.DEFAULT,
#     max_cuts: int = 2,
#     fidelity: float = 1.0):
# class Bond:
# class Node:
# class Graph:


# Path: tests/python/order_circuit_simulation_test.py
import random
import cirq
import pytest
import sys
from qflexcirq.ordering import order_circuit_simulation as order_lib



def test_max_cuts_negative_fails():
    """Tests the circuit-to-ordering conversion."""
    qubits = [cirq.GridQubit(0, 0), cirq.GridQubit(0, 1)]
    size = 4
    for x in range(size):
        qubits.append([cirq.GridQubit(x, y) for y in range(size)])

    moments = (cirq.Moment([cirq.CZ(qubits[0], qubits[1])]),
               cirq.Moment([cirq.CZ(qubits[0], qubits[1])]))
    circuit = cirq.Circuit(moments)

    # max_cuts cannot be less than zero.
    with pytest.raises(ValueError):
        order_lib.circuit_to_ordering(circuit=circuit, max_cuts=-1)


def test_max_cuts_zero_succeeds():
    """Tests the circuit-to-ordering conversion."""
    qubits = [cirq.GridQubit(0, 0), cirq.GridQubit(0, 1)]
    size = 4
    for x in range(size):
        qubits.append([cirq.GridQubit(x, y) for y in range(size)])

    moments = (cirq.Moment([cirq.CZ(qubits[0], qubits[1])]),
               cirq.Moment([cirq.CZ(qubits[0], qubits[1])]))
    circuit = cirq.Circuit(moments)

    # max_cuts of zero will generate an ordering.

    order = order_lib.circuit_to_ordering(circuit=circuit, max_cuts=0)