nodes: 0, module; 1, function_definition; 2, function_name:embed_ising; 3, parameters; 4, block; 5, identifier:source_h; 6, identifier:source_J; 7, identifier:embedding; 8, identifier:target_adjacency; 9, default_parameter; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, expression_statement; 14, return_statement; 15, identifier:chain_strength; 16, float:1.0; 17, comment:"""Embed an Ising problem onto a target graph.
  
      Args:
          source_h (dict[variable, bias]/list[bias]):
              Linear biases of the Ising problem. If a list, the list's indices are used as
              variable labels.
  
          source_J (dict[(variable, variable), bias]):
              Quadratic biases of the Ising problem.
  
          embedding (dict):
              Mapping from source graph to target graph as a dict of form {s: {t, ...}, ...},
              where s is a source-model variable and t is a target-model variable.
  
          target_adjacency (dict/:class:`networkx.Graph`):
              Adjacency of the target graph as a dict of form {t: Nt, ...},
              where t is a target-graph variable and Nt is its set of neighbours.
  
          chain_strength (float, optional):
              Magnitude of the quadratic bias (in SPIN-space) applied between variables to form a chain. Note
              that the energy penalty of chain breaks is 2 * `chain_strength`.
  
      Returns:
          tuple: A 2-tuple:
  
              dict[variable, bias]: Linear biases of the target Ising problem.
  
              dict[(variable, variable), bias]: Quadratic biases of the target Ising problem.
  
      Examples:
          This example embeds a fully connected :math:`K_3` graph onto a square target graph.
          Embedding is accomplished by an edge contraction operation on the target graph: target-nodes
          2 and 3 are chained to represent source-node c.
  
          >>> import dimod
          >>> import networkx as nx
          >>> # Ising problem for a triangular source graph
          >>> h = {}
          >>> J = {('a', 'b'): 1, ('b', 'c'): 1, ('a', 'c'): 1}
          >>> # Target graph is a square graph
          >>> target = nx.cycle_graph(4)
          >>> # Embedding from source to target graph
          >>> embedding = {'a': {0}, 'b': {1}, 'c': {2, 3}}
          >>> # Embed the Ising problem
          >>> target_h, target_J = dimod.embed_ising(h, J, embedding, target)
          >>> target_J[(0, 1)] == J[('a', 'b')]
          True
          >>> target_J        # doctest: +SKIP
          {(0, 1): 1.0, (0, 3): 1.0, (1, 2): 1.0, (2, 3): -1.0}
  
          This example embeds a fully connected :math:`K_3` graph onto the target graph
          of a dimod reference structured sampler, `StructureComposite`, using the dimod reference
          `ExactSolver` sampler with a square graph specified. Target-nodes 2 and 3 are chained to
          represent source-node c.
  
          >>> import dimod
          >>> # Ising problem for a triangular source graph
          >>> h = {}
          >>> J = {('a', 'b'): 1, ('b', 'c'): 1, ('a', 'c'): 1}
          >>> # Structured dimod sampler with a structure defined by a square graph
          >>> sampler = dimod.StructureComposite(dimod.ExactSolver(), [0, 1, 2, 3], [(0, 1), (1, 2), (2, 3), (0, 3)])
          >>> # Embedding from source to target graph
          >>> embedding = {'a': {0}, 'b': {1}, 'c': {2, 3}}
          >>> # Embed the Ising problem
          >>> target_h, target_J = dimod.embed_ising(h, J, embedding, sampler.adjacency)
          >>> # Sample
          >>> samples = sampler.sample_ising(target_h, target_J)
          >>> for sample in samples.samples(n=3, sorted_by='energy'):   # doctest: +SKIP
          ...     print(sample)
          ...
          {0: 1, 1: -1, 2: -1, 3: -1}
          {0: 1, 1: 1, 2: -1, 3: -1}
          {0: -1, 1: 1, 2: -1, 3: -1}
  
      """; 18, assignment; 19, assignment; 20, assignment; 21, expression_list; 22, identifier:source_bqm; 23, call; 24, identifier:target_bqm; 25, call; 26, pattern_list; 27, call; 28, identifier:target_h; 29, identifier:target_J; 30, attribute; 31, argument_list; 32, identifier:embed_bqm; 33, argument_list; 34, identifier:target_h; 35, identifier:target_J; 36, identifier:__; 37, attribute; 38, argument_list; 39, attribute; 40, identifier:from_ising; 41, identifier:source_h; 42, identifier:source_J; 43, identifier:source_bqm; 44, identifier:embedding; 45, identifier:target_adjacency; 46, keyword_argument; 47, identifier:target_bqm; 48, identifier:to_ising; 49, identifier:dimod; 50, identifier:BinaryQuadraticModel; 51, identifier:chain_strength; 52, identifier:chain_strength
code: def embed_ising(source_h, source_J, embedding, target_adjacency, chain_strength=1.0):
      """Embed an Ising problem onto a target graph.
  
      Args:
          source_h (dict[variable, bias]/list[bias]):
              Linear biases of the Ising problem. If a list, the list's indices are used as
              variable labels.
  
          source_J (dict[(variable, variable), bias]):
              Quadratic biases of the Ising problem.
  
          embedding (dict):
              Mapping from source graph to target graph as a dict of form {s: {t, ...}, ...},
              where s is a source-model variable and t is a target-model variable.
  
          target_adjacency (dict/:class:`networkx.Graph`):
              Adjacency of the target graph as a dict of form {t: Nt, ...},
              where t is a target-graph variable and Nt is its set of neighbours.
  
          chain_strength (float, optional):
              Magnitude of the quadratic bias (in SPIN-space) applied between variables to form a chain. Note
              that the energy penalty of chain breaks is 2 * `chain_strength`.
  
      Returns:
          tuple: A 2-tuple:
  
              dict[variable, bias]: Linear biases of the target Ising problem.
  
              dict[(variable, variable), bias]: Quadratic biases of the target Ising problem.
  
      Examples:
          This example embeds a fully connected :math:`K_3` graph onto a square target graph.
          Embedding is accomplished by an edge contraction operation on the target graph: target-nodes
          2 and 3 are chained to represent source-node c.
  
          >>> import dimod
          >>> import networkx as nx
          >>> # Ising problem for a triangular source graph
          >>> h = {}
          >>> J = {('a', 'b'): 1, ('b', 'c'): 1, ('a', 'c'): 1}
          >>> # Target graph is a square graph
          >>> target = nx.cycle_graph(4)
          >>> # Embedding from source to target graph
          >>> embedding = {'a': {0}, 'b': {1}, 'c': {2, 3}}
          >>> # Embed the Ising problem
          >>> target_h, target_J = dimod.embed_ising(h, J, embedding, target)
          >>> target_J[(0, 1)] == J[('a', 'b')]
          True
          >>> target_J        # doctest: +SKIP
          {(0, 1): 1.0, (0, 3): 1.0, (1, 2): 1.0, (2, 3): -1.0}
  
          This example embeds a fully connected :math:`K_3` graph onto the target graph
          of a dimod reference structured sampler, `StructureComposite`, using the dimod reference
          `ExactSolver` sampler with a square graph specified. Target-nodes 2 and 3 are chained to
          represent source-node c.
  
          >>> import dimod
          >>> # Ising problem for a triangular source graph
          >>> h = {}
          >>> J = {('a', 'b'): 1, ('b', 'c'): 1, ('a', 'c'): 1}
          >>> # Structured dimod sampler with a structure defined by a square graph
          >>> sampler = dimod.StructureComposite(dimod.ExactSolver(), [0, 1, 2, 3], [(0, 1), (1, 2), (2, 3), (0, 3)])
          >>> # Embedding from source to target graph
          >>> embedding = {'a': {0}, 'b': {1}, 'c': {2, 3}}
          >>> # Embed the Ising problem
          >>> target_h, target_J = dimod.embed_ising(h, J, embedding, sampler.adjacency)
          >>> # Sample
          >>> samples = sampler.sample_ising(target_h, target_J)
          >>> for sample in samples.samples(n=3, sorted_by='energy'):   # doctest: +SKIP
          ...     print(sample)
          ...
          {0: 1, 1: -1, 2: -1, 3: -1}
          {0: 1, 1: 1, 2: -1, 3: -1}
          {0: -1, 1: 1, 2: -1, 3: -1}
  
      """
      source_bqm = dimod.BinaryQuadraticModel.from_ising(source_h, source_J)
      target_bqm = embed_bqm(source_bqm, embedding, target_adjacency, chain_strength=chain_strength)
      target_h, target_J, __ = target_bqm.to_ising()
      return target_h, target_J