repo
stringlengths
7
55
path
stringlengths
4
223
func_name
stringlengths
1
134
original_string
stringlengths
75
104k
language
stringclasses
1 value
code
stringlengths
75
104k
code_tokens
listlengths
19
28.4k
docstring
stringlengths
1
46.9k
docstring_tokens
listlengths
1
1.97k
sha
stringlengths
40
40
url
stringlengths
87
315
partition
stringclasses
1 value
lmcinnes/umap
umap/spectral.py
multi_component_layout
def multi_component_layout( data, graph, n_components, component_labels, dim, random_state, metric="euclidean", metric_kwds={}, ): """Specialised layout algorithm for dealing with graphs with many connected components. This will first fid relative positions for the components by ...
python
def multi_component_layout( data, graph, n_components, component_labels, dim, random_state, metric="euclidean", metric_kwds={}, ): """Specialised layout algorithm for dealing with graphs with many connected components. This will first fid relative positions for the components by ...
[ "def", "multi_component_layout", "(", "data", ",", "graph", ",", "n_components", ",", "component_labels", ",", "dim", ",", "random_state", ",", "metric", "=", "\"euclidean\"", ",", "metric_kwds", "=", "{", "}", ",", ")", ":", "result", "=", "np", ".", "emp...
Specialised layout algorithm for dealing with graphs with many connected components. This will first fid relative positions for the components by spectrally embedding their centroids, then spectrally embed each individual connected component positioning them according to the centroid embeddings. This provid...
[ "Specialised", "layout", "algorithm", "for", "dealing", "with", "graphs", "with", "many", "connected", "components", ".", "This", "will", "first", "fid", "relative", "positions", "for", "the", "components", "by", "spectrally", "embedding", "their", "centroids", "t...
bbb01c03ba49f7bff8f77fd662d00e50d6686c77
https://github.com/lmcinnes/umap/blob/bbb01c03ba49f7bff8f77fd662d00e50d6686c77/umap/spectral.py#L65-L196
train
lmcinnes/umap
umap/spectral.py
spectral_layout
def spectral_layout(data, graph, dim, random_state, metric="euclidean", metric_kwds={}): """Given a graph compute the spectral embedding of the graph. This is simply the eigenvectors of the laplacian of the graph. Here we use the normalized laplacian. Parameters ---------- data: array of shape ...
python
def spectral_layout(data, graph, dim, random_state, metric="euclidean", metric_kwds={}): """Given a graph compute the spectral embedding of the graph. This is simply the eigenvectors of the laplacian of the graph. Here we use the normalized laplacian. Parameters ---------- data: array of shape ...
[ "def", "spectral_layout", "(", "data", ",", "graph", ",", "dim", ",", "random_state", ",", "metric", "=", "\"euclidean\"", ",", "metric_kwds", "=", "{", "}", ")", ":", "n_samples", "=", "graph", ".", "shape", "[", "0", "]", "n_components", ",", "labels",...
Given a graph compute the spectral embedding of the graph. This is simply the eigenvectors of the laplacian of the graph. Here we use the normalized laplacian. Parameters ---------- data: array of shape (n_samples, n_features) The source data graph: sparse matrix The (weighted)...
[ "Given", "a", "graph", "compute", "the", "spectral", "embedding", "of", "the", "graph", ".", "This", "is", "simply", "the", "eigenvectors", "of", "the", "laplacian", "of", "the", "graph", ".", "Here", "we", "use", "the", "normalized", "laplacian", "." ]
bbb01c03ba49f7bff8f77fd662d00e50d6686c77
https://github.com/lmcinnes/umap/blob/bbb01c03ba49f7bff8f77fd662d00e50d6686c77/umap/spectral.py#L199-L283
train
lmcinnes/umap
umap/rp_tree.py
sparse_angular_random_projection_split
def sparse_angular_random_projection_split(inds, indptr, data, indices, rng_state): """Given a set of ``indices`` for data points from a sparse data set presented in csr sparse format as inds, indptr and data, create a random hyperplane to split the data, returning two arrays indices that fall on either...
python
def sparse_angular_random_projection_split(inds, indptr, data, indices, rng_state): """Given a set of ``indices`` for data points from a sparse data set presented in csr sparse format as inds, indptr and data, create a random hyperplane to split the data, returning two arrays indices that fall on either...
[ "def", "sparse_angular_random_projection_split", "(", "inds", ",", "indptr", ",", "data", ",", "indices", ",", "rng_state", ")", ":", "# Select two random points, set the hyperplane between them", "left_index", "=", "tau_rand_int", "(", "rng_state", ")", "%", "indices", ...
Given a set of ``indices`` for data points from a sparse data set presented in csr sparse format as inds, indptr and data, create a random hyperplane to split the data, returning two arrays indices that fall on either side of the hyperplane. This is the basis for a random projection tree, which simply u...
[ "Given", "a", "set", "of", "indices", "for", "data", "points", "from", "a", "sparse", "data", "set", "presented", "in", "csr", "sparse", "format", "as", "inds", "indptr", "and", "data", "create", "a", "random", "hyperplane", "to", "split", "the", "data", ...
bbb01c03ba49f7bff8f77fd662d00e50d6686c77
https://github.com/lmcinnes/umap/blob/bbb01c03ba49f7bff8f77fd662d00e50d6686c77/umap/rp_tree.py#L224-L338
train
lmcinnes/umap
umap/rp_tree.py
sparse_euclidean_random_projection_split
def sparse_euclidean_random_projection_split(inds, indptr, data, indices, rng_state): """Given a set of ``indices`` for data points from a sparse data set presented in csr sparse format as inds, indptr and data, create a random hyperplane to split the data, returning two arrays indices that fall on eith...
python
def sparse_euclidean_random_projection_split(inds, indptr, data, indices, rng_state): """Given a set of ``indices`` for data points from a sparse data set presented in csr sparse format as inds, indptr and data, create a random hyperplane to split the data, returning two arrays indices that fall on eith...
[ "def", "sparse_euclidean_random_projection_split", "(", "inds", ",", "indptr", ",", "data", ",", "indices", ",", "rng_state", ")", ":", "# Select two random points, set the hyperplane between them", "left_index", "=", "tau_rand_int", "(", "rng_state", ")", "%", "indices",...
Given a set of ``indices`` for data points from a sparse data set presented in csr sparse format as inds, indptr and data, create a random hyperplane to split the data, returning two arrays indices that fall on either side of the hyperplane. This is the basis for a random projection tree, which simply u...
[ "Given", "a", "set", "of", "indices", "for", "data", "points", "from", "a", "sparse", "data", "set", "presented", "in", "csr", "sparse", "format", "as", "inds", "indptr", "and", "data", "create", "a", "random", "hyperplane", "to", "split", "the", "data", ...
bbb01c03ba49f7bff8f77fd662d00e50d6686c77
https://github.com/lmcinnes/umap/blob/bbb01c03ba49f7bff8f77fd662d00e50d6686c77/umap/rp_tree.py#L342-L447
train
lmcinnes/umap
umap/rp_tree.py
make_tree
def make_tree(data, rng_state, leaf_size=30, angular=False): """Construct a random projection tree based on ``data`` with leaves of size at most ``leaf_size``. Parameters ---------- data: array of shape (n_samples, n_features) The original data to be split rng_state: array of int64, shap...
python
def make_tree(data, rng_state, leaf_size=30, angular=False): """Construct a random projection tree based on ``data`` with leaves of size at most ``leaf_size``. Parameters ---------- data: array of shape (n_samples, n_features) The original data to be split rng_state: array of int64, shap...
[ "def", "make_tree", "(", "data", ",", "rng_state", ",", "leaf_size", "=", "30", ",", "angular", "=", "False", ")", ":", "is_sparse", "=", "scipy", ".", "sparse", ".", "isspmatrix_csr", "(", "data", ")", "indices", "=", "np", ".", "arange", "(", "data",...
Construct a random projection tree based on ``data`` with leaves of size at most ``leaf_size``. Parameters ---------- data: array of shape (n_samples, n_features) The original data to be split rng_state: array of int64, shape (3,) The internal state of the rng leaf_size: int (opt...
[ "Construct", "a", "random", "projection", "tree", "based", "on", "data", "with", "leaves", "of", "size", "at", "most", "leaf_size", ".", "Parameters", "----------", "data", ":", "array", "of", "shape", "(", "n_samples", "n_features", ")", "The", "original", ...
bbb01c03ba49f7bff8f77fd662d00e50d6686c77
https://github.com/lmcinnes/umap/blob/bbb01c03ba49f7bff8f77fd662d00e50d6686c77/umap/rp_tree.py#L534-L577
train
lmcinnes/umap
umap/rp_tree.py
num_nodes
def num_nodes(tree): """Determine the number of nodes in a tree""" if tree.is_leaf: return 1 else: return 1 + num_nodes(tree.left_child) + num_nodes(tree.right_child)
python
def num_nodes(tree): """Determine the number of nodes in a tree""" if tree.is_leaf: return 1 else: return 1 + num_nodes(tree.left_child) + num_nodes(tree.right_child)
[ "def", "num_nodes", "(", "tree", ")", ":", "if", "tree", ".", "is_leaf", ":", "return", "1", "else", ":", "return", "1", "+", "num_nodes", "(", "tree", ".", "left_child", ")", "+", "num_nodes", "(", "tree", ".", "right_child", ")" ]
Determine the number of nodes in a tree
[ "Determine", "the", "number", "of", "nodes", "in", "a", "tree" ]
bbb01c03ba49f7bff8f77fd662d00e50d6686c77
https://github.com/lmcinnes/umap/blob/bbb01c03ba49f7bff8f77fd662d00e50d6686c77/umap/rp_tree.py#L580-L585
train
lmcinnes/umap
umap/rp_tree.py
num_leaves
def num_leaves(tree): """Determine the number of leaves in a tree""" if tree.is_leaf: return 1 else: return num_leaves(tree.left_child) + num_leaves(tree.right_child)
python
def num_leaves(tree): """Determine the number of leaves in a tree""" if tree.is_leaf: return 1 else: return num_leaves(tree.left_child) + num_leaves(tree.right_child)
[ "def", "num_leaves", "(", "tree", ")", ":", "if", "tree", ".", "is_leaf", ":", "return", "1", "else", ":", "return", "num_leaves", "(", "tree", ".", "left_child", ")", "+", "num_leaves", "(", "tree", ".", "right_child", ")" ]
Determine the number of leaves in a tree
[ "Determine", "the", "number", "of", "leaves", "in", "a", "tree" ]
bbb01c03ba49f7bff8f77fd662d00e50d6686c77
https://github.com/lmcinnes/umap/blob/bbb01c03ba49f7bff8f77fd662d00e50d6686c77/umap/rp_tree.py#L588-L593
train
lmcinnes/umap
umap/rp_tree.py
max_sparse_hyperplane_size
def max_sparse_hyperplane_size(tree): """Determine the most number on non zeros in a hyperplane entry""" if tree.is_leaf: return 0 else: return max( tree.hyperplane.shape[1], max_sparse_hyperplane_size(tree.left_child), max_sparse_hyperplane_size(tree.righ...
python
def max_sparse_hyperplane_size(tree): """Determine the most number on non zeros in a hyperplane entry""" if tree.is_leaf: return 0 else: return max( tree.hyperplane.shape[1], max_sparse_hyperplane_size(tree.left_child), max_sparse_hyperplane_size(tree.righ...
[ "def", "max_sparse_hyperplane_size", "(", "tree", ")", ":", "if", "tree", ".", "is_leaf", ":", "return", "0", "else", ":", "return", "max", "(", "tree", ".", "hyperplane", ".", "shape", "[", "1", "]", ",", "max_sparse_hyperplane_size", "(", "tree", ".", ...
Determine the most number on non zeros in a hyperplane entry
[ "Determine", "the", "most", "number", "on", "non", "zeros", "in", "a", "hyperplane", "entry" ]
bbb01c03ba49f7bff8f77fd662d00e50d6686c77
https://github.com/lmcinnes/umap/blob/bbb01c03ba49f7bff8f77fd662d00e50d6686c77/umap/rp_tree.py#L596-L605
train
lmcinnes/umap
umap/rp_tree.py
make_forest
def make_forest(data, n_neighbors, n_trees, rng_state, angular=False): """Build a random projection forest with ``n_trees``. Parameters ---------- data n_neighbors n_trees rng_state angular Returns ------- forest: list A list of random projection trees. """ ...
python
def make_forest(data, n_neighbors, n_trees, rng_state, angular=False): """Build a random projection forest with ``n_trees``. Parameters ---------- data n_neighbors n_trees rng_state angular Returns ------- forest: list A list of random projection trees. """ ...
[ "def", "make_forest", "(", "data", ",", "n_neighbors", ",", "n_trees", ",", "rng_state", ",", "angular", "=", "False", ")", ":", "result", "=", "[", "]", "leaf_size", "=", "max", "(", "10", ",", "n_neighbors", ")", "try", ":", "result", "=", "[", "fl...
Build a random projection forest with ``n_trees``. Parameters ---------- data n_neighbors n_trees rng_state angular Returns ------- forest: list A list of random projection trees.
[ "Build", "a", "random", "projection", "forest", "with", "n_trees", "." ]
bbb01c03ba49f7bff8f77fd662d00e50d6686c77
https://github.com/lmcinnes/umap/blob/bbb01c03ba49f7bff8f77fd662d00e50d6686c77/umap/rp_tree.py#L698-L728
train
lmcinnes/umap
umap/rp_tree.py
rptree_leaf_array
def rptree_leaf_array(rp_forest): """Generate an array of sets of candidate nearest neighbors by constructing a random projection forest and taking the leaves of all the trees. Any given tree has leaves that are a set of potential nearest neighbors. Given enough trees the set of all such leaves gives a ...
python
def rptree_leaf_array(rp_forest): """Generate an array of sets of candidate nearest neighbors by constructing a random projection forest and taking the leaves of all the trees. Any given tree has leaves that are a set of potential nearest neighbors. Given enough trees the set of all such leaves gives a ...
[ "def", "rptree_leaf_array", "(", "rp_forest", ")", ":", "if", "len", "(", "rp_forest", ")", ">", "0", ":", "leaf_array", "=", "np", ".", "vstack", "(", "[", "tree", ".", "indices", "for", "tree", "in", "rp_forest", "]", ")", "else", ":", "leaf_array", ...
Generate an array of sets of candidate nearest neighbors by constructing a random projection forest and taking the leaves of all the trees. Any given tree has leaves that are a set of potential nearest neighbors. Given enough trees the set of all such leaves gives a good likelihood of getting a good set...
[ "Generate", "an", "array", "of", "sets", "of", "candidate", "nearest", "neighbors", "by", "constructing", "a", "random", "projection", "forest", "and", "taking", "the", "leaves", "of", "all", "the", "trees", ".", "Any", "given", "tree", "has", "leaves", "tha...
bbb01c03ba49f7bff8f77fd662d00e50d6686c77
https://github.com/lmcinnes/umap/blob/bbb01c03ba49f7bff8f77fd662d00e50d6686c77/umap/rp_tree.py#L731-L764
train
lmcinnes/umap
umap/umap_.py
smooth_knn_dist
def smooth_knn_dist(distances, k, n_iter=64, local_connectivity=1.0, bandwidth=1.0): """Compute a continuous version of the distance to the kth nearest neighbor. That is, this is similar to knn-distance but allows continuous k values rather than requiring an integral k. In esscence we are simply computi...
python
def smooth_knn_dist(distances, k, n_iter=64, local_connectivity=1.0, bandwidth=1.0): """Compute a continuous version of the distance to the kth nearest neighbor. That is, this is similar to knn-distance but allows continuous k values rather than requiring an integral k. In esscence we are simply computi...
[ "def", "smooth_knn_dist", "(", "distances", ",", "k", ",", "n_iter", "=", "64", ",", "local_connectivity", "=", "1.0", ",", "bandwidth", "=", "1.0", ")", ":", "target", "=", "np", ".", "log2", "(", "k", ")", "*", "bandwidth", "rho", "=", "np", ".", ...
Compute a continuous version of the distance to the kth nearest neighbor. That is, this is similar to knn-distance but allows continuous k values rather than requiring an integral k. In esscence we are simply computing the distance such that the cardinality of fuzzy set we generate is k. Parameters...
[ "Compute", "a", "continuous", "version", "of", "the", "distance", "to", "the", "kth", "nearest", "neighbor", ".", "That", "is", "this", "is", "similar", "to", "knn", "-", "distance", "but", "allows", "continuous", "k", "values", "rather", "than", "requiring"...
bbb01c03ba49f7bff8f77fd662d00e50d6686c77
https://github.com/lmcinnes/umap/blob/bbb01c03ba49f7bff8f77fd662d00e50d6686c77/umap/umap_.py#L49-L146
train
lmcinnes/umap
umap/umap_.py
nearest_neighbors
def nearest_neighbors( X, n_neighbors, metric, metric_kwds, angular, random_state, verbose=False ): """Compute the ``n_neighbors`` nearest points for each data point in ``X`` under ``metric``. This may be exact, but more likely is approximated via nearest neighbor descent. Parameters ----------...
python
def nearest_neighbors( X, n_neighbors, metric, metric_kwds, angular, random_state, verbose=False ): """Compute the ``n_neighbors`` nearest points for each data point in ``X`` under ``metric``. This may be exact, but more likely is approximated via nearest neighbor descent. Parameters ----------...
[ "def", "nearest_neighbors", "(", "X", ",", "n_neighbors", ",", "metric", ",", "metric_kwds", ",", "angular", ",", "random_state", ",", "verbose", "=", "False", ")", ":", "if", "verbose", ":", "print", "(", "ts", "(", ")", ",", "\"Finding Nearest Neighbors\""...
Compute the ``n_neighbors`` nearest points for each data point in ``X`` under ``metric``. This may be exact, but more likely is approximated via nearest neighbor descent. Parameters ---------- X: array of shape (n_samples, n_features) The input data to compute the k-neighbor graph of. ...
[ "Compute", "the", "n_neighbors", "nearest", "points", "for", "each", "data", "point", "in", "X", "under", "metric", ".", "This", "may", "be", "exact", "but", "more", "likely", "is", "approximated", "via", "nearest", "neighbor", "descent", "." ]
bbb01c03ba49f7bff8f77fd662d00e50d6686c77
https://github.com/lmcinnes/umap/blob/bbb01c03ba49f7bff8f77fd662d00e50d6686c77/umap/umap_.py#L149-L282
train
lmcinnes/umap
umap/umap_.py
compute_membership_strengths
def compute_membership_strengths(knn_indices, knn_dists, sigmas, rhos): """Construct the membership strength data for the 1-skeleton of each local fuzzy simplicial set -- this is formed as a sparse matrix where each row is a local fuzzy simplicial set, with a membership strength for the 1-simplex to eac...
python
def compute_membership_strengths(knn_indices, knn_dists, sigmas, rhos): """Construct the membership strength data for the 1-skeleton of each local fuzzy simplicial set -- this is formed as a sparse matrix where each row is a local fuzzy simplicial set, with a membership strength for the 1-simplex to eac...
[ "def", "compute_membership_strengths", "(", "knn_indices", ",", "knn_dists", ",", "sigmas", ",", "rhos", ")", ":", "n_samples", "=", "knn_indices", ".", "shape", "[", "0", "]", "n_neighbors", "=", "knn_indices", ".", "shape", "[", "1", "]", "rows", "=", "n...
Construct the membership strength data for the 1-skeleton of each local fuzzy simplicial set -- this is formed as a sparse matrix where each row is a local fuzzy simplicial set, with a membership strength for the 1-simplex to each other data point. Parameters ---------- knn_indices: array of sh...
[ "Construct", "the", "membership", "strength", "data", "for", "the", "1", "-", "skeleton", "of", "each", "local", "fuzzy", "simplicial", "set", "--", "this", "is", "formed", "as", "a", "sparse", "matrix", "where", "each", "row", "is", "a", "local", "fuzzy",...
bbb01c03ba49f7bff8f77fd662d00e50d6686c77
https://github.com/lmcinnes/umap/blob/bbb01c03ba49f7bff8f77fd662d00e50d6686c77/umap/umap_.py#L286-L339
train
lmcinnes/umap
umap/umap_.py
fuzzy_simplicial_set
def fuzzy_simplicial_set( X, n_neighbors, random_state, metric, metric_kwds={}, knn_indices=None, knn_dists=None, angular=False, set_op_mix_ratio=1.0, local_connectivity=1.0, verbose=False, ): """Given a set of data X, a neighborhood size, and a measure of distance co...
python
def fuzzy_simplicial_set( X, n_neighbors, random_state, metric, metric_kwds={}, knn_indices=None, knn_dists=None, angular=False, set_op_mix_ratio=1.0, local_connectivity=1.0, verbose=False, ): """Given a set of data X, a neighborhood size, and a measure of distance co...
[ "def", "fuzzy_simplicial_set", "(", "X", ",", "n_neighbors", ",", "random_state", ",", "metric", ",", "metric_kwds", "=", "{", "}", ",", "knn_indices", "=", "None", ",", "knn_dists", "=", "None", ",", "angular", "=", "False", ",", "set_op_mix_ratio", "=", ...
Given a set of data X, a neighborhood size, and a measure of distance compute the fuzzy simplicial set (here represented as a fuzzy graph in the form of a sparse matrix) associated to the data. This is done by locally approximating geodesic distance at each point, creating a fuzzy simplicial set for eac...
[ "Given", "a", "set", "of", "data", "X", "a", "neighborhood", "size", "and", "a", "measure", "of", "distance", "compute", "the", "fuzzy", "simplicial", "set", "(", "here", "represented", "as", "a", "fuzzy", "graph", "in", "the", "form", "of", "a", "sparse...
bbb01c03ba49f7bff8f77fd662d00e50d6686c77
https://github.com/lmcinnes/umap/blob/bbb01c03ba49f7bff8f77fd662d00e50d6686c77/umap/umap_.py#L343-L488
train
lmcinnes/umap
umap/umap_.py
fast_intersection
def fast_intersection(rows, cols, values, target, unknown_dist=1.0, far_dist=5.0): """Under the assumption of categorical distance for the intersecting simplicial set perform a fast intersection. Parameters ---------- rows: array An array of the row of each non-zero in the sparse matrix ...
python
def fast_intersection(rows, cols, values, target, unknown_dist=1.0, far_dist=5.0): """Under the assumption of categorical distance for the intersecting simplicial set perform a fast intersection. Parameters ---------- rows: array An array of the row of each non-zero in the sparse matrix ...
[ "def", "fast_intersection", "(", "rows", ",", "cols", ",", "values", ",", "target", ",", "unknown_dist", "=", "1.0", ",", "far_dist", "=", "5.0", ")", ":", "for", "nz", "in", "range", "(", "rows", ".", "shape", "[", "0", "]", ")", ":", "i", "=", ...
Under the assumption of categorical distance for the intersecting simplicial set perform a fast intersection. Parameters ---------- rows: array An array of the row of each non-zero in the sparse matrix representation. cols: array An array of the column of each non-zero in t...
[ "Under", "the", "assumption", "of", "categorical", "distance", "for", "the", "intersecting", "simplicial", "set", "perform", "a", "fast", "intersection", "." ]
bbb01c03ba49f7bff8f77fd662d00e50d6686c77
https://github.com/lmcinnes/umap/blob/bbb01c03ba49f7bff8f77fd662d00e50d6686c77/umap/umap_.py#L492-L531
train
lmcinnes/umap
umap/umap_.py
reset_local_connectivity
def reset_local_connectivity(simplicial_set): """Reset the local connectivity requirement -- each data sample should have complete confidence in at least one 1-simplex in the simplicial set. We can enforce this by locally rescaling confidences, and then remerging the different local simplicial sets toge...
python
def reset_local_connectivity(simplicial_set): """Reset the local connectivity requirement -- each data sample should have complete confidence in at least one 1-simplex in the simplicial set. We can enforce this by locally rescaling confidences, and then remerging the different local simplicial sets toge...
[ "def", "reset_local_connectivity", "(", "simplicial_set", ")", ":", "simplicial_set", "=", "normalize", "(", "simplicial_set", ",", "norm", "=", "\"max\"", ")", "transpose", "=", "simplicial_set", ".", "transpose", "(", ")", "prod_matrix", "=", "simplicial_set", "...
Reset the local connectivity requirement -- each data sample should have complete confidence in at least one 1-simplex in the simplicial set. We can enforce this by locally rescaling confidences, and then remerging the different local simplicial sets together. Parameters ---------- simplicial_s...
[ "Reset", "the", "local", "connectivity", "requirement", "--", "each", "data", "sample", "should", "have", "complete", "confidence", "in", "at", "least", "one", "1", "-", "simplex", "in", "the", "simplicial", "set", ".", "We", "can", "enforce", "this", "by", ...
bbb01c03ba49f7bff8f77fd662d00e50d6686c77
https://github.com/lmcinnes/umap/blob/bbb01c03ba49f7bff8f77fd662d00e50d6686c77/umap/umap_.py#L535-L559
train
lmcinnes/umap
umap/umap_.py
categorical_simplicial_set_intersection
def categorical_simplicial_set_intersection( simplicial_set, target, unknown_dist=1.0, far_dist=5.0 ): """Combine a fuzzy simplicial set with another fuzzy simplicial set generated from categorical data using categorical distances. The target data is assumed to be categorical label data (a vector of lab...
python
def categorical_simplicial_set_intersection( simplicial_set, target, unknown_dist=1.0, far_dist=5.0 ): """Combine a fuzzy simplicial set with another fuzzy simplicial set generated from categorical data using categorical distances. The target data is assumed to be categorical label data (a vector of lab...
[ "def", "categorical_simplicial_set_intersection", "(", "simplicial_set", ",", "target", ",", "unknown_dist", "=", "1.0", ",", "far_dist", "=", "5.0", ")", ":", "simplicial_set", "=", "simplicial_set", ".", "tocoo", "(", ")", "fast_intersection", "(", "simplicial_set...
Combine a fuzzy simplicial set with another fuzzy simplicial set generated from categorical data using categorical distances. The target data is assumed to be categorical label data (a vector of labels), and this will update the fuzzy simplicial set to respect that label data. TODO: optional category c...
[ "Combine", "a", "fuzzy", "simplicial", "set", "with", "another", "fuzzy", "simplicial", "set", "generated", "from", "categorical", "data", "using", "categorical", "distances", ".", "The", "target", "data", "is", "assumed", "to", "be", "categorical", "label", "da...
bbb01c03ba49f7bff8f77fd662d00e50d6686c77
https://github.com/lmcinnes/umap/blob/bbb01c03ba49f7bff8f77fd662d00e50d6686c77/umap/umap_.py#L563-L605
train
lmcinnes/umap
umap/umap_.py
make_epochs_per_sample
def make_epochs_per_sample(weights, n_epochs): """Given a set of weights and number of epochs generate the number of epochs per sample for each weight. Parameters ---------- weights: array of shape (n_1_simplices) The weights ofhow much we wish to sample each 1-simplex. n_epochs: int ...
python
def make_epochs_per_sample(weights, n_epochs): """Given a set of weights and number of epochs generate the number of epochs per sample for each weight. Parameters ---------- weights: array of shape (n_1_simplices) The weights ofhow much we wish to sample each 1-simplex. n_epochs: int ...
[ "def", "make_epochs_per_sample", "(", "weights", ",", "n_epochs", ")", ":", "result", "=", "-", "1.0", "*", "np", ".", "ones", "(", "weights", ".", "shape", "[", "0", "]", ",", "dtype", "=", "np", ".", "float64", ")", "n_samples", "=", "n_epochs", "*...
Given a set of weights and number of epochs generate the number of epochs per sample for each weight. Parameters ---------- weights: array of shape (n_1_simplices) The weights ofhow much we wish to sample each 1-simplex. n_epochs: int The total number of epochs we want to train for...
[ "Given", "a", "set", "of", "weights", "and", "number", "of", "epochs", "generate", "the", "number", "of", "epochs", "per", "sample", "for", "each", "weight", "." ]
bbb01c03ba49f7bff8f77fd662d00e50d6686c77
https://github.com/lmcinnes/umap/blob/bbb01c03ba49f7bff8f77fd662d00e50d6686c77/umap/umap_.py#L632-L651
train
lmcinnes/umap
umap/umap_.py
rdist
def rdist(x, y): """Reduced Euclidean distance. Parameters ---------- x: array of shape (embedding_dim,) y: array of shape (embedding_dim,) Returns ------- The squared euclidean distance between x and y """ result = 0.0 for i in range(x.shape[0]): result += (x[i] - ...
python
def rdist(x, y): """Reduced Euclidean distance. Parameters ---------- x: array of shape (embedding_dim,) y: array of shape (embedding_dim,) Returns ------- The squared euclidean distance between x and y """ result = 0.0 for i in range(x.shape[0]): result += (x[i] - ...
[ "def", "rdist", "(", "x", ",", "y", ")", ":", "result", "=", "0.0", "for", "i", "in", "range", "(", "x", ".", "shape", "[", "0", "]", ")", ":", "result", "+=", "(", "x", "[", "i", "]", "-", "y", "[", "i", "]", ")", "**", "2", "return", ...
Reduced Euclidean distance. Parameters ---------- x: array of shape (embedding_dim,) y: array of shape (embedding_dim,) Returns ------- The squared euclidean distance between x and y
[ "Reduced", "Euclidean", "distance", "." ]
bbb01c03ba49f7bff8f77fd662d00e50d6686c77
https://github.com/lmcinnes/umap/blob/bbb01c03ba49f7bff8f77fd662d00e50d6686c77/umap/umap_.py#L677-L693
train
lmcinnes/umap
umap/umap_.py
optimize_layout
def optimize_layout( head_embedding, tail_embedding, head, tail, n_epochs, n_vertices, epochs_per_sample, a, b, rng_state, gamma=1.0, initial_alpha=1.0, negative_sample_rate=5.0, verbose=False, ): """Improve an embedding using stochastic gradient descent to mi...
python
def optimize_layout( head_embedding, tail_embedding, head, tail, n_epochs, n_vertices, epochs_per_sample, a, b, rng_state, gamma=1.0, initial_alpha=1.0, negative_sample_rate=5.0, verbose=False, ): """Improve an embedding using stochastic gradient descent to mi...
[ "def", "optimize_layout", "(", "head_embedding", ",", "tail_embedding", ",", "head", ",", "tail", ",", "n_epochs", ",", "n_vertices", ",", "epochs_per_sample", ",", "a", ",", "b", ",", "rng_state", ",", "gamma", "=", "1.0", ",", "initial_alpha", "=", "1.0", ...
Improve an embedding using stochastic gradient descent to minimize the fuzzy set cross entropy between the 1-skeletons of the high dimensional and low dimensional fuzzy simplicial sets. In practice this is done by sampling edges based on their membership strength (with the (1-p) terms coming from negati...
[ "Improve", "an", "embedding", "using", "stochastic", "gradient", "descent", "to", "minimize", "the", "fuzzy", "set", "cross", "entropy", "between", "the", "1", "-", "skeletons", "of", "the", "high", "dimensional", "and", "low", "dimensional", "fuzzy", "simplicia...
bbb01c03ba49f7bff8f77fd662d00e50d6686c77
https://github.com/lmcinnes/umap/blob/bbb01c03ba49f7bff8f77fd662d00e50d6686c77/umap/umap_.py#L697-L844
train
lmcinnes/umap
umap/umap_.py
simplicial_set_embedding
def simplicial_set_embedding( data, graph, n_components, initial_alpha, a, b, gamma, negative_sample_rate, n_epochs, init, random_state, metric, metric_kwds, verbose, ): """Perform a fuzzy simplicial set embedding, using a specified initialisation method a...
python
def simplicial_set_embedding( data, graph, n_components, initial_alpha, a, b, gamma, negative_sample_rate, n_epochs, init, random_state, metric, metric_kwds, verbose, ): """Perform a fuzzy simplicial set embedding, using a specified initialisation method a...
[ "def", "simplicial_set_embedding", "(", "data", ",", "graph", ",", "n_components", ",", "initial_alpha", ",", "a", ",", "b", ",", "gamma", ",", "negative_sample_rate", ",", "n_epochs", ",", "init", ",", "random_state", ",", "metric", ",", "metric_kwds", ",", ...
Perform a fuzzy simplicial set embedding, using a specified initialisation method and then minimizing the fuzzy set cross entropy between the 1-skeletons of the high and low dimensional fuzzy simplicial sets. Parameters ---------- data: array of shape (n_samples, n_features) The source ...
[ "Perform", "a", "fuzzy", "simplicial", "set", "embedding", "using", "a", "specified", "initialisation", "method", "and", "then", "minimizing", "the", "fuzzy", "set", "cross", "entropy", "between", "the", "1", "-", "skeletons", "of", "the", "high", "and", "low"...
bbb01c03ba49f7bff8f77fd662d00e50d6686c77
https://github.com/lmcinnes/umap/blob/bbb01c03ba49f7bff8f77fd662d00e50d6686c77/umap/umap_.py#L847-L1003
train
lmcinnes/umap
umap/umap_.py
init_transform
def init_transform(indices, weights, embedding): """Given indices and weights and an original embeddings initialize the positions of new points relative to the indices and weights (of their neighbors in the source data). Parameters ---------- indices: array of shape (n_new_samples, n_neighbors)...
python
def init_transform(indices, weights, embedding): """Given indices and weights and an original embeddings initialize the positions of new points relative to the indices and weights (of their neighbors in the source data). Parameters ---------- indices: array of shape (n_new_samples, n_neighbors)...
[ "def", "init_transform", "(", "indices", ",", "weights", ",", "embedding", ")", ":", "result", "=", "np", ".", "zeros", "(", "(", "indices", ".", "shape", "[", "0", "]", ",", "embedding", ".", "shape", "[", "1", "]", ")", ",", "dtype", "=", "np", ...
Given indices and weights and an original embeddings initialize the positions of new points relative to the indices and weights (of their neighbors in the source data). Parameters ---------- indices: array of shape (n_new_samples, n_neighbors) The indices of the neighbors of each new sample...
[ "Given", "indices", "and", "weights", "and", "an", "original", "embeddings", "initialize", "the", "positions", "of", "new", "points", "relative", "to", "the", "indices", "and", "weights", "(", "of", "their", "neighbors", "in", "the", "source", "data", ")", "...
bbb01c03ba49f7bff8f77fd662d00e50d6686c77
https://github.com/lmcinnes/umap/blob/bbb01c03ba49f7bff8f77fd662d00e50d6686c77/umap/umap_.py#L1007-L1036
train
lmcinnes/umap
umap/umap_.py
find_ab_params
def find_ab_params(spread, min_dist): """Fit a, b params for the differentiable curve used in lower dimensional fuzzy simplicial complex construction. We want the smooth curve (from a pre-defined family with simple gradient) that best matches an offset exponential decay. """ def curve(x, a, b):...
python
def find_ab_params(spread, min_dist): """Fit a, b params for the differentiable curve used in lower dimensional fuzzy simplicial complex construction. We want the smooth curve (from a pre-defined family with simple gradient) that best matches an offset exponential decay. """ def curve(x, a, b):...
[ "def", "find_ab_params", "(", "spread", ",", "min_dist", ")", ":", "def", "curve", "(", "x", ",", "a", ",", "b", ")", ":", "return", "1.0", "/", "(", "1.0", "+", "a", "*", "x", "**", "(", "2", "*", "b", ")", ")", "xv", "=", "np", ".", "lins...
Fit a, b params for the differentiable curve used in lower dimensional fuzzy simplicial complex construction. We want the smooth curve (from a pre-defined family with simple gradient) that best matches an offset exponential decay.
[ "Fit", "a", "b", "params", "for", "the", "differentiable", "curve", "used", "in", "lower", "dimensional", "fuzzy", "simplicial", "complex", "construction", ".", "We", "want", "the", "smooth", "curve", "(", "from", "a", "pre", "-", "defined", "family", "with"...
bbb01c03ba49f7bff8f77fd662d00e50d6686c77
https://github.com/lmcinnes/umap/blob/bbb01c03ba49f7bff8f77fd662d00e50d6686c77/umap/umap_.py#L1039-L1054
train
lmcinnes/umap
umap/umap_.py
UMAP.fit
def fit(self, X, y=None): """Fit X into an embedded space. Optionally use y for supervised dimension reduction. Parameters ---------- X : array, shape (n_samples, n_features) or (n_samples, n_samples) If the metric is 'precomputed' X must be a square distance ...
python
def fit(self, X, y=None): """Fit X into an embedded space. Optionally use y for supervised dimension reduction. Parameters ---------- X : array, shape (n_samples, n_features) or (n_samples, n_samples) If the metric is 'precomputed' X must be a square distance ...
[ "def", "fit", "(", "self", ",", "X", ",", "y", "=", "None", ")", ":", "X", "=", "check_array", "(", "X", ",", "dtype", "=", "np", ".", "float32", ",", "accept_sparse", "=", "\"csr\"", ")", "self", ".", "_raw_data", "=", "X", "# Handle all the optiona...
Fit X into an embedded space. Optionally use y for supervised dimension reduction. Parameters ---------- X : array, shape (n_samples, n_features) or (n_samples, n_samples) If the metric is 'precomputed' X must be a square distance matrix. Otherwise it contains a...
[ "Fit", "X", "into", "an", "embedded", "space", "." ]
bbb01c03ba49f7bff8f77fd662d00e50d6686c77
https://github.com/lmcinnes/umap/blob/bbb01c03ba49f7bff8f77fd662d00e50d6686c77/umap/umap_.py#L1319-L1566
train
lmcinnes/umap
umap/umap_.py
UMAP.fit_transform
def fit_transform(self, X, y=None): """Fit X into an embedded space and return that transformed output. Parameters ---------- X : array, shape (n_samples, n_features) or (n_samples, n_samples) If the metric is 'precomputed' X must be a square distance mat...
python
def fit_transform(self, X, y=None): """Fit X into an embedded space and return that transformed output. Parameters ---------- X : array, shape (n_samples, n_features) or (n_samples, n_samples) If the metric is 'precomputed' X must be a square distance mat...
[ "def", "fit_transform", "(", "self", ",", "X", ",", "y", "=", "None", ")", ":", "self", ".", "fit", "(", "X", ",", "y", ")", "return", "self", ".", "embedding_" ]
Fit X into an embedded space and return that transformed output. Parameters ---------- X : array, shape (n_samples, n_features) or (n_samples, n_samples) If the metric is 'precomputed' X must be a square distance matrix. Otherwise it contains a sample per row. ...
[ "Fit", "X", "into", "an", "embedded", "space", "and", "return", "that", "transformed", "output", "." ]
bbb01c03ba49f7bff8f77fd662d00e50d6686c77
https://github.com/lmcinnes/umap/blob/bbb01c03ba49f7bff8f77fd662d00e50d6686c77/umap/umap_.py#L1568-L1590
train
lmcinnes/umap
umap/umap_.py
UMAP.transform
def transform(self, X): """Transform X into the existing embedded space and return that transformed output. Parameters ---------- X : array, shape (n_samples, n_features) New data to be transformed. Returns ------- X_new : array, shape (n_sam...
python
def transform(self, X): """Transform X into the existing embedded space and return that transformed output. Parameters ---------- X : array, shape (n_samples, n_features) New data to be transformed. Returns ------- X_new : array, shape (n_sam...
[ "def", "transform", "(", "self", ",", "X", ")", ":", "# If we fit just a single instance then error", "if", "self", ".", "embedding_", ".", "shape", "[", "0", "]", "==", "1", ":", "raise", "ValueError", "(", "'Transform unavailable when model was fit with'", "'only ...
Transform X into the existing embedded space and return that transformed output. Parameters ---------- X : array, shape (n_samples, n_features) New data to be transformed. Returns ------- X_new : array, shape (n_samples, n_components) Emb...
[ "Transform", "X", "into", "the", "existing", "embedded", "space", "and", "return", "that", "transformed", "output", "." ]
bbb01c03ba49f7bff8f77fd662d00e50d6686c77
https://github.com/lmcinnes/umap/blob/bbb01c03ba49f7bff8f77fd662d00e50d6686c77/umap/umap_.py#L1592-L1712
train
lmcinnes/umap
umap/sparse.py
make_sparse_nn_descent
def make_sparse_nn_descent(sparse_dist, dist_args): """Create a numba accelerated version of nearest neighbor descent specialised for the given distance metric and metric arguments on sparse matrix data provided in CSR ind, indptr and data format. Numba doesn't support higher order functions directly, b...
python
def make_sparse_nn_descent(sparse_dist, dist_args): """Create a numba accelerated version of nearest neighbor descent specialised for the given distance metric and metric arguments on sparse matrix data provided in CSR ind, indptr and data format. Numba doesn't support higher order functions directly, b...
[ "def", "make_sparse_nn_descent", "(", "sparse_dist", ",", "dist_args", ")", ":", "@", "numba", ".", "njit", "(", "parallel", "=", "True", ")", "def", "nn_descent", "(", "inds", ",", "indptr", ",", "data", ",", "n_vertices", ",", "n_neighbors", ",", "rng_st...
Create a numba accelerated version of nearest neighbor descent specialised for the given distance metric and metric arguments on sparse matrix data provided in CSR ind, indptr and data format. Numba doesn't support higher order functions directly, but we can instead JIT compile the version of NN-descent...
[ "Create", "a", "numba", "accelerated", "version", "of", "nearest", "neighbor", "descent", "specialised", "for", "the", "given", "distance", "metric", "and", "metric", "arguments", "on", "sparse", "matrix", "data", "provided", "in", "CSR", "ind", "indptr", "and",...
bbb01c03ba49f7bff8f77fd662d00e50d6686c77
https://github.com/lmcinnes/umap/blob/bbb01c03ba49f7bff8f77fd662d00e50d6686c77/umap/sparse.py#L152-L283
train
deepmind/pysc2
pysc2/bin/benchmark_observe.py
interface_options
def interface_options(score=False, raw=False, features=None, rgb=None): """Get an InterfaceOptions for the config.""" interface = sc_pb.InterfaceOptions() interface.score = score interface.raw = raw if features: interface.feature_layer.width = 24 interface.feature_layer.resolution.x = features int...
python
def interface_options(score=False, raw=False, features=None, rgb=None): """Get an InterfaceOptions for the config.""" interface = sc_pb.InterfaceOptions() interface.score = score interface.raw = raw if features: interface.feature_layer.width = 24 interface.feature_layer.resolution.x = features int...
[ "def", "interface_options", "(", "score", "=", "False", ",", "raw", "=", "False", ",", "features", "=", "None", ",", "rgb", "=", "None", ")", ":", "interface", "=", "sc_pb", ".", "InterfaceOptions", "(", ")", "interface", ".", "score", "=", "score", "i...
Get an InterfaceOptions for the config.
[ "Get", "an", "InterfaceOptions", "for", "the", "config", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/bin/benchmark_observe.py#L39-L55
train
deepmind/pysc2
pysc2/lib/point_flag.py
DEFINE_point
def DEFINE_point(name, default, help): # pylint: disable=invalid-name,redefined-builtin """Registers a flag whose value parses as a point.""" flags.DEFINE(PointParser(), name, default, help)
python
def DEFINE_point(name, default, help): # pylint: disable=invalid-name,redefined-builtin """Registers a flag whose value parses as a point.""" flags.DEFINE(PointParser(), name, default, help)
[ "def", "DEFINE_point", "(", "name", ",", "default", ",", "help", ")", ":", "# pylint: disable=invalid-name,redefined-builtin", "flags", ".", "DEFINE", "(", "PointParser", "(", ")", ",", "name", ",", "default", ",", "help", ")" ]
Registers a flag whose value parses as a point.
[ "Registers", "a", "flag", "whose", "value", "parses", "as", "a", "point", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/point_flag.py#L56-L58
train
deepmind/pysc2
pysc2/lib/actions.py
spatial
def spatial(action, action_space): """Choose the action space for the action proto.""" if action_space == ActionSpace.FEATURES: return action.action_feature_layer elif action_space == ActionSpace.RGB: return action.action_render else: raise ValueError("Unexpected value for action_space: %s" % action...
python
def spatial(action, action_space): """Choose the action space for the action proto.""" if action_space == ActionSpace.FEATURES: return action.action_feature_layer elif action_space == ActionSpace.RGB: return action.action_render else: raise ValueError("Unexpected value for action_space: %s" % action...
[ "def", "spatial", "(", "action", ",", "action_space", ")", ":", "if", "action_space", "==", "ActionSpace", ".", "FEATURES", ":", "return", "action", ".", "action_feature_layer", "elif", "action_space", "==", "ActionSpace", ".", "RGB", ":", "return", "action", ...
Choose the action space for the action proto.
[ "Choose", "the", "action", "space", "for", "the", "action", "proto", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/actions.py#L36-L43
train
deepmind/pysc2
pysc2/lib/actions.py
move_camera
def move_camera(action, action_space, minimap): """Move the camera.""" minimap.assign_to(spatial(action, action_space).camera_move.center_minimap)
python
def move_camera(action, action_space, minimap): """Move the camera.""" minimap.assign_to(spatial(action, action_space).camera_move.center_minimap)
[ "def", "move_camera", "(", "action", ",", "action_space", ",", "minimap", ")", ":", "minimap", ".", "assign_to", "(", "spatial", "(", "action", ",", "action_space", ")", ".", "camera_move", ".", "center_minimap", ")" ]
Move the camera.
[ "Move", "the", "camera", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/actions.py#L50-L52
train
deepmind/pysc2
pysc2/lib/actions.py
select_point
def select_point(action, action_space, select_point_act, screen): """Select a unit at a point.""" select = spatial(action, action_space).unit_selection_point screen.assign_to(select.selection_screen_coord) select.type = select_point_act
python
def select_point(action, action_space, select_point_act, screen): """Select a unit at a point.""" select = spatial(action, action_space).unit_selection_point screen.assign_to(select.selection_screen_coord) select.type = select_point_act
[ "def", "select_point", "(", "action", ",", "action_space", ",", "select_point_act", ",", "screen", ")", ":", "select", "=", "spatial", "(", "action", ",", "action_space", ")", ".", "unit_selection_point", "screen", ".", "assign_to", "(", "select", ".", "select...
Select a unit at a point.
[ "Select", "a", "unit", "at", "a", "point", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/actions.py#L55-L59
train
deepmind/pysc2
pysc2/lib/actions.py
select_rect
def select_rect(action, action_space, select_add, screen, screen2): """Select units within a rectangle.""" select = spatial(action, action_space).unit_selection_rect out_rect = select.selection_screen_coord.add() screen_rect = point.Rect(screen, screen2) screen_rect.tl.assign_to(out_rect.p0) screen_rect.br....
python
def select_rect(action, action_space, select_add, screen, screen2): """Select units within a rectangle.""" select = spatial(action, action_space).unit_selection_rect out_rect = select.selection_screen_coord.add() screen_rect = point.Rect(screen, screen2) screen_rect.tl.assign_to(out_rect.p0) screen_rect.br....
[ "def", "select_rect", "(", "action", ",", "action_space", ",", "select_add", ",", "screen", ",", "screen2", ")", ":", "select", "=", "spatial", "(", "action", ",", "action_space", ")", ".", "unit_selection_rect", "out_rect", "=", "select", ".", "selection_scre...
Select units within a rectangle.
[ "Select", "units", "within", "a", "rectangle", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/actions.py#L62-L69
train
deepmind/pysc2
pysc2/lib/actions.py
select_idle_worker
def select_idle_worker(action, action_space, select_worker): """Select an idle worker.""" del action_space action.action_ui.select_idle_worker.type = select_worker
python
def select_idle_worker(action, action_space, select_worker): """Select an idle worker.""" del action_space action.action_ui.select_idle_worker.type = select_worker
[ "def", "select_idle_worker", "(", "action", ",", "action_space", ",", "select_worker", ")", ":", "del", "action_space", "action", ".", "action_ui", ".", "select_idle_worker", ".", "type", "=", "select_worker" ]
Select an idle worker.
[ "Select", "an", "idle", "worker", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/actions.py#L72-L75
train
deepmind/pysc2
pysc2/lib/actions.py
select_army
def select_army(action, action_space, select_add): """Select the entire army.""" del action_space action.action_ui.select_army.selection_add = select_add
python
def select_army(action, action_space, select_add): """Select the entire army.""" del action_space action.action_ui.select_army.selection_add = select_add
[ "def", "select_army", "(", "action", ",", "action_space", ",", "select_add", ")", ":", "del", "action_space", "action", ".", "action_ui", ".", "select_army", ".", "selection_add", "=", "select_add" ]
Select the entire army.
[ "Select", "the", "entire", "army", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/actions.py#L78-L81
train
deepmind/pysc2
pysc2/lib/actions.py
select_warp_gates
def select_warp_gates(action, action_space, select_add): """Select all warp gates.""" del action_space action.action_ui.select_warp_gates.selection_add = select_add
python
def select_warp_gates(action, action_space, select_add): """Select all warp gates.""" del action_space action.action_ui.select_warp_gates.selection_add = select_add
[ "def", "select_warp_gates", "(", "action", ",", "action_space", ",", "select_add", ")", ":", "del", "action_space", "action", ".", "action_ui", ".", "select_warp_gates", ".", "selection_add", "=", "select_add" ]
Select all warp gates.
[ "Select", "all", "warp", "gates", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/actions.py#L84-L87
train
deepmind/pysc2
pysc2/lib/actions.py
select_unit
def select_unit(action, action_space, select_unit_act, select_unit_id): """Select a specific unit from the multi-unit selection.""" del action_space select = action.action_ui.multi_panel select.type = select_unit_act select.unit_index = select_unit_id
python
def select_unit(action, action_space, select_unit_act, select_unit_id): """Select a specific unit from the multi-unit selection.""" del action_space select = action.action_ui.multi_panel select.type = select_unit_act select.unit_index = select_unit_id
[ "def", "select_unit", "(", "action", ",", "action_space", ",", "select_unit_act", ",", "select_unit_id", ")", ":", "del", "action_space", "select", "=", "action", ".", "action_ui", ".", "multi_panel", "select", ".", "type", "=", "select_unit_act", "select", ".",...
Select a specific unit from the multi-unit selection.
[ "Select", "a", "specific", "unit", "from", "the", "multi", "-", "unit", "selection", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/actions.py#L96-L101
train
deepmind/pysc2
pysc2/lib/actions.py
control_group
def control_group(action, action_space, control_group_act, control_group_id): """Act on a control group, selecting, setting, etc.""" del action_space select = action.action_ui.control_group select.action = control_group_act select.control_group_index = control_group_id
python
def control_group(action, action_space, control_group_act, control_group_id): """Act on a control group, selecting, setting, etc.""" del action_space select = action.action_ui.control_group select.action = control_group_act select.control_group_index = control_group_id
[ "def", "control_group", "(", "action", ",", "action_space", ",", "control_group_act", ",", "control_group_id", ")", ":", "del", "action_space", "select", "=", "action", ".", "action_ui", ".", "control_group", "select", ".", "action", "=", "control_group_act", "sel...
Act on a control group, selecting, setting, etc.
[ "Act", "on", "a", "control", "group", "selecting", "setting", "etc", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/actions.py#L104-L109
train
deepmind/pysc2
pysc2/lib/actions.py
unload
def unload(action, action_space, unload_id): """Unload a unit from a transport/bunker/nydus/etc.""" del action_space action.action_ui.cargo_panel.unit_index = unload_id
python
def unload(action, action_space, unload_id): """Unload a unit from a transport/bunker/nydus/etc.""" del action_space action.action_ui.cargo_panel.unit_index = unload_id
[ "def", "unload", "(", "action", ",", "action_space", ",", "unload_id", ")", ":", "del", "action_space", "action", ".", "action_ui", ".", "cargo_panel", ".", "unit_index", "=", "unload_id" ]
Unload a unit from a transport/bunker/nydus/etc.
[ "Unload", "a", "unit", "from", "a", "transport", "/", "bunker", "/", "nydus", "/", "etc", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/actions.py#L112-L115
train
deepmind/pysc2
pysc2/lib/actions.py
build_queue
def build_queue(action, action_space, build_queue_id): """Cancel a unit in the build queue.""" del action_space action.action_ui.production_panel.unit_index = build_queue_id
python
def build_queue(action, action_space, build_queue_id): """Cancel a unit in the build queue.""" del action_space action.action_ui.production_panel.unit_index = build_queue_id
[ "def", "build_queue", "(", "action", ",", "action_space", ",", "build_queue_id", ")", ":", "del", "action_space", "action", ".", "action_ui", ".", "production_panel", ".", "unit_index", "=", "build_queue_id" ]
Cancel a unit in the build queue.
[ "Cancel", "a", "unit", "in", "the", "build", "queue", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/actions.py#L118-L121
train
deepmind/pysc2
pysc2/lib/actions.py
cmd_quick
def cmd_quick(action, action_space, ability_id, queued): """Do a quick command like 'Stop' or 'Stim'.""" action_cmd = spatial(action, action_space).unit_command action_cmd.ability_id = ability_id action_cmd.queue_command = queued
python
def cmd_quick(action, action_space, ability_id, queued): """Do a quick command like 'Stop' or 'Stim'.""" action_cmd = spatial(action, action_space).unit_command action_cmd.ability_id = ability_id action_cmd.queue_command = queued
[ "def", "cmd_quick", "(", "action", ",", "action_space", ",", "ability_id", ",", "queued", ")", ":", "action_cmd", "=", "spatial", "(", "action", ",", "action_space", ")", ".", "unit_command", "action_cmd", ".", "ability_id", "=", "ability_id", "action_cmd", "....
Do a quick command like 'Stop' or 'Stim'.
[ "Do", "a", "quick", "command", "like", "Stop", "or", "Stim", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/actions.py#L124-L128
train
deepmind/pysc2
pysc2/lib/actions.py
cmd_screen
def cmd_screen(action, action_space, ability_id, queued, screen): """Do a command that needs a point on the screen.""" action_cmd = spatial(action, action_space).unit_command action_cmd.ability_id = ability_id action_cmd.queue_command = queued screen.assign_to(action_cmd.target_screen_coord)
python
def cmd_screen(action, action_space, ability_id, queued, screen): """Do a command that needs a point on the screen.""" action_cmd = spatial(action, action_space).unit_command action_cmd.ability_id = ability_id action_cmd.queue_command = queued screen.assign_to(action_cmd.target_screen_coord)
[ "def", "cmd_screen", "(", "action", ",", "action_space", ",", "ability_id", ",", "queued", ",", "screen", ")", ":", "action_cmd", "=", "spatial", "(", "action", ",", "action_space", ")", ".", "unit_command", "action_cmd", ".", "ability_id", "=", "ability_id", ...
Do a command that needs a point on the screen.
[ "Do", "a", "command", "that", "needs", "a", "point", "on", "the", "screen", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/actions.py#L131-L136
train
deepmind/pysc2
pysc2/lib/actions.py
cmd_minimap
def cmd_minimap(action, action_space, ability_id, queued, minimap): """Do a command that needs a point on the minimap.""" action_cmd = spatial(action, action_space).unit_command action_cmd.ability_id = ability_id action_cmd.queue_command = queued minimap.assign_to(action_cmd.target_minimap_coord)
python
def cmd_minimap(action, action_space, ability_id, queued, minimap): """Do a command that needs a point on the minimap.""" action_cmd = spatial(action, action_space).unit_command action_cmd.ability_id = ability_id action_cmd.queue_command = queued minimap.assign_to(action_cmd.target_minimap_coord)
[ "def", "cmd_minimap", "(", "action", ",", "action_space", ",", "ability_id", ",", "queued", ",", "minimap", ")", ":", "action_cmd", "=", "spatial", "(", "action", ",", "action_space", ")", ".", "unit_command", "action_cmd", ".", "ability_id", "=", "ability_id"...
Do a command that needs a point on the minimap.
[ "Do", "a", "command", "that", "needs", "a", "point", "on", "the", "minimap", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/actions.py#L139-L144
train
deepmind/pysc2
pysc2/lib/actions.py
autocast
def autocast(action, action_space, ability_id): """Toggle autocast.""" del action_space action.action_ui.toggle_autocast.ability_id = ability_id
python
def autocast(action, action_space, ability_id): """Toggle autocast.""" del action_space action.action_ui.toggle_autocast.ability_id = ability_id
[ "def", "autocast", "(", "action", ",", "action_space", ",", "ability_id", ")", ":", "del", "action_space", "action", ".", "action_ui", ".", "toggle_autocast", ".", "ability_id", "=", "ability_id" ]
Toggle autocast.
[ "Toggle", "autocast", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/actions.py#L147-L150
train
deepmind/pysc2
pysc2/lib/actions.py
ArgumentType.enum
def enum(cls, options, values): """Create an ArgumentType where you choose one of a set of known values.""" names, real = zip(*options) del names # unused def factory(i, name): return cls(i, name, (len(real),), lambda a: real[a[0]], values) return factory
python
def enum(cls, options, values): """Create an ArgumentType where you choose one of a set of known values.""" names, real = zip(*options) del names # unused def factory(i, name): return cls(i, name, (len(real),), lambda a: real[a[0]], values) return factory
[ "def", "enum", "(", "cls", ",", "options", ",", "values", ")", ":", "names", ",", "real", "=", "zip", "(", "*", "options", ")", "del", "names", "# unused", "def", "factory", "(", "i", ",", "name", ")", ":", "return", "cls", "(", "i", ",", "name",...
Create an ArgumentType where you choose one of a set of known values.
[ "Create", "an", "ArgumentType", "where", "you", "choose", "one", "of", "a", "set", "of", "known", "values", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/actions.py#L175-L182
train
deepmind/pysc2
pysc2/lib/actions.py
ArgumentType.scalar
def scalar(cls, value): """Create an ArgumentType with a single scalar in range(value).""" return lambda i, name: cls(i, name, (value,), lambda a: a[0], None)
python
def scalar(cls, value): """Create an ArgumentType with a single scalar in range(value).""" return lambda i, name: cls(i, name, (value,), lambda a: a[0], None)
[ "def", "scalar", "(", "cls", ",", "value", ")", ":", "return", "lambda", "i", ",", "name", ":", "cls", "(", "i", ",", "name", ",", "(", "value", ",", ")", ",", "lambda", "a", ":", "a", "[", "0", "]", ",", "None", ")" ]
Create an ArgumentType with a single scalar in range(value).
[ "Create", "an", "ArgumentType", "with", "a", "single", "scalar", "in", "range", "(", "value", ")", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/actions.py#L185-L187
train
deepmind/pysc2
pysc2/lib/actions.py
ArgumentType.point
def point(cls): # No range because it's unknown at this time. """Create an ArgumentType that is represented by a point.Point.""" def factory(i, name): return cls(i, name, (0, 0), lambda a: point.Point(*a).floor(), None) return factory
python
def point(cls): # No range because it's unknown at this time. """Create an ArgumentType that is represented by a point.Point.""" def factory(i, name): return cls(i, name, (0, 0), lambda a: point.Point(*a).floor(), None) return factory
[ "def", "point", "(", "cls", ")", ":", "# No range because it's unknown at this time.", "def", "factory", "(", "i", ",", "name", ")", ":", "return", "cls", "(", "i", ",", "name", ",", "(", "0", ",", "0", ")", ",", "lambda", "a", ":", "point", ".", "Po...
Create an ArgumentType that is represented by a point.Point.
[ "Create", "an", "ArgumentType", "that", "is", "represented", "by", "a", "point", ".", "Point", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/actions.py#L190-L194
train
deepmind/pysc2
pysc2/lib/actions.py
Arguments.types
def types(cls, **kwargs): """Create an Arguments of the possible Types.""" named = {name: factory(Arguments._fields.index(name), name) for name, factory in six.iteritems(kwargs)} return cls(**named)
python
def types(cls, **kwargs): """Create an Arguments of the possible Types.""" named = {name: factory(Arguments._fields.index(name), name) for name, factory in six.iteritems(kwargs)} return cls(**named)
[ "def", "types", "(", "cls", ",", "*", "*", "kwargs", ")", ":", "named", "=", "{", "name", ":", "factory", "(", "Arguments", ".", "_fields", ".", "index", "(", "name", ")", ",", "name", ")", "for", "name", ",", "factory", "in", "six", ".", "iterit...
Create an Arguments of the possible Types.
[ "Create", "an", "Arguments", "of", "the", "possible", "Types", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/actions.py#L229-L233
train
deepmind/pysc2
pysc2/lib/actions.py
Function.ui_func
def ui_func(cls, id_, name, function_type, avail_fn=always): """Define a function representing a ui action.""" return cls(id_, name, 0, 0, function_type, FUNCTION_TYPES[function_type], avail_fn)
python
def ui_func(cls, id_, name, function_type, avail_fn=always): """Define a function representing a ui action.""" return cls(id_, name, 0, 0, function_type, FUNCTION_TYPES[function_type], avail_fn)
[ "def", "ui_func", "(", "cls", ",", "id_", ",", "name", ",", "function_type", ",", "avail_fn", "=", "always", ")", ":", "return", "cls", "(", "id_", ",", "name", ",", "0", ",", "0", ",", "function_type", ",", "FUNCTION_TYPES", "[", "function_type", "]",...
Define a function representing a ui action.
[ "Define", "a", "function", "representing", "a", "ui", "action", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/actions.py#L366-L369
train
deepmind/pysc2
pysc2/lib/actions.py
Function.ability
def ability(cls, id_, name, function_type, ability_id, general_id=0): """Define a function represented as a game ability.""" assert function_type in ABILITY_FUNCTIONS return cls(id_, name, ability_id, general_id, function_type, FUNCTION_TYPES[function_type], None)
python
def ability(cls, id_, name, function_type, ability_id, general_id=0): """Define a function represented as a game ability.""" assert function_type in ABILITY_FUNCTIONS return cls(id_, name, ability_id, general_id, function_type, FUNCTION_TYPES[function_type], None)
[ "def", "ability", "(", "cls", ",", "id_", ",", "name", ",", "function_type", ",", "ability_id", ",", "general_id", "=", "0", ")", ":", "assert", "function_type", "in", "ABILITY_FUNCTIONS", "return", "cls", "(", "id_", ",", "name", ",", "ability_id", ",", ...
Define a function represented as a game ability.
[ "Define", "a", "function", "represented", "as", "a", "game", "ability", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/actions.py#L372-L376
train
deepmind/pysc2
pysc2/lib/actions.py
Function.str
def str(self, space=False): """String version. Set space=True to line them all up nicely.""" return "%s/%s (%s)" % (str(int(self.id)).rjust(space and 4), self.name.ljust(space and 50), "; ".join(str(a) for a in self.args))
python
def str(self, space=False): """String version. Set space=True to line them all up nicely.""" return "%s/%s (%s)" % (str(int(self.id)).rjust(space and 4), self.name.ljust(space and 50), "; ".join(str(a) for a in self.args))
[ "def", "str", "(", "self", ",", "space", "=", "False", ")", ":", "return", "\"%s/%s (%s)\"", "%", "(", "str", "(", "int", "(", "self", ".", "id", ")", ")", ".", "rjust", "(", "space", "and", "4", ")", ",", "self", ".", "name", ".", "ljust", "("...
String version. Set space=True to line them all up nicely.
[ "String", "version", ".", "Set", "space", "=", "True", "to", "line", "them", "all", "up", "nicely", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/actions.py#L396-L400
train
deepmind/pysc2
pysc2/lib/actions.py
FunctionCall.init_with_validation
def init_with_validation(cls, function, arguments): """Return a `FunctionCall` given some validation for the function and args. Args: function: A function name or id, to be converted into a function id enum. arguments: An iterable of function arguments. Arguments that are enum types can b...
python
def init_with_validation(cls, function, arguments): """Return a `FunctionCall` given some validation for the function and args. Args: function: A function name or id, to be converted into a function id enum. arguments: An iterable of function arguments. Arguments that are enum types can b...
[ "def", "init_with_validation", "(", "cls", ",", "function", ",", "arguments", ")", ":", "func", "=", "FUNCTIONS", "[", "function", "]", "args", "=", "[", "]", "for", "arg", ",", "arg_type", "in", "zip", "(", "arguments", ",", "func", ".", "args", ")", ...
Return a `FunctionCall` given some validation for the function and args. Args: function: A function name or id, to be converted into a function id enum. arguments: An iterable of function arguments. Arguments that are enum types can be passed by name. Arguments that only take one value (ie ...
[ "Return", "a", "FunctionCall", "given", "some", "validation", "for", "the", "function", "and", "args", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/actions.py#L1039-L1077
train
deepmind/pysc2
pysc2/lib/actions.py
FunctionCall.all_arguments
def all_arguments(cls, function, arguments): """Helper function for creating `FunctionCall`s with `Arguments`. Args: function: The value to store for the action function. arguments: The values to store for the arguments of the action. Can either be an `Arguments` object, a `dict`, or an ite...
python
def all_arguments(cls, function, arguments): """Helper function for creating `FunctionCall`s with `Arguments`. Args: function: The value to store for the action function. arguments: The values to store for the arguments of the action. Can either be an `Arguments` object, a `dict`, or an ite...
[ "def", "all_arguments", "(", "cls", ",", "function", ",", "arguments", ")", ":", "if", "isinstance", "(", "arguments", ",", "dict", ")", ":", "arguments", "=", "Arguments", "(", "*", "*", "arguments", ")", "elif", "not", "isinstance", "(", "arguments", "...
Helper function for creating `FunctionCall`s with `Arguments`. Args: function: The value to store for the action function. arguments: The values to store for the arguments of the action. Can either be an `Arguments` object, a `dict`, or an iterable. If a `dict` or an iterable is provide...
[ "Helper", "function", "for", "creating", "FunctionCall", "s", "with", "Arguments", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/actions.py#L1080-L1097
train
deepmind/pysc2
pysc2/bin/valid_actions.py
main
def main(unused_argv): """Print the valid actions.""" feats = features.Features( # Actually irrelevant whether it's feature or rgb size. features.AgentInterfaceFormat( feature_dimensions=features.Dimensions( screen=FLAGS.screen_size, minimap=FLAGS.minimap_size))) ...
python
def main(unused_argv): """Print the valid actions.""" feats = features.Features( # Actually irrelevant whether it's feature or rgb size. features.AgentInterfaceFormat( feature_dimensions=features.Dimensions( screen=FLAGS.screen_size, minimap=FLAGS.minimap_size))) ...
[ "def", "main", "(", "unused_argv", ")", ":", "feats", "=", "features", ".", "Features", "(", "# Actually irrelevant whether it's feature or rgb size.", "features", ".", "AgentInterfaceFormat", "(", "feature_dimensions", "=", "features", ".", "Dimensions", "(", "screen",...
Print the valid actions.
[ "Print", "the", "valid", "actions", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/bin/valid_actions.py#L34-L56
train
deepmind/pysc2
pysc2/lib/portspicker.py
pick_unused_ports
def pick_unused_ports(num_ports, retry_interval_secs=3, retry_attempts=5): """Reserves and returns a list of `num_ports` unused ports.""" ports = set() for _ in range(retry_attempts): ports.update( portpicker.pick_unused_port() for _ in range(num_ports - len(ports))) ports.discard(None) # portpic...
python
def pick_unused_ports(num_ports, retry_interval_secs=3, retry_attempts=5): """Reserves and returns a list of `num_ports` unused ports.""" ports = set() for _ in range(retry_attempts): ports.update( portpicker.pick_unused_port() for _ in range(num_ports - len(ports))) ports.discard(None) # portpic...
[ "def", "pick_unused_ports", "(", "num_ports", ",", "retry_interval_secs", "=", "3", ",", "retry_attempts", "=", "5", ")", ":", "ports", "=", "set", "(", ")", "for", "_", "in", "range", "(", "retry_attempts", ")", ":", "ports", ".", "update", "(", "portpi...
Reserves and returns a list of `num_ports` unused ports.
[ "Reserves", "and", "returns", "a", "list", "of", "num_ports", "unused", "ports", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/portspicker.py#L24-L40
train
deepmind/pysc2
pysc2/lib/portspicker.py
pick_contiguous_unused_ports
def pick_contiguous_unused_ports( num_ports, retry_interval_secs=3, retry_attempts=5): """Reserves and returns a list of `num_ports` contiguous unused ports.""" for _ in range(retry_attempts): start_port = portpicker.pick_unused_port() if start_port is not None: ports = [start_port + p for...
python
def pick_contiguous_unused_ports( num_ports, retry_interval_secs=3, retry_attempts=5): """Reserves and returns a list of `num_ports` contiguous unused ports.""" for _ in range(retry_attempts): start_port = portpicker.pick_unused_port() if start_port is not None: ports = [start_port + p for...
[ "def", "pick_contiguous_unused_ports", "(", "num_ports", ",", "retry_interval_secs", "=", "3", ",", "retry_attempts", "=", "5", ")", ":", "for", "_", "in", "range", "(", "retry_attempts", ")", ":", "start_port", "=", "portpicker", ".", "pick_unused_port", "(", ...
Reserves and returns a list of `num_ports` contiguous unused ports.
[ "Reserves", "and", "returns", "a", "list", "of", "num_ports", "contiguous", "unused", "ports", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/portspicker.py#L43-L59
train
deepmind/pysc2
pysc2/bin/agent.py
run_thread
def run_thread(agent_classes, players, map_name, visualize): """Run one thread worth of the environment with agents.""" with sc2_env.SC2Env( map_name=map_name, players=players, agent_interface_format=sc2_env.parse_agent_interface_format( feature_screen=FLAGS.feature_screen_size, ...
python
def run_thread(agent_classes, players, map_name, visualize): """Run one thread worth of the environment with agents.""" with sc2_env.SC2Env( map_name=map_name, players=players, agent_interface_format=sc2_env.parse_agent_interface_format( feature_screen=FLAGS.feature_screen_size, ...
[ "def", "run_thread", "(", "agent_classes", ",", "players", ",", "map_name", ",", "visualize", ")", ":", "with", "sc2_env", ".", "SC2Env", "(", "map_name", "=", "map_name", ",", "players", "=", "players", ",", "agent_interface_format", "=", "sc2_env", ".", "p...
Run one thread worth of the environment with agents.
[ "Run", "one", "thread", "worth", "of", "the", "environment", "with", "agents", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/bin/agent.py#L83-L103
train
deepmind/pysc2
pysc2/bin/agent.py
main
def main(unused_argv): """Run an agent.""" stopwatch.sw.enabled = FLAGS.profile or FLAGS.trace stopwatch.sw.trace = FLAGS.trace map_inst = maps.get(FLAGS.map) agent_classes = [] players = [] agent_module, agent_name = FLAGS.agent.rsplit(".", 1) agent_cls = getattr(importlib.import_module(agent_module...
python
def main(unused_argv): """Run an agent.""" stopwatch.sw.enabled = FLAGS.profile or FLAGS.trace stopwatch.sw.trace = FLAGS.trace map_inst = maps.get(FLAGS.map) agent_classes = [] players = [] agent_module, agent_name = FLAGS.agent.rsplit(".", 1) agent_cls = getattr(importlib.import_module(agent_module...
[ "def", "main", "(", "unused_argv", ")", ":", "stopwatch", ".", "sw", ".", "enabled", "=", "FLAGS", ".", "profile", "or", "FLAGS", ".", "trace", "stopwatch", ".", "sw", ".", "trace", "=", "FLAGS", ".", "trace", "map_inst", "=", "maps", ".", "get", "("...
Run an agent.
[ "Run", "an", "agent", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/bin/agent.py#L106-L146
train
deepmind/pysc2
pysc2/lib/remote_controller.py
check_error
def check_error(res, error_enum): """Raise if the result has an error, otherwise return the result.""" if res.HasField("error"): enum_name = error_enum.DESCRIPTOR.full_name error_name = error_enum.Name(res.error) details = getattr(res, "error_details", "<none>") raise RequestError("%s.%s: '%s'" % (e...
python
def check_error(res, error_enum): """Raise if the result has an error, otherwise return the result.""" if res.HasField("error"): enum_name = error_enum.DESCRIPTOR.full_name error_name = error_enum.Name(res.error) details = getattr(res, "error_details", "<none>") raise RequestError("%s.%s: '%s'" % (e...
[ "def", "check_error", "(", "res", ",", "error_enum", ")", ":", "if", "res", ".", "HasField", "(", "\"error\"", ")", ":", "enum_name", "=", "error_enum", ".", "DESCRIPTOR", ".", "full_name", "error_name", "=", "error_enum", ".", "Name", "(", "res", ".", "...
Raise if the result has an error, otherwise return the result.
[ "Raise", "if", "the", "result", "has", "an", "error", "otherwise", "return", "the", "result", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/remote_controller.py#L56-L63
train
deepmind/pysc2
pysc2/lib/remote_controller.py
decorate_check_error
def decorate_check_error(error_enum): """Decorator to call `check_error` on the return value.""" def decorator(func): @functools.wraps(func) def _check_error(*args, **kwargs): return check_error(func(*args, **kwargs), error_enum) return _check_error return decorator
python
def decorate_check_error(error_enum): """Decorator to call `check_error` on the return value.""" def decorator(func): @functools.wraps(func) def _check_error(*args, **kwargs): return check_error(func(*args, **kwargs), error_enum) return _check_error return decorator
[ "def", "decorate_check_error", "(", "error_enum", ")", ":", "def", "decorator", "(", "func", ")", ":", "@", "functools", ".", "wraps", "(", "func", ")", "def", "_check_error", "(", "*", "args", ",", "*", "*", "kwargs", ")", ":", "return", "check_error", ...
Decorator to call `check_error` on the return value.
[ "Decorator", "to", "call", "check_error", "on", "the", "return", "value", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/remote_controller.py#L66-L73
train
deepmind/pysc2
pysc2/lib/remote_controller.py
skip_status
def skip_status(*skipped): """Decorator to skip this call if we're in one of the skipped states.""" def decorator(func): @functools.wraps(func) def _skip_status(self, *args, **kwargs): if self.status not in skipped: return func(self, *args, **kwargs) return _skip_status return decorator
python
def skip_status(*skipped): """Decorator to skip this call if we're in one of the skipped states.""" def decorator(func): @functools.wraps(func) def _skip_status(self, *args, **kwargs): if self.status not in skipped: return func(self, *args, **kwargs) return _skip_status return decorator
[ "def", "skip_status", "(", "*", "skipped", ")", ":", "def", "decorator", "(", "func", ")", ":", "@", "functools", ".", "wraps", "(", "func", ")", "def", "_skip_status", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "if", "self",...
Decorator to skip this call if we're in one of the skipped states.
[ "Decorator", "to", "skip", "this", "call", "if", "we", "re", "in", "one", "of", "the", "skipped", "states", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/remote_controller.py#L76-L84
train
deepmind/pysc2
pysc2/lib/remote_controller.py
valid_status
def valid_status(*valid): """Decorator to assert that we're in a valid state.""" def decorator(func): @functools.wraps(func) def _valid_status(self, *args, **kwargs): if self.status not in valid: raise protocol.ProtocolError( "`%s` called while in state: %s, valid: (%s)" % ( ...
python
def valid_status(*valid): """Decorator to assert that we're in a valid state.""" def decorator(func): @functools.wraps(func) def _valid_status(self, *args, **kwargs): if self.status not in valid: raise protocol.ProtocolError( "`%s` called while in state: %s, valid: (%s)" % ( ...
[ "def", "valid_status", "(", "*", "valid", ")", ":", "def", "decorator", "(", "func", ")", ":", "@", "functools", ".", "wraps", "(", "func", ")", "def", "_valid_status", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "if", "self",...
Decorator to assert that we're in a valid state.
[ "Decorator", "to", "assert", "that", "we", "re", "in", "a", "valid", "state", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/remote_controller.py#L87-L98
train
deepmind/pysc2
pysc2/lib/remote_controller.py
catch_game_end
def catch_game_end(func): """Decorator to handle 'Game has already ended' exceptions.""" @functools.wraps(func) def _catch_game_end(self, *args, **kwargs): """Decorator to handle 'Game has already ended' exceptions.""" prev_status = self.status try: return func(self, *args, **kwargs) except ...
python
def catch_game_end(func): """Decorator to handle 'Game has already ended' exceptions.""" @functools.wraps(func) def _catch_game_end(self, *args, **kwargs): """Decorator to handle 'Game has already ended' exceptions.""" prev_status = self.status try: return func(self, *args, **kwargs) except ...
[ "def", "catch_game_end", "(", "func", ")", ":", "@", "functools", ".", "wraps", "(", "func", ")", "def", "_catch_game_end", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "\"\"\"Decorator to handle 'Game has already ended' exceptions.\"\"\"", ...
Decorator to handle 'Game has already ended' exceptions.
[ "Decorator", "to", "handle", "Game", "has", "already", "ended", "exceptions", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/remote_controller.py#L101-L126
train
deepmind/pysc2
pysc2/lib/remote_controller.py
RemoteController._connect
def _connect(self, host, port, proc, timeout_seconds): """Connect to the websocket, retrying as needed. Returns the socket.""" if ":" in host and not host.startswith("["): # Support ipv6 addresses. host = "[%s]" % host url = "ws://%s:%s/sc2api" % (host, port) was_running = False for i in ran...
python
def _connect(self, host, port, proc, timeout_seconds): """Connect to the websocket, retrying as needed. Returns the socket.""" if ":" in host and not host.startswith("["): # Support ipv6 addresses. host = "[%s]" % host url = "ws://%s:%s/sc2api" % (host, port) was_running = False for i in ran...
[ "def", "_connect", "(", "self", ",", "host", ",", "port", ",", "proc", ",", "timeout_seconds", ")", ":", "if", "\":\"", "in", "host", "and", "not", "host", ".", "startswith", "(", "\"[\"", ")", ":", "# Support ipv6 addresses.", "host", "=", "\"[%s]\"", "...
Connect to the websocket, retrying as needed. Returns the socket.
[ "Connect", "to", "the", "websocket", "retrying", "as", "needed", ".", "Returns", "the", "socket", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/remote_controller.py#L148-L174
train
deepmind/pysc2
pysc2/lib/remote_controller.py
RemoteController.save_map
def save_map(self, map_path, map_data): """Save a map into temp dir so create game can access it in multiplayer.""" return self._client.send(save_map=sc_pb.RequestSaveMap( map_path=map_path, map_data=map_data))
python
def save_map(self, map_path, map_data): """Save a map into temp dir so create game can access it in multiplayer.""" return self._client.send(save_map=sc_pb.RequestSaveMap( map_path=map_path, map_data=map_data))
[ "def", "save_map", "(", "self", ",", "map_path", ",", "map_data", ")", ":", "return", "self", ".", "_client", ".", "send", "(", "save_map", "=", "sc_pb", ".", "RequestSaveMap", "(", "map_path", "=", "map_path", ",", "map_data", "=", "map_data", ")", ")" ...
Save a map into temp dir so create game can access it in multiplayer.
[ "Save", "a", "map", "into", "temp", "dir", "so", "create", "game", "can", "access", "it", "in", "multiplayer", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/remote_controller.py#L189-L192
train
deepmind/pysc2
pysc2/lib/remote_controller.py
RemoteController.data_raw
def data_raw(self): """Get the raw static data for the current game. Prefer `data` instead.""" return self._client.send(data=sc_pb.RequestData( ability_id=True, unit_type_id=True))
python
def data_raw(self): """Get the raw static data for the current game. Prefer `data` instead.""" return self._client.send(data=sc_pb.RequestData( ability_id=True, unit_type_id=True))
[ "def", "data_raw", "(", "self", ")", ":", "return", "self", ".", "_client", ".", "send", "(", "data", "=", "sc_pb", ".", "RequestData", "(", "ability_id", "=", "True", ",", "unit_type_id", "=", "True", ")", ")" ]
Get the raw static data for the current game. Prefer `data` instead.
[ "Get", "the", "raw", "static", "data", "for", "the", "current", "game", ".", "Prefer", "data", "instead", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/remote_controller.py#L223-L226
train
deepmind/pysc2
pysc2/lib/remote_controller.py
RemoteController.step
def step(self, count=1): """Step the engine forward by one (or more) step.""" return self._client.send(step=sc_pb.RequestStep(count=count))
python
def step(self, count=1): """Step the engine forward by one (or more) step.""" return self._client.send(step=sc_pb.RequestStep(count=count))
[ "def", "step", "(", "self", ",", "count", "=", "1", ")", ":", "return", "self", ".", "_client", ".", "send", "(", "step", "=", "sc_pb", ".", "RequestStep", "(", "count", "=", "count", ")", ")" ]
Step the engine forward by one (or more) step.
[ "Step", "the", "engine", "forward", "by", "one", "(", "or", "more", ")", "step", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/remote_controller.py#L240-L242
train
deepmind/pysc2
pysc2/lib/remote_controller.py
RemoteController.actions
def actions(self, req_action): """Send a `sc_pb.RequestAction`, which may include multiple actions.""" if FLAGS.sc2_log_actions: for action in req_action.actions: sys.stderr.write(str(action)) sys.stderr.flush() return self._client.send(action=req_action)
python
def actions(self, req_action): """Send a `sc_pb.RequestAction`, which may include multiple actions.""" if FLAGS.sc2_log_actions: for action in req_action.actions: sys.stderr.write(str(action)) sys.stderr.flush() return self._client.send(action=req_action)
[ "def", "actions", "(", "self", ",", "req_action", ")", ":", "if", "FLAGS", ".", "sc2_log_actions", ":", "for", "action", "in", "req_action", ".", "actions", ":", "sys", ".", "stderr", ".", "write", "(", "str", "(", "action", ")", ")", "sys", ".", "st...
Send a `sc_pb.RequestAction`, which may include multiple actions.
[ "Send", "a", "sc_pb", ".", "RequestAction", "which", "may", "include", "multiple", "actions", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/remote_controller.py#L248-L255
train
deepmind/pysc2
pysc2/lib/remote_controller.py
RemoteController.act
def act(self, action): """Send a single action. This is a shortcut for `actions`.""" if action and action.ListFields(): # Skip no-ops. return self.actions(sc_pb.RequestAction(actions=[action]))
python
def act(self, action): """Send a single action. This is a shortcut for `actions`.""" if action and action.ListFields(): # Skip no-ops. return self.actions(sc_pb.RequestAction(actions=[action]))
[ "def", "act", "(", "self", ",", "action", ")", ":", "if", "action", "and", "action", ".", "ListFields", "(", ")", ":", "# Skip no-ops.", "return", "self", ".", "actions", "(", "sc_pb", ".", "RequestAction", "(", "actions", "=", "[", "action", "]", ")",...
Send a single action. This is a shortcut for `actions`.
[ "Send", "a", "single", "action", ".", "This", "is", "a", "shortcut", "for", "actions", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/remote_controller.py#L257-L260
train
deepmind/pysc2
pysc2/lib/remote_controller.py
RemoteController.chat
def chat(self, message): """Send chat message as a broadcast.""" if message: action_chat = sc_pb.ActionChat( channel=sc_pb.ActionChat.Broadcast, message=message) action = sc_pb.Action(action_chat=action_chat) return self.act(action)
python
def chat(self, message): """Send chat message as a broadcast.""" if message: action_chat = sc_pb.ActionChat( channel=sc_pb.ActionChat.Broadcast, message=message) action = sc_pb.Action(action_chat=action_chat) return self.act(action)
[ "def", "chat", "(", "self", ",", "message", ")", ":", "if", "message", ":", "action_chat", "=", "sc_pb", ".", "ActionChat", "(", "channel", "=", "sc_pb", ".", "ActionChat", ".", "Broadcast", ",", "message", "=", "message", ")", "action", "=", "sc_pb", ...
Send chat message as a broadcast.
[ "Send", "chat", "message", "as", "a", "broadcast", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/remote_controller.py#L262-L268
train
deepmind/pysc2
pysc2/lib/remote_controller.py
RemoteController.save_replay
def save_replay(self): """Save a replay, returning the data.""" res = self._client.send(save_replay=sc_pb.RequestSaveReplay()) return res.data
python
def save_replay(self): """Save a replay, returning the data.""" res = self._client.send(save_replay=sc_pb.RequestSaveReplay()) return res.data
[ "def", "save_replay", "(", "self", ")", ":", "res", "=", "self", ".", "_client", ".", "send", "(", "save_replay", "=", "sc_pb", ".", "RequestSaveReplay", "(", ")", ")", "return", "res", ".", "data" ]
Save a replay, returning the data.
[ "Save", "a", "replay", "returning", "the", "data", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/remote_controller.py#L278-L281
train
deepmind/pysc2
pysc2/lib/remote_controller.py
RemoteController.debug
def debug(self, debug_commands): """Run a debug command.""" if isinstance(debug_commands, sc_debug.DebugCommand): debug_commands = [debug_commands] return self._client.send(debug=sc_pb.RequestDebug(debug=debug_commands))
python
def debug(self, debug_commands): """Run a debug command.""" if isinstance(debug_commands, sc_debug.DebugCommand): debug_commands = [debug_commands] return self._client.send(debug=sc_pb.RequestDebug(debug=debug_commands))
[ "def", "debug", "(", "self", ",", "debug_commands", ")", ":", "if", "isinstance", "(", "debug_commands", ",", "sc_debug", ".", "DebugCommand", ")", ":", "debug_commands", "=", "[", "debug_commands", "]", "return", "self", ".", "_client", ".", "send", "(", ...
Run a debug command.
[ "Run", "a", "debug", "command", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/remote_controller.py#L285-L289
train
deepmind/pysc2
pysc2/lib/remote_controller.py
RemoteController.quit
def quit(self): """Shut down the SC2 process.""" try: # Don't expect a response. self._client.write(sc_pb.Request(quit=sc_pb.RequestQuit())) except protocol.ConnectionError: pass # It's likely already (shutting) down, so continue as if it worked. finally: self.close()
python
def quit(self): """Shut down the SC2 process.""" try: # Don't expect a response. self._client.write(sc_pb.Request(quit=sc_pb.RequestQuit())) except protocol.ConnectionError: pass # It's likely already (shutting) down, so continue as if it worked. finally: self.close()
[ "def", "quit", "(", "self", ")", ":", "try", ":", "# Don't expect a response.", "self", ".", "_client", ".", "write", "(", "sc_pb", ".", "Request", "(", "quit", "=", "sc_pb", ".", "RequestQuit", "(", ")", ")", ")", "except", "protocol", ".", "ConnectionE...
Shut down the SC2 process.
[ "Shut", "down", "the", "SC2", "process", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/remote_controller.py#L293-L301
train
deepmind/pysc2
pysc2/env/run_loop.py
run_loop
def run_loop(agents, env, max_frames=0, max_episodes=0): """A run loop to have agents and an environment interact.""" total_frames = 0 total_episodes = 0 start_time = time.time() observation_spec = env.observation_spec() action_spec = env.action_spec() for agent, obs_spec, act_spec in zip(agents, observa...
python
def run_loop(agents, env, max_frames=0, max_episodes=0): """A run loop to have agents and an environment interact.""" total_frames = 0 total_episodes = 0 start_time = time.time() observation_spec = env.observation_spec() action_spec = env.action_spec() for agent, obs_spec, act_spec in zip(agents, observa...
[ "def", "run_loop", "(", "agents", ",", "env", ",", "max_frames", "=", "0", ",", "max_episodes", "=", "0", ")", ":", "total_frames", "=", "0", "total_episodes", "=", "0", "start_time", "=", "time", ".", "time", "(", ")", "observation_spec", "=", "env", ...
A run loop to have agents and an environment interact.
[ "A", "run", "loop", "to", "have", "agents", "and", "an", "environment", "interact", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/env/run_loop.py#L23-L54
train
deepmind/pysc2
pysc2/run_configs/lib.py
RunConfig.map_data
def map_data(self, map_name): """Return the map data for a map by name or path.""" with gfile.Open(os.path.join(self.data_dir, "Maps", map_name), "rb") as f: return f.read()
python
def map_data(self, map_name): """Return the map data for a map by name or path.""" with gfile.Open(os.path.join(self.data_dir, "Maps", map_name), "rb") as f: return f.read()
[ "def", "map_data", "(", "self", ",", "map_name", ")", ":", "with", "gfile", ".", "Open", "(", "os", ".", "path", ".", "join", "(", "self", ".", "data_dir", ",", "\"Maps\"", ",", "map_name", ")", ",", "\"rb\"", ")", "as", "f", ":", "return", "f", ...
Return the map data for a map by name or path.
[ "Return", "the", "map", "data", "for", "a", "map", "by", "name", "or", "path", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/run_configs/lib.py#L101-L104
train
deepmind/pysc2
pysc2/run_configs/lib.py
RunConfig.replay_data
def replay_data(self, replay_path): """Return the replay data given a path to the replay.""" with gfile.Open(self.abs_replay_path(replay_path), "rb") as f: return f.read()
python
def replay_data(self, replay_path): """Return the replay data given a path to the replay.""" with gfile.Open(self.abs_replay_path(replay_path), "rb") as f: return f.read()
[ "def", "replay_data", "(", "self", ",", "replay_path", ")", ":", "with", "gfile", ".", "Open", "(", "self", ".", "abs_replay_path", "(", "replay_path", ")", ",", "\"rb\"", ")", "as", "f", ":", "return", "f", ".", "read", "(", ")" ]
Return the replay data given a path to the replay.
[ "Return", "the", "replay", "data", "given", "a", "path", "to", "the", "replay", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/run_configs/lib.py#L110-L113
train
deepmind/pysc2
pysc2/run_configs/lib.py
RunConfig.replay_paths
def replay_paths(self, replay_dir): """A generator yielding the full path to the replays under `replay_dir`.""" replay_dir = self.abs_replay_path(replay_dir) if replay_dir.lower().endswith(".sc2replay"): yield replay_dir return for f in gfile.ListDir(replay_dir): if f.lower().endswith(...
python
def replay_paths(self, replay_dir): """A generator yielding the full path to the replays under `replay_dir`.""" replay_dir = self.abs_replay_path(replay_dir) if replay_dir.lower().endswith(".sc2replay"): yield replay_dir return for f in gfile.ListDir(replay_dir): if f.lower().endswith(...
[ "def", "replay_paths", "(", "self", ",", "replay_dir", ")", ":", "replay_dir", "=", "self", ".", "abs_replay_path", "(", "replay_dir", ")", "if", "replay_dir", ".", "lower", "(", ")", ".", "endswith", "(", "\".sc2replay\"", ")", ":", "yield", "replay_dir", ...
A generator yielding the full path to the replays under `replay_dir`.
[ "A", "generator", "yielding", "the", "full", "path", "to", "the", "replays", "under", "replay_dir", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/run_configs/lib.py#L115-L123
train
deepmind/pysc2
pysc2/run_configs/lib.py
RunConfig.save_replay
def save_replay(self, replay_data, replay_dir, prefix=None): """Save a replay to a directory, returning the path to the replay. Args: replay_data: The result of controller.save_replay(), ie the binary data. replay_dir: Where to save the replay. This can be absolute or relative. prefix: Option...
python
def save_replay(self, replay_data, replay_dir, prefix=None): """Save a replay to a directory, returning the path to the replay. Args: replay_data: The result of controller.save_replay(), ie the binary data. replay_dir: Where to save the replay. This can be absolute or relative. prefix: Option...
[ "def", "save_replay", "(", "self", ",", "replay_data", ",", "replay_dir", ",", "prefix", "=", "None", ")", ":", "if", "not", "prefix", ":", "replay_filename", "=", "\"\"", "elif", "os", ".", "path", ".", "sep", "in", "prefix", ":", "raise", "ValueError",...
Save a replay to a directory, returning the path to the replay. Args: replay_data: The result of controller.save_replay(), ie the binary data. replay_dir: Where to save the replay. This can be absolute or relative. prefix: Optional prefix for the replay filename. Returns: The full path...
[ "Save", "a", "replay", "to", "a", "directory", "returning", "the", "path", "to", "the", "replay", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/run_configs/lib.py#L125-L154
train
deepmind/pysc2
pysc2/run_configs/lib.py
RunConfig.all_subclasses
def all_subclasses(cls): """An iterator over all subclasses of `cls`.""" for s in cls.__subclasses__(): yield s for c in s.all_subclasses(): yield c
python
def all_subclasses(cls): """An iterator over all subclasses of `cls`.""" for s in cls.__subclasses__(): yield s for c in s.all_subclasses(): yield c
[ "def", "all_subclasses", "(", "cls", ")", ":", "for", "s", "in", "cls", ".", "__subclasses__", "(", ")", ":", "yield", "s", "for", "c", "in", "s", ".", "all_subclasses", "(", ")", ":", "yield", "c" ]
An iterator over all subclasses of `cls`.
[ "An", "iterator", "over", "all", "subclasses", "of", "cls", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/run_configs/lib.py#L161-L166
train
deepmind/pysc2
pysc2/lib/named_array.py
NamedNumpyArray._indices
def _indices(self, indices): """Turn all string indices into int indices, preserving ellipsis.""" if isinstance(indices, tuple): out = [] dim = 0 for i, index in enumerate(indices): if index is Ellipsis: out.append(index) dim = len(self.shape) - len(indices) + i ...
python
def _indices(self, indices): """Turn all string indices into int indices, preserving ellipsis.""" if isinstance(indices, tuple): out = [] dim = 0 for i, index in enumerate(indices): if index is Ellipsis: out.append(index) dim = len(self.shape) - len(indices) + i ...
[ "def", "_indices", "(", "self", ",", "indices", ")", ":", "if", "isinstance", "(", "indices", ",", "tuple", ")", ":", "out", "=", "[", "]", "dim", "=", "0", "for", "i", ",", "index", "in", "enumerate", "(", "indices", ")", ":", "if", "index", "is...
Turn all string indices into int indices, preserving ellipsis.
[ "Turn", "all", "string", "indices", "into", "int", "indices", "preserving", "ellipsis", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/named_array.py#L231-L245
train
deepmind/pysc2
pysc2/lib/named_array.py
NamedNumpyArray._get_index
def _get_index(self, dim, index): """Turn a string into a real index, otherwise return the index.""" if isinstance(index, six.string_types): try: return self._index_names[dim][index] except KeyError: raise KeyError("Name '%s' is invalid for axis %s." % (index, dim)) except Type...
python
def _get_index(self, dim, index): """Turn a string into a real index, otherwise return the index.""" if isinstance(index, six.string_types): try: return self._index_names[dim][index] except KeyError: raise KeyError("Name '%s' is invalid for axis %s." % (index, dim)) except Type...
[ "def", "_get_index", "(", "self", ",", "dim", ",", "index", ")", ":", "if", "isinstance", "(", "index", ",", "six", ".", "string_types", ")", ":", "try", ":", "return", "self", ".", "_index_names", "[", "dim", "]", "[", "index", "]", "except", "KeyEr...
Turn a string into a real index, otherwise return the index.
[ "Turn", "a", "string", "into", "a", "real", "index", "otherwise", "return", "the", "index", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/named_array.py#L247-L258
train
deepmind/pysc2
pysc2/lib/point.py
Point.assign_to
def assign_to(self, obj): """Assign `x` and `y` to an object that has properties `x` and `y`.""" obj.x = self.x obj.y = self.y
python
def assign_to(self, obj): """Assign `x` and `y` to an object that has properties `x` and `y`.""" obj.x = self.x obj.y = self.y
[ "def", "assign_to", "(", "self", ",", "obj", ")", ":", "obj", ".", "x", "=", "self", ".", "x", "obj", ".", "y", "=", "self", ".", "y" ]
Assign `x` and `y` to an object that has properties `x` and `y`.
[ "Assign", "x", "and", "y", "to", "an", "object", "that", "has", "properties", "x", "and", "y", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/point.py#L39-L42
train
deepmind/pysc2
pysc2/lib/point.py
Point.dist
def dist(self, other): """Distance to some other point.""" dx = self.x - other.x dy = self.y - other.y return math.sqrt(dx**2 + dy**2)
python
def dist(self, other): """Distance to some other point.""" dx = self.x - other.x dy = self.y - other.y return math.sqrt(dx**2 + dy**2)
[ "def", "dist", "(", "self", ",", "other", ")", ":", "dx", "=", "self", ".", "x", "-", "other", ".", "x", "dy", "=", "self", ".", "y", "-", "other", ".", "y", "return", "math", ".", "sqrt", "(", "dx", "**", "2", "+", "dy", "**", "2", ")" ]
Distance to some other point.
[ "Distance", "to", "some", "other", "point", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/point.py#L44-L48
train
deepmind/pysc2
pysc2/lib/point.py
Point.dist_sq
def dist_sq(self, other): """Distance squared to some other point.""" dx = self.x - other.x dy = self.y - other.y return dx**2 + dy**2
python
def dist_sq(self, other): """Distance squared to some other point.""" dx = self.x - other.x dy = self.y - other.y return dx**2 + dy**2
[ "def", "dist_sq", "(", "self", ",", "other", ")", ":", "dx", "=", "self", ".", "x", "-", "other", ".", "x", "dy", "=", "self", ".", "y", "-", "other", ".", "y", "return", "dx", "**", "2", "+", "dy", "**", "2" ]
Distance squared to some other point.
[ "Distance", "squared", "to", "some", "other", "point", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/point.py#L50-L54
train
deepmind/pysc2
pysc2/lib/point.py
Point.round
def round(self): """Round `x` and `y` to integers.""" return Point(int(round(self.x)), int(round(self.y)))
python
def round(self): """Round `x` and `y` to integers.""" return Point(int(round(self.x)), int(round(self.y)))
[ "def", "round", "(", "self", ")", ":", "return", "Point", "(", "int", "(", "round", "(", "self", ".", "x", ")", ")", ",", "int", "(", "round", "(", "self", ".", "y", ")", ")", ")" ]
Round `x` and `y` to integers.
[ "Round", "x", "and", "y", "to", "integers", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/point.py#L56-L58
train
deepmind/pysc2
pysc2/lib/point.py
Point.floor
def floor(self): """Round `x` and `y` down to integers.""" return Point(int(math.floor(self.x)), int(math.floor(self.y)))
python
def floor(self): """Round `x` and `y` down to integers.""" return Point(int(math.floor(self.x)), int(math.floor(self.y)))
[ "def", "floor", "(", "self", ")", ":", "return", "Point", "(", "int", "(", "math", ".", "floor", "(", "self", ".", "x", ")", ")", ",", "int", "(", "math", ".", "floor", "(", "self", ".", "y", ")", ")", ")" ]
Round `x` and `y` down to integers.
[ "Round", "x", "and", "y", "down", "to", "integers", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/point.py#L60-L62
train
deepmind/pysc2
pysc2/lib/point.py
Point.ceil
def ceil(self): """Round `x` and `y` up to integers.""" return Point(int(math.ceil(self.x)), int(math.ceil(self.y)))
python
def ceil(self): """Round `x` and `y` up to integers.""" return Point(int(math.ceil(self.x)), int(math.ceil(self.y)))
[ "def", "ceil", "(", "self", ")", ":", "return", "Point", "(", "int", "(", "math", ".", "ceil", "(", "self", ".", "x", ")", ")", ",", "int", "(", "math", ".", "ceil", "(", "self", ".", "y", ")", ")", ")" ]
Round `x` and `y` up to integers.
[ "Round", "x", "and", "y", "up", "to", "integers", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/point.py#L64-L66
train
deepmind/pysc2
pysc2/lib/point.py
Point.bound
def bound(self, p1, p2=None): """Bound this point within the rect defined by (`p1`, `p2`).""" r = Rect(p1, p2) return Point(min(max(self.x, r.l), r.r), min(max(self.y, r.t), r.b))
python
def bound(self, p1, p2=None): """Bound this point within the rect defined by (`p1`, `p2`).""" r = Rect(p1, p2) return Point(min(max(self.x, r.l), r.r), min(max(self.y, r.t), r.b))
[ "def", "bound", "(", "self", ",", "p1", ",", "p2", "=", "None", ")", ":", "r", "=", "Rect", "(", "p1", ",", "p2", ")", "return", "Point", "(", "min", "(", "max", "(", "self", ".", "x", ",", "r", ".", "l", ")", ",", "r", ".", "r", ")", "...
Bound this point within the rect defined by (`p1`, `p2`).
[ "Bound", "this", "point", "within", "the", "rect", "defined", "by", "(", "p1", "p2", ")", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/point.py#L112-L115
train
deepmind/pysc2
pysc2/lib/point.py
Rect.contains_point
def contains_point(self, pt): """Is the point inside this rect?""" return (self.l < pt.x and self.r > pt.x and self.t < pt.y and self.b > pt.y)
python
def contains_point(self, pt): """Is the point inside this rect?""" return (self.l < pt.x and self.r > pt.x and self.t < pt.y and self.b > pt.y)
[ "def", "contains_point", "(", "self", ",", "pt", ")", ":", "return", "(", "self", ".", "l", "<", "pt", ".", "x", "and", "self", ".", "r", ">", "pt", ".", "x", "and", "self", ".", "t", "<", "pt", ".", "y", "and", "self", ".", "b", ">", "pt",...
Is the point inside this rect?
[ "Is", "the", "point", "inside", "this", "rect?" ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/point.py#L239-L242
train
deepmind/pysc2
pysc2/lib/point.py
Rect.contains_circle
def contains_circle(self, pt, radius): """Is the circle completely inside this rect?""" return (self.l < pt.x - radius and self.r > pt.x + radius and self.t < pt.y - radius and self.b > pt.y + radius)
python
def contains_circle(self, pt, radius): """Is the circle completely inside this rect?""" return (self.l < pt.x - radius and self.r > pt.x + radius and self.t < pt.y - radius and self.b > pt.y + radius)
[ "def", "contains_circle", "(", "self", ",", "pt", ",", "radius", ")", ":", "return", "(", "self", ".", "l", "<", "pt", ".", "x", "-", "radius", "and", "self", ".", "r", ">", "pt", ".", "x", "+", "radius", "and", "self", ".", "t", "<", "pt", "...
Is the circle completely inside this rect?
[ "Is", "the", "circle", "completely", "inside", "this", "rect?" ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/point.py#L244-L247
train
deepmind/pysc2
pysc2/lib/point.py
Rect.intersects_circle
def intersects_circle(self, pt, radius): """Does the circle intersect with this rect?""" # How this works: http://stackoverflow.com/a/402010 rect_corner = self.size / 2 # relative to the rect center circle_center = (pt - self.center).abs() # relative to the rect center # Is the circle far from th...
python
def intersects_circle(self, pt, radius): """Does the circle intersect with this rect?""" # How this works: http://stackoverflow.com/a/402010 rect_corner = self.size / 2 # relative to the rect center circle_center = (pt - self.center).abs() # relative to the rect center # Is the circle far from th...
[ "def", "intersects_circle", "(", "self", ",", "pt", ",", "radius", ")", ":", "# How this works: http://stackoverflow.com/a/402010", "rect_corner", "=", "self", ".", "size", "/", "2", "# relative to the rect center", "circle_center", "=", "(", "pt", "-", "self", ".",...
Does the circle intersect with this rect?
[ "Does", "the", "circle", "intersect", "with", "this", "rect?" ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/lib/point.py#L249-L266
train
deepmind/pysc2
pysc2/run_configs/platforms.py
_read_execute_info
def _read_execute_info(path, parents): """Read the ExecuteInfo.txt file and return the base directory.""" path = os.path.join(path, "StarCraft II/ExecuteInfo.txt") if os.path.exists(path): with open(path, "rb") as f: # Binary because the game appends a '\0' :(. for line in f: parts = [p.strip()...
python
def _read_execute_info(path, parents): """Read the ExecuteInfo.txt file and return the base directory.""" path = os.path.join(path, "StarCraft II/ExecuteInfo.txt") if os.path.exists(path): with open(path, "rb") as f: # Binary because the game appends a '\0' :(. for line in f: parts = [p.strip()...
[ "def", "_read_execute_info", "(", "path", ",", "parents", ")", ":", "path", "=", "os", ".", "path", ".", "join", "(", "path", ",", "\"StarCraft II/ExecuteInfo.txt\"", ")", "if", "os", ".", "path", ".", "exists", "(", "path", ")", ":", "with", "open", "...
Read the ExecuteInfo.txt file and return the base directory.
[ "Read", "the", "ExecuteInfo", ".", "txt", "file", "and", "return", "the", "base", "directory", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/run_configs/platforms.py#L41-L52
train
deepmind/pysc2
pysc2/run_configs/platforms.py
LocalBase.start
def start(self, version=None, want_rgb=True, **kwargs): """Launch the game.""" del want_rgb # Unused if not os.path.isdir(self.data_dir): raise sc_process.SC2LaunchError( "Expected to find StarCraft II installed at '%s'. If it's not " "installed, do that and run it once so auto-de...
python
def start(self, version=None, want_rgb=True, **kwargs): """Launch the game.""" del want_rgb # Unused if not os.path.isdir(self.data_dir): raise sc_process.SC2LaunchError( "Expected to find StarCraft II installed at '%s'. If it's not " "installed, do that and run it once so auto-de...
[ "def", "start", "(", "self", ",", "version", "=", "None", ",", "want_rgb", "=", "True", ",", "*", "*", "kwargs", ")", ":", "del", "want_rgb", "# Unused", "if", "not", "os", ".", "path", ".", "isdir", "(", "self", ".", "data_dir", ")", ":", "raise",...
Launch the game.
[ "Launch", "the", "game", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/run_configs/platforms.py#L66-L97
train
deepmind/pysc2
pysc2/env/host_remote_agent.py
VsAgent.create_game
def create_game(self, map_name): """Create a game for the agents to join. Args: map_name: The map to use. """ map_inst = maps.get(map_name) map_data = map_inst.data(self._run_config) if map_name not in self._saved_maps: for controller in self._controllers: controller.save_ma...
python
def create_game(self, map_name): """Create a game for the agents to join. Args: map_name: The map to use. """ map_inst = maps.get(map_name) map_data = map_inst.data(self._run_config) if map_name not in self._saved_maps: for controller in self._controllers: controller.save_ma...
[ "def", "create_game", "(", "self", ",", "map_name", ")", ":", "map_inst", "=", "maps", ".", "get", "(", "map_name", ")", "map_data", "=", "map_inst", ".", "data", "(", "self", ".", "_run_config", ")", "if", "map_name", "not", "in", "self", ".", "_saved...
Create a game for the agents to join. Args: map_name: The map to use.
[ "Create", "a", "game", "for", "the", "agents", "to", "join", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/env/host_remote_agent.py#L71-L94
train
deepmind/pysc2
pysc2/env/host_remote_agent.py
VsAgent.close
def close(self): """Shutdown and free all resources.""" for controller in self._controllers: controller.quit() self._controllers = [] for process in self._processes: process.close() self._processes = [] portspicker.return_ports(self._lan_ports) self._lan_ports = []
python
def close(self): """Shutdown and free all resources.""" for controller in self._controllers: controller.quit() self._controllers = [] for process in self._processes: process.close() self._processes = [] portspicker.return_ports(self._lan_ports) self._lan_ports = []
[ "def", "close", "(", "self", ")", ":", "for", "controller", "in", "self", ".", "_controllers", ":", "controller", ".", "quit", "(", ")", "self", ".", "_controllers", "=", "[", "]", "for", "process", "in", "self", ".", "_processes", ":", "process", ".",...
Shutdown and free all resources.
[ "Shutdown", "and", "free", "all", "resources", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/env/host_remote_agent.py#L111-L122
train
deepmind/pysc2
pysc2/env/host_remote_agent.py
VsBot.create_game
def create_game( self, map_name, bot_difficulty=sc_pb.VeryEasy, bot_race=sc_common.Random, bot_first=False): """Create a game, one remote agent vs the specified bot. Args: map_name: The map to use. bot_difficulty: The difficulty of the bot to play against. bot_ra...
python
def create_game( self, map_name, bot_difficulty=sc_pb.VeryEasy, bot_race=sc_common.Random, bot_first=False): """Create a game, one remote agent vs the specified bot. Args: map_name: The map to use. bot_difficulty: The difficulty of the bot to play against. bot_ra...
[ "def", "create_game", "(", "self", ",", "map_name", ",", "bot_difficulty", "=", "sc_pb", ".", "VeryEasy", ",", "bot_race", "=", "sc_common", ".", "Random", ",", "bot_first", "=", "False", ")", ":", "self", ".", "_controller", ".", "ping", "(", ")", "# Fo...
Create a game, one remote agent vs the specified bot. Args: map_name: The map to use. bot_difficulty: The difficulty of the bot to play against. bot_race: The race for the bot. bot_first: Whether the bot should be player 1 (else is player 2).
[ "Create", "a", "game", "one", "remote", "agent", "vs", "the", "specified", "bot", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/env/host_remote_agent.py#L158-L196
train
deepmind/pysc2
pysc2/env/host_remote_agent.py
VsBot.close
def close(self): """Shutdown and free all resources.""" if self._controller is not None: self._controller.quit() self._controller = None if self._process is not None: self._process.close() self._process = None
python
def close(self): """Shutdown and free all resources.""" if self._controller is not None: self._controller.quit() self._controller = None if self._process is not None: self._process.close() self._process = None
[ "def", "close", "(", "self", ")", ":", "if", "self", ".", "_controller", "is", "not", "None", ":", "self", ".", "_controller", ".", "quit", "(", ")", "self", ".", "_controller", "=", "None", "if", "self", ".", "_process", "is", "not", "None", ":", ...
Shutdown and free all resources.
[ "Shutdown", "and", "free", "all", "resources", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/env/host_remote_agent.py#L208-L215
train
deepmind/pysc2
pysc2/bin/play_vs_agent.py
agent
def agent(): """Run the agent, connecting to a (remote) host started independently.""" agent_module, agent_name = FLAGS.agent.rsplit(".", 1) agent_cls = getattr(importlib.import_module(agent_module), agent_name) logging.info("Starting agent:") with lan_sc2_env.LanSC2Env( host=FLAGS.host, config_p...
python
def agent(): """Run the agent, connecting to a (remote) host started independently.""" agent_module, agent_name = FLAGS.agent.rsplit(".", 1) agent_cls = getattr(importlib.import_module(agent_module), agent_name) logging.info("Starting agent:") with lan_sc2_env.LanSC2Env( host=FLAGS.host, config_p...
[ "def", "agent", "(", ")", ":", "agent_module", ",", "agent_name", "=", "FLAGS", ".", "agent", ".", "rsplit", "(", "\".\"", ",", "1", ")", "agent_cls", "=", "getattr", "(", "importlib", ".", "import_module", "(", "agent_module", ")", ",", "agent_name", ")...
Run the agent, connecting to a (remote) host started independently.
[ "Run", "the", "agent", "connecting", "to", "a", "(", "remote", ")", "host", "started", "independently", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/bin/play_vs_agent.py#L118-L143
train
deepmind/pysc2
pysc2/bin/play_vs_agent.py
human
def human(): """Run a host which expects one player to connect remotely.""" run_config = run_configs.get() map_inst = maps.get(FLAGS.map) if not FLAGS.rgb_screen_size or not FLAGS.rgb_minimap_size: logging.info("Use --rgb_screen_size and --rgb_minimap_size if you want rgb " "observations....
python
def human(): """Run a host which expects one player to connect remotely.""" run_config = run_configs.get() map_inst = maps.get(FLAGS.map) if not FLAGS.rgb_screen_size or not FLAGS.rgb_minimap_size: logging.info("Use --rgb_screen_size and --rgb_minimap_size if you want rgb " "observations....
[ "def", "human", "(", ")", ":", "run_config", "=", "run_configs", ".", "get", "(", ")", "map_inst", "=", "maps", ".", "get", "(", "FLAGS", ".", "map", ")", "if", "not", "FLAGS", ".", "rgb_screen_size", "or", "not", "FLAGS", ".", "rgb_minimap_size", ":",...
Run a host which expects one player to connect remotely.
[ "Run", "a", "host", "which", "expects", "one", "player", "to", "connect", "remotely", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/bin/play_vs_agent.py#L146-L269
train
deepmind/pysc2
pysc2/env/remote_sc2_env.py
RemoteSC2Env._connect_remote
def _connect_remote(self, host, host_port, lan_ports, race, name, map_inst, save_map, interface): """Make sure this stays synced with bin/agent_remote.py.""" # Connect! logging.info("Connecting...") self._controllers = [remote_controller.RemoteController(host, host_port)] loggi...
python
def _connect_remote(self, host, host_port, lan_ports, race, name, map_inst, save_map, interface): """Make sure this stays synced with bin/agent_remote.py.""" # Connect! logging.info("Connecting...") self._controllers = [remote_controller.RemoteController(host, host_port)] loggi...
[ "def", "_connect_remote", "(", "self", ",", "host", ",", "host_port", ",", "lan_ports", ",", "race", ",", "name", ",", "map_inst", ",", "save_map", ",", "interface", ")", ":", "# Connect!", "logging", ".", "info", "(", "\"Connecting...\"", ")", "self", "."...
Make sure this stays synced with bin/agent_remote.py.
[ "Make", "sure", "this", "stays", "synced", "with", "bin", "/", "agent_remote", ".", "py", "." ]
df4cc4b00f07a2242be9ba153d4a7f4ad2017897
https://github.com/deepmind/pysc2/blob/df4cc4b00f07a2242be9ba153d4a7f4ad2017897/pysc2/env/remote_sc2_env.py#L189-L214
train