def insert_ising_model(cur, nodelist, edgelist, linear, quadratic, offset, encoded_data=None):
    """Insert an Ising model into the cache.

    Args:
        cur (:class:`sqlite3.Cursor`): An sqlite3 cursor. This function
            is meant to be run within a :obj:`with` statement.
        nodelist (list): The nodes in the graph.
        edgelist (list): The edges in the graph.
        linear (dict): The linear bias associated with each node in nodelist.
        quadratic (dict): The quadratic bias associated with teach edge in edgelist.
        offset (float): The constant offset applied to the ising problem.
        encoded_data (dict, optional): If a dictionary is provided, it
            will be populated with the serialized data. This is useful for
            preventing encoding the same information many times.

    """
    if encoded_data is None:
        encoded_data = {}

    # insert graph and partially populate encoded_data with graph info
    insert_graph(cur, nodelist, edgelist, encoded_data=encoded_data)

    # need to encode the biases
    if 'linear_biases' not in encoded_data:
        encoded_data['linear_biases'] = _serialize_linear_biases(linear, nodelist)
    if 'quadratic_biases' not in encoded_data:
        encoded_data['quadratic_biases'] = _serialize_quadratic_biases(quadratic, edgelist)
    if 'offset' not in encoded_data:
        encoded_data['offset'] = offset
    if 'max_quadratic_bias' not in encoded_data:
        encoded_data['max_quadratic_bias'] = max(itervalues(quadratic))
    if 'min_quadratic_bias' not in encoded_data:
        encoded_data['min_quadratic_bias'] = min(itervalues(quadratic))
    if 'max_linear_bias' not in encoded_data:
        encoded_data['max_linear_bias'] = max(itervalues(linear))
    if 'min_linear_bias' not in encoded_data:
        encoded_data['min_linear_bias'] = min(itervalues(linear))

    insert = \
        """
        INSERT OR IGNORE INTO ising_model(
            linear_biases,
            quadratic_biases,
            offset,
            max_quadratic_bias,
            min_quadratic_bias,
            max_linear_bias,
            min_linear_bias,
            graph_id)
        SELECT
            :linear_biases,
            :quadratic_biases,
            :offset,
            :max_quadratic_bias,
            :min_quadratic_bias,
            :max_linear_bias,
            :min_linear_bias,
            graph.id
        FROM graph WHERE
            num_nodes = :num_nodes AND
            num_edges = :num_edges AND
            edges = :edges;
        """

    cur.execute(insert, encoded_data)
def insert_ising_model ( cur , nodelist , edgelist , linear , quadratic , offset , encoded_data = None ) : if encoded_data is None : encoded_data = { } insert_graph ( cur , nodelist , edgelist , encoded_data = encoded_data ) if 'linear_biases' not in encoded_data : encoded_data [ 'linear_biases' ] = _serialize_linear_biases ( linear , nodelist ) if 'quadratic_biases' not in encoded_data : encoded_data [ 'quadratic_biases' ] = _serialize_quadratic_biases ( quadratic , edgelist ) if 'offset' not in encoded_data : encoded_data [ 'offset' ] = offset if 'max_quadratic_bias' not in encoded_data : encoded_data [ 'max_quadratic_bias' ] = max ( itervalues ( quadratic ) ) if 'min_quadratic_bias' not in encoded_data : encoded_data [ 'min_quadratic_bias' ] = min ( itervalues ( quadratic ) ) if 'max_linear_bias' not in encoded_data : encoded_data [ 'max_linear_bias' ] = max ( itervalues ( linear ) ) if 'min_linear_bias' not in encoded_data : encoded_data [ 'min_linear_bias' ] = min ( itervalues ( linear ) ) insert = """
        INSERT OR IGNORE INTO ising_model(
            linear_biases,
            quadratic_biases,
            offset,
            max_quadratic_bias,
            min_quadratic_bias,
            max_linear_bias,
            min_linear_bias,
            graph_id)
        SELECT
            :linear_biases,
            :quadratic_biases,
            :offset,
            :max_quadratic_bias,
            :min_quadratic_bias,
            :max_linear_bias,
            :min_linear_bias,
            graph.id
        FROM graph WHERE
            num_nodes = :num_nodes AND
            num_edges = :num_edges AND
            edges = :edges;
        """ cur . execute ( insert , encoded_data )
Insert an Ising model into the cache.

    Args:
        cur (:class:`sqlite3.Cursor`): An sqlite3 cursor. This function
            is meant to be run within a :obj:`with` statement.
        nodelist (list): The nodes in the graph.
        edgelist (list): The edges in the graph.
        linear (dict): The linear bias associated with each node in nodelist.
        quadratic (dict): The quadratic bias associated with teach edge in edgelist.
        offset (float): The constant offset applied to the ising problem.
        encoded_data (dict, optional): If a dictionary is provided, it
            will be populated with the serialized data. This is useful for
            preventing encoding the same information many times.