qiskit.optimization.applications.ising.common
common module
Functions
get_gset_result (x) | Get graph solution in Gset format from binary string. |
parse_gset_format (filename) | Read graph in Gset format from file. |
random_graph (n[, weight_range, edge_prob, …]) | Generate random Erdos-Renyi graph. |
random_number_list (n[, weight_range, …]) | Generate a set of positive integers within the given range. |
read_numbers_from_file (filename) | Read numbers from a file |
sample_most_likely (state_vector) | Compute the most likely binary string from state vector. |
get_gset_result
get_gset_result(x)
Get graph solution in Gset format from binary string.
Parameters
x (numpy.ndarray) – binary string as numpy array.
Returns
graph solution in Gset format.
Return type
Dict[int, int]
parse_gset_format
parse_gset_format(filename)
Read graph in Gset format from file.
Parameters
filename (str) – name of the file.
Returns
adjacency matrix as a 2D numpy array.
Return type
numpy.ndarray
random_graph
random_graph(n, weight_range=10, edge_prob=0.3, negative_weight=True, savefile=None, seed=None)
Generate random Erdos-Renyi graph.
Parameters
- n (int) – number of nodes.
- weight_range (int) – weights will be smaller than this value, in absolute value. range: [1, weight_range).
- edge_prob (float) – probability of edge appearing.
- negative_weight (bool) – allow to have edge with negative weights
- savefile (str or None) – name of file where to save graph.
- seed (int or None) – random seed - if None, will not initialize.
Returns
adjacency matrix (with weights).
Return type
numpy.ndarray
random_number_list
random_number_list(n, weight_range=100, savefile=None, seed=None)
Generate a set of positive integers within the given range.
Parameters
- n (int) – size of the set of numbers.
- weight_range (int) – maximum absolute value of the numbers.
- savefile (str or None) – write numbers to this file.
- seed (Union(int,None)) – random seed - if None, will not initialize.
Returns
the list of integer numbers.
Return type
numpy.ndarray
read_numbers_from_file
read_numbers_from_file(filename)
Read numbers from a file
Parameters
filename (str) – name of the file.
Returns
list of numbers as a numpy.ndarray.
Return type
numpy.ndarray
sample_most_likely
sample_most_likely(state_vector)
Compute the most likely binary string from state vector. :param state_vector: state vector or counts. :type state_vector: numpy.ndarray or dict
Returns
binary string as numpy.ndarray of ints.
Return type
numpy.ndarray