当前位置: 首页>>代码示例>>Python>>正文


Python networkx.is_isomorphic方法代码示例

本文整理汇总了Python中networkx.is_isomorphic方法的典型用法代码示例。如果您正苦于以下问题:Python networkx.is_isomorphic方法的具体用法?Python networkx.is_isomorphic怎么用?Python networkx.is_isomorphic使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在networkx的用法示例。


在下文中一共展示了networkx.is_isomorphic方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_from_json_object

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import is_isomorphic [as 别名]
def test_from_json_object(nx):
    proc = Process(process_id=10, process_image="test.exe", command_line=None)
    other_proc = Process(process_id=12, process_image="best.exe", command_line="best.exe /c 123456")

    proc.launched[other_proc]

    G = nx(nodes=[proc, other_proc])

    _json_output = NetworkX.graph_to_json(G)

    assert isinstance(_json_output, dict)

    G2 = NetworkX.from_json(_json_output)

    # Graphs should be equal.
    assert networkx.is_isomorphic(G, G2) 
开发者ID:yampelo,项目名称:beagle,代码行数:18,代码来源:test_networkx.py

示例2: test_from_json_path

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import is_isomorphic [as 别名]
def test_from_json_path(nx, tmpdir):
    proc = Process(process_id=10, process_image="test.exe", command_line=None)
    other_proc = Process(process_id=12, process_image="best.exe", command_line="best.exe /c 123456")

    proc.launched[other_proc]

    G = nx(nodes=[proc, other_proc])

    _json_output = NetworkX.graph_to_json(G)

    # Save to file
    p = tmpdir.mkdir("networkx").join("data.json")
    p.write(json.dumps(_json_output))

    G2 = NetworkX.from_json(p)

    # Graphs should be equal.
    assert networkx.is_isomorphic(G, G2) 
开发者ID:yampelo,项目名称:beagle,代码行数:20,代码来源:test_networkx.py

示例3: test_identify_hubs_and_experts

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import is_isomorphic [as 别名]
def test_identify_hubs_and_experts(self):
    
        top_hub_ = util.load_from_disk(self.test_data_dir + "hits/top_hub")
        top_keyword_overlap_ = util.load_from_disk(self.test_data_dir + "hits/top_keyword_overlap")
        top_auth_ = util.load_from_disk(self.test_data_dir + "hits/top_auth")
        message_graph = util.load_from_disk(self.test_data_dir + "hits/message_graph")
        
        capturedOutput = StringIO.StringIO()
        sys.stdout = capturedOutput
        
        message_num_graph, top_hub, top_keyword_overlap, top_auth = network.identify_hubs_and_experts(self.log_data, self.nicks, self.nick_same_list)
        
        sys.stdout = sys.__stdout__
        capturedOutput.close()
        
        self.assertEqual(top_hub, top_hub_)
        self.assertEqual(top_keyword_overlap, top_keyword_overlap_)
        self.assertEqual(top_auth, top_auth_) 
        self.assertTrue(nx.is_isomorphic(message_graph, message_num_graph)) 
开发者ID:prasadtalasila,项目名称:IRCLogParser,代码行数:21,代码来源:test_network.py

示例4: test_identify_hubs_and_experts

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import is_isomorphic [as 别名]
def test_identify_hubs_and_experts(self):
        
        log_data = util.load_from_disk(self.test_data_dir + "hits/log_data")
        nicks = util.load_from_disk(self.test_data_dir + "hits/nicks")
        nick_same_list = util.load_from_disk(self.test_data_dir + "hits/nick_same_list")
        expected_top_hub = util.load_from_disk(self.test_data_dir + "hits/top_hub")
        expected_top_keyword_overlap = util.load_from_disk(self.test_data_dir + "hits/top_keyword_overlap")
        expected_top_auth = util.load_from_disk(self.test_data_dir + "hits/top_auth")
        message_graph = util.load_from_disk(self.test_data_dir + "hits/message_graph")
        
        capturedOutput = StringIO.StringIO()
        sys.stdout = capturedOutput
        
        message_num_graph, top_hub, top_keyword_overlap, top_auth = network.identify_hubs_and_experts(log_data, nicks, nick_same_list)
        
        sys.stdout = sys.__stdout__
        capturedOutput.close()

        self.assertEqual(top_hub, expected_top_hub)
        self.assertEqual(top_keyword_overlap, expected_top_keyword_overlap)
        self.assertEqual(top_auth, expected_top_auth)
        self.assertTrue(nx.is_isomorphic(message_graph, message_num_graph)) 
开发者ID:prasadtalasila,项目名称:IRCLogParser,代码行数:24,代码来源:test_network.py

示例5: test_identify_hubs_and_experts

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import is_isomorphic [as 别名]
def test_identify_hubs_and_experts(self):

        expected_top_hub = util.load_from_disk(self.out_dir+ "top_hub")
        expected_top_keyword_overlap = util.load_from_disk(self.out_dir+ "top_keyword_overlap")
        expected_top_auth = util.load_from_disk(self.out_dir+ "top_auth")
        expected_message_graph = util.load_from_disk(self.out_dir + "message_num_graph")

        capturedOutput = StringIO.StringIO()
        sys.stdout = capturedOutput

        nicks, nick_same_list = nickTracker.nick_tracker(self.log_data)
        message_num_graph, top_hub, top_keyword_overlap, top_auth = network.identify_hubs_and_experts(self.log_data, nicks, nick_same_list)

        sys.stdout = sys.__stdout__
        capturedOutput.close()

        self.assertEqual(top_hub, expected_top_hub)
        self.assertEqual(top_keyword_overlap, expected_top_keyword_overlap)
        self.assertEqual(top_auth, expected_top_auth)
        self.assertTrue(nx.is_isomorphic(expected_message_graph, message_num_graph)) 
开发者ID:prasadtalasila,项目名称:IRCLogParser,代码行数:22,代码来源:test_userprofile.py

示例6: test_message_time_graph

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import is_isomorphic [as 别名]
def test_message_time_graph(self, mock_rec_list_splice, mock_correctLastCharCR, mock_get_year_month_day, mock_get_nick_sen_rec, mock_check_if_msg_line, mock_create_connected_nick_list, mock_to_graph):
        to_graph_ret = util.load_from_disk(self.test_data_dir + "message_time_graph/to_graph")
        
        conn_list = list(connected_components(to_graph_ret))
        
        mock_to_graph.return_value = to_graph_ret
        mock_rec_list_splice.side_effect = util.load_from_disk(self.test_data_dir + "message_time_graph/rec_list_splice")
        mock_create_connected_nick_list.return_value = util.load_from_disk(self.test_data_dir + "message_time_graph/conn_comp_list")
        mock_check_if_msg_line.side_effect = util.load_from_disk(self.test_data_dir + "message_time_graph/check_if_msg_line")
        mock_correctLastCharCR.side_effect = util.load_from_disk(self.test_data_dir + "message_time_graph/correctLastCharCR")
        mock_get_nick_sen_rec.side_effect = util.load_from_disk(self.test_data_dir + "message_time_graph/get_nick_sen_rec")
        #mock_correct_last_char_list.side_effect = util.load_from_disk(self.test_data_dir + "message_time_graph/correct_last_char_list")
        mock_get_year_month_day.side_effect = util.load_from_disk(self.test_data_dir + "message_time_graph/get_year_month_day")
        
        capturedOutput = StringIO.StringIO()
        sys.stdout = capturedOutput
        
        ret = network.message_time_graph(self.log_data, self.nicks, self.nick_same_list, DAY_BY_DAY_ANALYSIS=False)
        
        sys.stdout = sys.__stdout__
        capturedOutput.close()
        
        mock_to_graph.assert_called_once_with(self.nick_same_list)
        mock_create_connected_nick_list.assert_called_once_with(conn_list)
        self.assertTrue(nx.is_isomorphic(ret, util.load_from_disk(self.test_data_dir + "message_time_graph/msg_time_aggr_graph"))) 
开发者ID:prasadtalasila,项目名称:IRCLogParser,代码行数:27,代码来源:test_network.py

示例7: __eq__

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import is_isomorphic [as 别名]
def __eq__(self, other):
    if not isinstance(other, self.__class__):
      return False

    # We know these dicts have the same keys because 'other' is also a params
    # instance.
    self_dict = self.asdict()
    other_dict = other.asdict()

    for key in self_dict:
      if key == 'population_graph':
        if not nx.is_isomorphic(
            self_dict['population_graph'], other_dict['population_graph']):
          return False
      if (isinstance(self_dict[key], np.ndarray)
          and isinstance(other_dict[key], np.ndarray)):
        return (self_dict[key] == other_dict[key]).all()
      else:
        if self_dict[key] != other_dict[key]:
          return False
    return True 
开发者ID:google,项目名称:ml-fairness-gym,代码行数:23,代码来源:infectious_disease.py

示例8: test_nonsquare_coordinate_generator

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import is_isomorphic [as 别名]
def test_nonsquare_coordinate_generator(self):
        #issue 149 found an issue with non-square generators -- let's be extra careful here
        for (m, n) in [(2, 4), (4, 2)]:
            G = dnx.chimera_graph(m, n, coordinates=True, data=True)
            H = dnx.chimera_graph(m, n, coordinates=False, data=True)
            self.assertTrue(nx.is_isomorphic(G, H))

            Gnodes = set(G.nodes)
            Glabels = set(q['linear_index'] for q in G.nodes.values())

            Hnodes = set(H.nodes)
            Hlabels = set(q['chimera_index'] for q in H.nodes.values())

            self.assertEqual(Gnodes, Hlabels)
            self.assertEqual(Hnodes, Glabels)

            coords = dnx.chimera_coordinates(m, n)
            F = nx.relabel_nodes(G, coords.chimera_to_linear, copy=True)
            self.assertEqual(set(map(frozenset, F.edges)), set(map(frozenset, H.edges)))

            E = nx.relabel_nodes(H, coords.linear_to_chimera, copy=True)
            self.assertEqual(set(map(frozenset, E.edges)), set(map(frozenset, G.edges))) 
开发者ID:dwavesystems,项目名称:dwave_networkx,代码行数:24,代码来源:test_chimera.py

示例9: test_to_digraph

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import is_isomorphic [as 别名]
def test_to_digraph():
    ia = IndraNetAssembler([ab1, ab2, ab3, ab4, bc1, bc2, bc3, bc4])
    df = ia.make_df()
    net = IndraNet.from_df(df)
    assert len(net.nodes) == 3
    assert len(net.edges) == 8
    digraph = net.to_digraph(weight_mapping=_weight_mapping)
    assert len(digraph.nodes) == 3
    assert len(digraph.edges) == 2
    assert set([
        stmt['stmt_type'] for stmt in digraph['a']['b']['statements']]) == {
            'Activation', 'Phosphorylation', 'Inhibition', 'IncreaseAmount'}
    assert all(digraph.edges[e].get('belief', False) for e in digraph.edges)
    assert all(isinstance(digraph.edges[e]['belief'],
                          (float, np.longfloat)) for e in digraph.edges)
    assert all(digraph.edges[e].get('weight', False) for e in digraph.edges)
    assert all(isinstance(digraph.edges[e]['weight'],
                          (float, np.longfloat)) for e in digraph.edges)
    digraph_from_df = IndraNet.digraph_from_df(df)
    assert nx.is_isomorphic(digraph, digraph_from_df) 
开发者ID:sorgerlab,项目名称:indra,代码行数:22,代码来源:test_indranet_assembler.py

示例10: test_device_stuff

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import is_isomorphic [as 别名]
def test_device_stuff():
    topo = nx.from_edgelist([(0, 4), (0, 99)])
    qc = QuantumComputer(
        name="testy!",
        qam=None,  # not necessary for this test
        device=NxDevice(topo),
        compiler=DummyCompiler(),
    )
    assert nx.is_isomorphic(qc.qubit_topology(), topo)

    isa = qc.get_isa(twoq_type="CPHASE")
    assert isa.edges[0].type == "CPHASE"
    assert isa.edges[0].targets == (0, 4)


# We sometimes narrowly miss the np.mean(parity) < 0.15 assertion, below. Alternatively, that upper
# bound could be relaxed. 
开发者ID:rigetti,项目名称:pyquil,代码行数:19,代码来源:test_quantum_computer.py

示例11: test_weighted_input

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import is_isomorphic [as 别名]
def test_weighted_input():
    G1 = nx.karate_club_graph()
    G2 = nx.karate_club_graph()
    rand = np.random.RandomState(seed=42)
    edge_weights = {e: rand.randint(0, 1000) for e in G2.edges}
    nx.set_edge_attributes(G2, edge_weights, "weight")
    assert nx.is_isomorphic(G1, G2)

    for label, obj in distance.__dict__.items():
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always")
            if isinstance(obj, type) and BaseDistance in obj.__bases__:
                dist = obj().dist(G1, G2)
                warning_triggered = False
                for warning in w:
                    if "weighted" in str(warning.message):
                        warning_triggered = True
                if not warning_triggered:
                    assert not np.isclose(dist, 0.0)
                else:
                    assert np.isclose(dist, 0.0) 
开发者ID:netsiphd,项目名称:netrd,代码行数:23,代码来源:test_distance.py

示例12: test_write_read

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import is_isomorphic [as 别名]
def test_write_read(tmpdir):
    """
    Check that writing topology to disk and restoring it produces the
    expected result
    """
    dirname = u(os.path.abspath(tmpdir.dirname))
    topo = complete_topology(5)
    for l in topo.links():
        topo.set_resource(l, u'myresource', 4)
    topo.write_graph(dirname + os.path.sep + u'testgml.gml')
    topo2 = Topology(topo.name)
    topo2.load_graph(dirname + os.path.sep + u'testgml.gml')
    assert networkx.is_isomorphic(topo.get_graph(), topo2.get_graph())
    assert topo.name == topo2.name

    # Check that resources are preserved
    for n in topo.nodes():
        assert topo.get_resources(n) == topo2.get_resources(n)
    for l in topo.links():
        assert topo.get_resources(n) == topo2.get_resources(n) 
开发者ID:progwriter,项目名称:SOL,代码行数:22,代码来源:topology_test.py

示例13: test_subgraph_nbunch

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import is_isomorphic [as 别名]
def test_subgraph_nbunch(self):
        nullgraph=nx.null_graph()
        K1=nx.complete_graph(1)
        K3=nx.complete_graph(3)
        K5=nx.complete_graph(5)
        # Test G.subgraph(nbunch), where nbunch is a single node
        H=K5.subgraph(1)
        assert_true(nx.is_isomorphic(H,K1))
        # Test G.subgraph(nbunch), where nbunch is a set
        H=K5.subgraph(set([1]))
        assert_true(nx.is_isomorphic(H,K1))
        # Test G.subgraph(nbunch), where nbunch is an iterator
        H=K5.subgraph(iter(K3))
        assert_true(nx.is_isomorphic(H,K3))
        # Test G.subgraph(nbunch), where nbunch is another graph
        H=K5.subgraph(K3)
        assert_true(nx.is_isomorphic(H,K3))
        H=K5.subgraph([9])
        assert_true(nx.is_isomorphic(H,nullgraph)) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:21,代码来源:historical_tests.py

示例14: test_weightkey

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import is_isomorphic [as 别名]
def test_weightkey():
    g1 = nx.DiGraph()
    g2 = nx.DiGraph()

    g1.add_edge('A','B', weight=1)
    g2.add_edge('C','D', weight=0)

    assert_true(  nx.is_isomorphic(g1, g2) )
    em = iso.numerical_edge_match('nonexistent attribute', 1)
    assert_true(  nx.is_isomorphic(g1, g2, edge_match=em) )
    em = iso.numerical_edge_match('weight', 1)
    assert_false( nx.is_isomorphic(g1, g2, edge_match=em) )

    g2 = nx.DiGraph()
    g2.add_edge('C','D')
    assert_true( nx.is_isomorphic(g1, g2, edge_match=em) ) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:18,代码来源:test_vf2userfunc.py

示例15: compile

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import is_isomorphic [as 别名]
def compile(self, seq, registers):
        """Class-specific circuit compilation method.

        If additional compilation logic is required, child classes can redefine this method.

        Args:
            seq (Sequence[Command]): quantum circuit to modify
            registers (Sequence[RegRefs]): quantum registers
        Returns:
            List[Command]: modified circuit
        Raises:
            CircuitError: the given circuit cannot be validated to belong to this circuit class
        """
        # registers is not used here, but may be used if the method is overwritten pylint: disable=unused-argument
        if self.graph is not None:
            # check topology
            DAG = pu.list_to_DAG(seq)

            # relabel the DAG nodes to integers, with attributes
            # specifying the operation name. This allows them to be
            # compared, rather than using Command objects.
            mapping = {i: n.op.__class__.__name__ for i, n in enumerate(DAG.nodes())}
            circuit = nx.convert_node_labels_to_integers(DAG)
            nx.set_node_attributes(circuit, mapping, name="name")

            def node_match(n1, n2):
                """Returns True if both nodes have the same name"""
                return n1["name"] == n2["name"]

            # check if topology matches
            if not nx.is_isomorphic(circuit, self.graph, node_match):
                # TODO: try and compile the program to match the topology
                # TODO: add support for parameter range matching/compilation
                raise pu.CircuitError(
                    "Program cannot be used with the CircuitSpec '{}' "
                    "due to incompatible topology.".format(self.short_name)
                )

        return seq 
开发者ID:XanaduAI,项目名称:strawberryfields,代码行数:41,代码来源:circuit_specs.py


注:本文中的networkx.is_isomorphic方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。