Esempio n. 1
0
def test_is_maximalist(circuit):
    dag = cirq.CircuitDag.from_circuit(circuit)
    transitive_closure = networkx.dag.transitive_closure(dag)
    assert cirq.CircuitDag(incoming_graph_data=transitive_closure) == dag
    assert not any(
        dag.has_edge(b, a)
        for a, b in itertools.combinations(dag.ordered_nodes(), 2))
Esempio n. 2
0
def test_append():
    q0 = cirq.LineQubit(0)
    dag = cirq.CircuitDag()
    dag.append(cirq.X(q0))
    dag.append(cirq.Y(q0))
    assert networkx.dag.is_directed_acyclic_graph(dag)
    assert len(dag.nodes()) == 2
    assert [(n1.val, n2.val) for n1, n2 in dag.edges()] == [(cirq.X(q0), cirq.Y(q0))]
Esempio n. 3
0
def test_init():
    with cirq.testing.assert_deprecated('Use cirq contrib.CircuitDag',
                                        deadline='v0.16',
                                        count=1):
        dag = cirq.CircuitDag()
        assert networkx.dag.is_directed_acyclic_graph(dag)
        assert list(dag.nodes()) == []
        assert list(dag.edges()) == []
Esempio n. 4
0
def test_is_maximalist(circuit):
    # This creates a number of Unique classes so the count is not consistent.
    with cirq.testing.assert_deprecated('Use cirq contrib.CircuitDag',
                                        deadline='v0.16',
                                        count=None):
        dag = cirq.CircuitDag.from_circuit(circuit)
        transitive_closure = networkx.dag.transitive_closure(dag)
        assert cirq.CircuitDag(incoming_graph_data=transitive_closure) == dag
        assert not any(
            dag.has_edge(b, a)
            for a, b in itertools.combinations(dag.ordered_nodes(), 2))
Esempio n. 5
0
def test_two_identical_ops():
    q0 = cirq.LineQubit(0)
    dag = cirq.CircuitDag()
    dag.append(cirq.X(q0))
    dag.append(cirq.Y(q0))
    dag.append(cirq.X(q0))
    assert networkx.dag.is_directed_acyclic_graph(dag)
    assert len(dag.nodes) == 3
    assert (set((n1.val, n2.val) for n1, n2 in dag.edges) == set(
        ((cirq.X(q0), cirq.Y(q0)), (cirq.X(q0), cirq.X(q0)), (cirq.Y(q0),
                                                              cirq.X(q0)))))
Esempio n. 6
0
def test_append():
    q0 = cirq.LineQubit(0)
    with cirq.testing.assert_deprecated('Use cirq contrib.CircuitDag',
                                        deadline='v0.16',
                                        count=None):
        dag = cirq.CircuitDag()
        dag.append(cirq.X(q0))
        dag.append(cirq.Y(q0))
        assert networkx.dag.is_directed_acyclic_graph(dag)
        assert len(dag.nodes()) == 2
        assert [(n1.val, n2.val)
                for n1, n2 in dag.edges()] == [(cirq.X(q0), cirq.Y(q0))]
Esempio n. 7
0
def test_init():
    dag = cirq.CircuitDag()
    assert networkx.dag.is_directed_acyclic_graph(dag)
    assert list(dag.nodes) == []
    assert list(dag.edges) == []
Esempio n. 8
0
def test_is_maximalist(circuit):
    dag = cirq.CircuitDag.from_circuit(circuit)
    transitive_closure = networkx.dag.transitive_closure(dag)
    assert cirq.CircuitDag(incoming_graph_data=transitive_closure) == dag
Esempio n. 9
0
def test_device_deprecated():
    dag = cirq.CircuitDag()
    with cirq.testing.assert_deprecated(
        cirq.circuits.circuit._DEVICE_DEP_MESSAGE, deadline='v0.15'
    ):
        _ = dag.device
Esempio n. 10
0
def test_init_device_deprecated():
    with cirq.testing.assert_deprecated(
        cirq.circuits.circuit._DEVICE_DEP_MESSAGE, deadline='v0.15'
    ):
        _ = cirq.CircuitDag(device=cirq.UNCONSTRAINED_DEVICE)