Search is not available for this dataset
identifier
stringlengths
1
155
parameters
stringlengths
2
6.09k
docstring
stringlengths
11
63.4k
docstring_summary
stringlengths
0
63.4k
function
stringlengths
29
99.8k
function_tokens
list
start_point
list
end_point
list
language
stringclasses
1 value
docstring_language
stringlengths
2
7
docstring_language_predictions
stringlengths
18
23
is_langid_reliable
stringclasses
2 values
select_with_join_query
(self, user_name, grant_target_name, node=None)
Grant SELECT on the view and tables in the stored query and check the user is able to SELECT if and only if they have SELECT privilege on all of them.
Grant SELECT on the view and tables in the stored query and check the user is able to SELECT if and only if they have SELECT privilege on all of them.
def select_with_join_query(self, user_name, grant_target_name, node=None): """Grant SELECT on the view and tables in the stored query and check the user is able to SELECT if and only if they have SELECT privilege on all of them. """ view_name = f"view_{getuid()}" table0_name = f"table0_{getuid()}" t...
[ "def", "select_with_join_query", "(", "self", ",", "user_name", ",", "grant_target_name", ",", "node", "=", "None", ")", ":", "view_name", "=", "f\"view_{getuid()}\"", "table0_name", "=", "f\"table0_{getuid()}\"", "table1_name", "=", "f\"table1_{getuid()}\"", "exitcode"...
[ 754, 0 ]
[ 789, 62 ]
python
en
['en', 'en', 'en']
True
select_with_join_subquery_privilege_granted_directly_or_via_role
(self, node=None)
Check that user is able to select from a view with a stored query that includes `JOIN` and two subqueries if and only if the user has SELECT privilege on all the tables and the view, either directly or through a role.
Check that user is able to select from a view with a stored query that includes `JOIN` and two subqueries if and only if the user has SELECT privilege on all the tables and the view, either directly or through a role.
def select_with_join_subquery_privilege_granted_directly_or_via_role(self, node=None): """Check that user is able to select from a view with a stored query that includes `JOIN` and two subqueries if and only if the user has SELECT privilege on all the tables and the view, either directly or through a role. ...
[ "def", "select_with_join_subquery_privilege_granted_directly_or_via_role", "(", "self", ",", "node", "=", "None", ")", ":", "user_name", "=", "f\"user_{getuid()}\"", "role_name", "=", "f\"role_{getuid()}\"", "if", "node", "is", "None", ":", "node", "=", "self", ".", ...
[ 792, 0 ]
[ 809, 129 ]
python
en
['en', 'en', 'en']
True
select_with_join_subquery
(self, grant_target_name, user_name, node=None)
Grant SELECT on the view and tables in the stored query and check the user is able to SELECT if and only if they have SELECT privilege on all of them.
Grant SELECT on the view and tables in the stored query and check the user is able to SELECT if and only if they have SELECT privilege on all of them.
def select_with_join_subquery(self, grant_target_name, user_name, node=None): """Grant SELECT on the view and tables in the stored query and check the user is able to SELECT if and only if they have SELECT privilege on all of them. """ view_name = f"view_{getuid()}" table0_name = f"table0_{getuid()}" ...
[ "def", "select_with_join_subquery", "(", "self", ",", "grant_target_name", ",", "user_name", ",", "node", "=", "None", ")", ":", "view_name", "=", "f\"view_{getuid()}\"", "table0_name", "=", "f\"table0_{getuid()}\"", "table1_name", "=", "f\"table1_{getuid()}\"", "table2...
[ 812, 0 ]
[ 849, 62 ]
python
en
['en', 'en', 'en']
True
select_with_nested_views_privilege_granted_directly_or_via_role
(self, node=None)
Check that user is able to select from a view with a stored query that includes other views if and only if the user has SELECT privilege on all of the views and the source tables for those views, either directly or through a role.
Check that user is able to select from a view with a stored query that includes other views if and only if the user has SELECT privilege on all of the views and the source tables for those views, either directly or through a role.
def select_with_nested_views_privilege_granted_directly_or_via_role(self, node=None): """Check that user is able to select from a view with a stored query that includes other views if and only if the user has SELECT privilege on all of the views and the source tables for those views, either directly or through ...
[ "def", "select_with_nested_views_privilege_granted_directly_or_via_role", "(", "self", ",", "node", "=", "None", ")", ":", "user_name", "=", "f\"user_{getuid()}\"", "role_name", "=", "f\"role_{getuid()}\"", "if", "node", "is", "None", ":", "node", "=", "self", ".", ...
[ 852, 0 ]
[ 869, 128 ]
python
en
['en', 'en', 'en']
True
select_with_nested_views
(self, grant_target_name, user_name, node=None)
Grant SELECT on views and tables in the stored query and check the user is able to SELECT if and only if they have SELECT privilege on all of them.
Grant SELECT on views and tables in the stored query and check the user is able to SELECT if and only if they have SELECT privilege on all of them.
def select_with_nested_views(self, grant_target_name, user_name, node=None): """Grant SELECT on views and tables in the stored query and check the user is able to SELECT if and only if they have SELECT privilege on all of them. """ view0_name = f"view0_{getuid()}" view1_name = f"view1_{getuid()}" vi...
[ "def", "select_with_nested_views", "(", "self", ",", "grant_target_name", ",", "user_name", ",", "node", "=", "None", ")", ":", "view0_name", "=", "f\"view0_{getuid()}\"", "view1_name", "=", "f\"view1_{getuid()}\"", "view2_name", "=", "f\"view2_{getuid()}\"", "table0_na...
[ 872, 0 ]
[ 916, 67 ]
python
en
['en', 'en', 'en']
True
drop
(self, node=None)
Test the RBAC functionality of the `DROP VIEW` command.
Test the RBAC functionality of the `DROP VIEW` command.
def drop(self, node=None): """Test the RBAC functionality of the `DROP VIEW` command. """ Scenario(run=drop_with_privilege_granted_directly_or_via_role, setup=instrument_clickhouse_server_log) Scenario(run=drop_with_revoked_privilege_revoked_directly_or_from_role, setup=instrument_clickhouse_server_log)
[ "def", "drop", "(", "self", ",", "node", "=", "None", ")", ":", "Scenario", "(", "run", "=", "drop_with_privilege_granted_directly_or_via_role", ",", "setup", "=", "instrument_clickhouse_server_log", ")", "Scenario", "(", "run", "=", "drop_with_revoked_privilege_revok...
[ 922, 0 ]
[ 926, 115 ]
python
en
['en', 'en', 'en']
True
drop_with_privilege_granted_directly_or_via_role
(self, node=None)
Check that user is able to drop view with DROP VIEW privilege if the user has privilege directly or through a role.
Check that user is able to drop view with DROP VIEW privilege if the user has privilege directly or through a role.
def drop_with_privilege_granted_directly_or_via_role(self, node=None): """Check that user is able to drop view with DROP VIEW privilege if the user has privilege directly or through a role. """ user_name = f"user_{getuid()}" role_name = f"role_{getuid()}" if node is None: node = self.contex...
[ "def", "drop_with_privilege_granted_directly_or_via_role", "(", "self", ",", "node", "=", "None", ")", ":", "user_name", "=", "f\"user_{getuid()}\"", "role_name", "=", "f\"role_{getuid()}\"", "if", "node", "is", "None", ":", "node", "=", "self", ".", "context", "....
[ 929, 0 ]
[ 945, 107 ]
python
en
['en', 'en', 'en']
True
drop_with_privilege
(self, grant_target_name, user_name, node=None)
Grant DROP VIEW privilege and check the user is able to successfully drop a view.
Grant DROP VIEW privilege and check the user is able to successfully drop a view.
def drop_with_privilege(self, grant_target_name, user_name, node=None): """Grant DROP VIEW privilege and check the user is able to successfully drop a view. """ view_name = f"view_{getuid()}" exitcode, message = errors.table_does_not_exist(name=f"default.{view_name}") if node is None: node ...
[ "def", "drop_with_privilege", "(", "self", ",", "grant_target_name", ",", "user_name", ",", "node", "=", "None", ")", ":", "view_name", "=", "f\"view_{getuid()}\"", "exitcode", ",", "message", "=", "errors", ".", "table_does_not_exist", "(", "name", "=", "f\"def...
[ 948, 0 ]
[ 972, 58 ]
python
en
['en', 'en', 'en']
True
drop_with_revoked_privilege_revoked_directly_or_from_role
(self, node=None)
Check that user is unable to drop view with DROP VIEW privilege revoked directly or from a role.
Check that user is unable to drop view with DROP VIEW privilege revoked directly or from a role.
def drop_with_revoked_privilege_revoked_directly_or_from_role(self, node=None): """Check that user is unable to drop view with DROP VIEW privilege revoked directly or from a role. """ user_name = f"user_{getuid()}" role_name = f"role_{getuid()}" if node is None: node = self.context.node ...
[ "def", "drop_with_revoked_privilege_revoked_directly_or_from_role", "(", "self", ",", "node", "=", "None", ")", ":", "user_name", "=", "f\"user_{getuid()}\"", "role_name", "=", "f\"role_{getuid()}\"", "if", "node", "is", "None", ":", "node", "=", "self", ".", "conte...
[ 975, 0 ]
[ 991, 104 ]
python
en
['en', 'en', 'en']
True
drop_with_revoked_privilege
(self, grant_target_name, user_name, node=None)
Revoke DROP VIEW privilege and check the user is unable to DROP a view.
Revoke DROP VIEW privilege and check the user is unable to DROP a view.
def drop_with_revoked_privilege(self, grant_target_name, user_name, node=None): """Revoke DROP VIEW privilege and check the user is unable to DROP a view. """ view_name = f"view_{getuid()}" exitcode, message = errors.not_enough_privileges(name=f"{user_name}") if node is None: node = self.co...
[ "def", "drop_with_revoked_privilege", "(", "self", ",", "grant_target_name", ",", "user_name", ",", "node", "=", "None", ")", ":", "view_name", "=", "f\"view_{getuid()}\"", "exitcode", ",", "message", "=", "errors", ".", "not_enough_privileges", "(", "name", "=", ...
[ 994, 0 ]
[ 1018, 58 ]
python
en
['en', 'en', 'en']
True
refresh
(self, node=None)
Test the RBAC functionality of the `ALTER LIVE VIEW REFRESH` command.
Test the RBAC functionality of the `ALTER LIVE VIEW REFRESH` command.
def refresh(self, node=None): """Test the RBAC functionality of the `ALTER LIVE VIEW REFRESH` command. """ Scenario(run=refresh_with_privilege_granted_directly_or_via_role, setup=instrument_clickhouse_server_log) Scenario(run=refresh_with_privilege_revoked_directly_or_from_role, setup=instrument_clickho...
[ "def", "refresh", "(", "self", ",", "node", "=", "None", ")", ":", "Scenario", "(", "run", "=", "refresh_with_privilege_granted_directly_or_via_role", ",", "setup", "=", "instrument_clickhouse_server_log", ")", "Scenario", "(", "run", "=", "refresh_with_privilege_revo...
[ 1024, 0 ]
[ 1028, 110 ]
python
en
['en', 'en', 'en']
True
refresh_with_privilege_granted_directly_or_via_role
(self, node=None)
Check that user is able to refresh a live view with REFRESH privilege granted either directly or through a role.
Check that user is able to refresh a live view with REFRESH privilege granted either directly or through a role.
def refresh_with_privilege_granted_directly_or_via_role(self, node=None): """Check that user is able to refresh a live view with REFRESH privilege granted either directly or through a role. """ user_name = f"user_{getuid()}" role_name = f"role_{getuid()}" if node is None: node = self.co...
[ "def", "refresh_with_privilege_granted_directly_or_via_role", "(", "self", ",", "node", "=", "None", ")", ":", "user_name", "=", "f\"user_{getuid()}\"", "role_name", "=", "f\"role_{getuid()}\"", "if", "node", "is", "None", ":", "node", "=", "self", ".", "context", ...
[ 1031, 0 ]
[ 1048, 107 ]
python
en
['en', 'en', 'en']
True
refresh_with_privilege
(self, grant_target_name, user_name, node=None)
Grant REFRESH privilege and check that user is able to refresh a live view.
Grant REFRESH privilege and check that user is able to refresh a live view.
def refresh_with_privilege(self, grant_target_name, user_name, node=None): """Grant REFRESH privilege and check that user is able to refresh a live view. """ view_name = f"view_{getuid()}" if node is None: node = self.context.node try: with Given("I have a view"): node.q...
[ "def", "refresh_with_privilege", "(", "self", ",", "grant_target_name", ",", "user_name", ",", "node", "=", "None", ")", ":", "view_name", "=", "f\"view_{getuid()}\"", "if", "node", "is", "None", ":", "node", "=", "self", ".", "context", ".", "node", "try", ...
[ 1051, 0 ]
[ 1071, 58 ]
python
en
['en', 'en', 'en']
True
refresh_with_privilege_revoked_directly_or_from_role
(self, node=None)
Check that user is unable to refresh a live view with REFRESH privilege revoked either directly or through a role.
Check that user is unable to refresh a live view with REFRESH privilege revoked either directly or through a role.
def refresh_with_privilege_revoked_directly_or_from_role(self, node=None): """Check that user is unable to refresh a live view with REFRESH privilege revoked either directly or through a role. """ user_name = f"user_{getuid()}" role_name = f"role_{getuid()}" if node is None: node = self...
[ "def", "refresh_with_privilege_revoked_directly_or_from_role", "(", "self", ",", "node", "=", "None", ")", ":", "user_name", "=", "f\"user_{getuid()}\"", "role_name", "=", "f\"role_{getuid()}\"", "if", "node", "is", "None", ":", "node", "=", "self", ".", "context", ...
[ 1074, 0 ]
[ 1091, 107 ]
python
en
['en', 'en', 'en']
True
refresh_with_revoked_privilege
(self, grant_target_name, user_name, node=None)
Revoke REFRESH privilege and check that user is unable to refresh a live view.
Revoke REFRESH privilege and check that user is unable to refresh a live view.
def refresh_with_revoked_privilege(self, grant_target_name, user_name, node=None): """Revoke REFRESH privilege and check that user is unable to refresh a live view. """ view_name = f"view_{getuid()}" exitcode, message = errors.not_enough_privileges(name=f"{user_name}") if node is None: node...
[ "def", "refresh_with_revoked_privilege", "(", "self", ",", "grant_target_name", ",", "user_name", ",", "node", "=", "None", ")", ":", "view_name", "=", "f\"view_{getuid()}\"", "exitcode", ",", "message", "=", "errors", ".", "not_enough_privileges", "(", "name", "=...
[ 1094, 0 ]
[ 1117, 58 ]
python
en
['en', 'en', 'en']
True
empty_user_name
(self, timeout=300)
Check that empty string as a user name is not allowed.
Check that empty string as a user name is not allowed.
def empty_user_name(self, timeout=300): """Check that empty string as a user name is not allowed. """ servers = {"openldap1": { "host": "openldap1", "port": "389", "enable_tls": "no", "auth_dn_prefix": "cn=", "auth_dn_suffix": ",ou=users,dc=company,dc=com" }} users = [{"server": "ope...
[ "def", "empty_user_name", "(", "self", ",", "timeout", "=", "300", ")", ":", "servers", "=", "{", "\"openldap1\"", ":", "{", "\"host\"", ":", "\"openldap1\"", ",", "\"port\"", ":", "\"389\"", ",", "\"enable_tls\"", ":", "\"no\"", ",", "\"auth_dn_prefix\"", "...
[ 12, 0 ]
[ 21, 57 ]
python
en
['en', 'en', 'en']
True
empty_server_name
(self, timeout=300)
Check that if server name is an empty string then login is not allowed.
Check that if server name is an empty string then login is not allowed.
def empty_server_name(self, timeout=300): """Check that if server name is an empty string then login is not allowed. """ message = "Exception: LDAP server name cannot be empty for user" servers = {"openldap1": { "host": "openldap1", "port": "389", "enable_tls": "no", "auth_dn_prefix": "c...
[ "def", "empty_server_name", "(", "self", ",", "timeout", "=", "300", ")", ":", "message", "=", "\"Exception: LDAP server name cannot be empty for user\"", "servers", "=", "{", "\"openldap1\"", ":", "{", "\"host\"", ":", "\"openldap1\"", ",", "\"port\"", ":", "\"389\...
[ 28, 0 ]
[ 41, 83 ]
python
en
['en', 'en', 'en']
True
empty_server_not_defined
(self)
Check that if server is not defined then login is not allowed.
Check that if server is not defined then login is not allowed.
def empty_server_not_defined(self): """Check that if server is not defined then login is not allowed. """ servers = {"openldap1": { "host": "openldap1", "port": "389", "enable_tls": "no", "auth_dn_prefix": "cn=", "auth_dn_suffix": ",ou=users,dc=company,dc=com" }} users = [{"server": ...
[ "def", "empty_server_not_defined", "(", "self", ")", ":", "servers", "=", "{", "\"openldap1\"", ":", "{", "\"host\"", ":", "\"openldap1\"", ",", "\"port\"", ":", "\"389\"", ",", "\"enable_tls\"", ":", "\"no\"", ",", "\"auth_dn_prefix\"", ":", "\"cn=\"", ",", "...
[ 48, 0 ]
[ 59, 26 ]
python
en
['en', 'en', 'en']
True
valid_user_config
(self)
Check syntax of valid user configuration of LDAP authenticated user.
Check syntax of valid user configuration of LDAP authenticated user.
def valid_user_config(self): """Check syntax of valid user configuration of LDAP authenticated user.""" servers = {"openldap1": { "host": "openldap1", "port": "389", "enable_tls": "no", "auth_dn_prefix": "cn=", "auth_dn_suffix": ",ou=users,dc=company,dc=com" }} users = [{"server": "openl...
[ "def", "valid_user_config", "(", "self", ")", ":", "servers", "=", "{", "\"openldap1\"", ":", "{", "\"host\"", ":", "\"openldap1\"", ",", "\"port\"", ":", "\"389\"", ",", "\"enable_tls\"", ":", "\"no\"", ",", "\"auth_dn_prefix\"", ":", "\"cn=\"", ",", "\"auth_...
[ 65, 0 ]
[ 72, 26 ]
python
en
['en', 'en', 'en']
True
multiple_servers
(self)
Check that user configuration allows to specify only one LDAP server for a given user and if multiple servers are specified then the first one is used.
Check that user configuration allows to specify only one LDAP server for a given user and if multiple servers are specified then the first one is used.
def multiple_servers(self): """Check that user configuration allows to specify only one LDAP server for a given user and if multiple servers are specified then the first one is used.""" servers = { "openldap1": { "host": "openldap1", "port": "389", "enable_tls": "no", "auth_d...
[ "def", "multiple_servers", "(", "self", ")", ":", "servers", "=", "{", "\"openldap1\"", ":", "{", "\"host\"", ":", "\"openldap1\"", ",", "\"port\"", ":", "\"389\"", ",", "\"enable_tls\"", ":", "\"no\"", ",", "\"auth_dn_prefix\"", ":", "\"cn=\"", ",", "\"auth_d...
[ 78, 0 ]
[ 108, 47 ]
python
en
['en', 'en', 'en']
True
ldap_and_password
(self)
Check that user can't be authenticated if both `ldap` and `password` is specified for the same user. We expect an error message to be present in the log and login attempt to fail.
Check that user can't be authenticated if both `ldap` and `password` is specified for the same user. We expect an error message to be present in the log and login attempt to fail.
def ldap_and_password(self): """Check that user can't be authenticated if both `ldap` and `password` is specified for the same user. We expect an error message to be present in the log and login attempt to fail. """ node = self.context.node servers = { "openldap1": { "host": ...
[ "def", "ldap_and_password", "(", "self", ")", ":", "node", "=", "self", ".", "context", ".", "node", "servers", "=", "{", "\"openldap1\"", ":", "{", "\"host\"", ":", "\"openldap1\"", ",", "\"port\"", ":", "\"389\"", ",", "\"enable_tls\"", ":", "\"no\"", ",...
[ 114, 0 ]
[ 149, 80 ]
python
en
['en', 'en', 'en']
True
feature
(self, node="clickhouse1")
Check that server returns an error and prohibits user login if LDAP users configuration is not valid.
Check that server returns an error and prohibits user login if LDAP users configuration is not valid.
def feature(self, node="clickhouse1"): """Check that server returns an error and prohibits user login if LDAP users configuration is not valid. """ self.context.node = self.context.cluster.node(node) for scenario in loads(current_module(), Scenario): scenario()
[ "def", "feature", "(", "self", ",", "node", "=", "\"clickhouse1\"", ")", ":", "self", ".", "context", ".", "node", "=", "self", ".", "context", ".", "cluster", ".", "node", "(", "node", ")", "for", "scenario", "in", "loads", "(", "current_module", "(",...
[ 153, 0 ]
[ 160, 18 ]
python
en
['en', 'en', 'en']
True
allow_experimental_bigint
(node)
Enable experimental big int setting in Clickhouse.
Enable experimental big int setting in Clickhouse.
def allow_experimental_bigint(node): """Enable experimental big int setting in Clickhouse. """ setting = ("allow_experimental_bigint_types", 1) default_query_settings = None try: with Given("I add allow_experimental_bigint to the default query settings"): default_query_settings ...
[ "def", "allow_experimental_bigint", "(", "node", ")", ":", "setting", "=", "(", "\"allow_experimental_bigint_types\"", ",", "1", ")", "default_query_settings", "=", "None", "try", ":", "with", "Given", "(", "\"I add allow_experimental_bigint to the default query settings\""...
[ 13, 0 ]
[ 30, 24 ]
python
en
['en', 'en', 'en']
True
allow_experimental_map_type
(self)
Set allow_experimental_map_type = 1
Set allow_experimental_map_type = 1
def allow_experimental_map_type(self): """Set allow_experimental_map_type = 1 """ setting = ("allow_experimental_map_type", 1) default_query_settings = None try: with By("adding allow_experimental_map_type to the default query settings"): default_query_settings = getsattr(curren...
[ "def", "allow_experimental_map_type", "(", "self", ")", ":", "setting", "=", "(", "\"allow_experimental_map_type\"", ",", "1", ")", "default_query_settings", "=", "None", "try", ":", "with", "By", "(", "\"adding allow_experimental_map_type to the default query settings\"", ...
[ 33, 0 ]
[ 50, 24 ]
python
en
['it', 'en', 'en']
True
execute_query
(sql, expected=None, format="TabSeparatedWithNames", compare_func=None)
Execute SQL query and compare the output to the snapshot.
Execute SQL query and compare the output to the snapshot.
def execute_query(sql, expected=None, format="TabSeparatedWithNames", compare_func=None): """Execute SQL query and compare the output to the snapshot. """ name = basename(current().name) with When("I execute query", description=sql): r = current().context.node.query(sql + " FORMAT " + format) ...
[ "def", "execute_query", "(", "sql", ",", "expected", "=", "None", ",", "format", "=", "\"TabSeparatedWithNames\"", ",", "compare_func", "=", "None", ")", ":", "name", "=", "basename", "(", "current", "(", ")", ".", "name", ")", "with", "When", "(", "\"I ...
[ 52, 0 ]
[ 72, 111 ]
python
en
['en', 'en', 'en']
True
table
(self, data_type, name="table0")
Create a table.
Create a table.
def table(self, data_type, name="table0"): """Create a table. """ node = current().context.node try: with By("creating table"): node.query(f"CREATE TABLE {name}(a {data_type}) ENGINE = Memory") yield finally: with Finally("drop the table"): node.quer...
[ "def", "table", "(", "self", ",", "data_type", ",", "name", "=", "\"table0\"", ")", ":", "node", "=", "current", "(", ")", ".", "context", ".", "node", "try", ":", "with", "By", "(", "\"creating table\"", ")", ":", "node", ".", "query", "(", "f\"CREA...
[ 75, 0 ]
[ 87, 54 ]
python
en
['en', 'ga', 'en']
True
getuid
()
Create a unique variable name based on the test it is called from.
Create a unique variable name based on the test it is called from.
def getuid(): """Create a unique variable name based on the test it is called from. """ if current().subtype == TestSubType.Example: testname = f"{basename(parentname(current().name)).replace(' ', '_').replace(',','')}" else: testname = f"{basename(current().name).replace(' ', '_').repla...
[ "def", "getuid", "(", ")", ":", "if", "current", "(", ")", ".", "subtype", "==", "TestSubType", ".", "Example", ":", "testname", "=", "f\"{basename(parentname(current().name)).replace(' ', '_').replace(',','')}\"", "else", ":", "testname", "=", "f\"{basename(current().n...
[ 89, 0 ]
[ 100, 63 ]
python
en
['en', 'en', 'en']
True
to_data_type
(data_type, value)
Return a conversion statement based on the data type provided
Return a conversion statement based on the data type provided
def to_data_type(data_type, value): """Return a conversion statement based on the data type provided """ if data_type in ['Decimal256(0)']: return f'toDecimal256(\'{value}\',0)' else: return f'to{data_type}(\'{value}\')'
[ "def", "to_data_type", "(", "data_type", ",", "value", ")", ":", "if", "data_type", "in", "[", "'Decimal256(0)'", "]", ":", "return", "f'toDecimal256(\\'{value}\\',0)'", "else", ":", "return", "f'to{data_type}(\\'{value}\\')'" ]
[ 102, 0 ]
[ 109, 44 ]
python
en
['en', 'en', 'en']
True
EpidemicDiscrete.__init__
(self, cost_function, model, simulation_horizon, ratio_death_to_R=0.005, # death ratio among people who were infected time_resolution=7, seed=np.random.randint(1e6) )
EpidemicDiscrete environment is based on the Epidemiological SEIRAH model from Prague et al., 2020 and on a bi-objective cost function (death toll and gdp recess). Parameters ---------- cost_function: BaseCostFunction A cost function. model: BaseModel ...
EpidemicDiscrete environment is based on the Epidemiological SEIRAH model from Prague et al., 2020 and on a bi-objective cost function (death toll and gdp recess).
def __init__(self, cost_function, model, simulation_horizon, ratio_death_to_R=0.005, # death ratio among people who were infected time_resolution=7, seed=np.random.randint(1e6) ): """ ...
[ "def", "__init__", "(", "self", ",", "cost_function", ",", "model", ",", "simulation_horizon", ",", "ratio_death_to_R", "=", "0.005", ",", "# death ratio among people who were infected", "time_resolution", "=", "7", ",", "seed", "=", "np", ".", "random", ".", "ran...
[ 6, 4 ]
[ 67, 22 ]
python
en
['en', 'error', 'th']
False
EpidemicDiscrete._compute_b
(self, times_since_start, times_since_last)
Computes the transmission rate depending on the number of days since the last lock-down or since beginning of the current lock-down. Parameters ---------- times_since_start: nd.array of ints Time since the start of the current lock-down, for each day. times_since_la...
Computes the transmission rate depending on the number of days since the last lock-down or since beginning of the current lock-down.
def _compute_b(self, times_since_start, times_since_last): """ Computes the transmission rate depending on the number of days since the last lock-down or since beginning of the current lock-down. Parameters ---------- times_since_start: nd.array of ints Time since th...
[ "def", "_compute_b", "(", "self", ",", "times_since_start", ",", "times_since_last", ")", ":", "if", "self", ".", "lockdown_state", "==", "0", ":", "# if new lock-down decrease the transmission rate of one stage", "if", "self", ".", "previous_lockdown_state", "!=", "sel...
[ 69, 4 ]
[ 109, 17 ]
python
en
['en', 'error', 'th']
False
EpidemicDiscrete._update_previous_env_state
(self)
Save previous env state.
Save previous env state.
def _update_previous_env_state(self): """ Save previous env state. """ if self.env_state is not None: self.previous_env_state = self.env_state.copy() self.previous_env_state_labelled = self.env_state_labelled.copy()
[ "def", "_update_previous_env_state", "(", "self", ")", ":", "if", "self", ".", "env_state", "is", "not", "None", ":", "self", ".", "previous_env_state", "=", "self", ".", "env_state", ".", "copy", "(", ")", "self", ".", "previous_env_state_labelled", "=", "s...
[ 111, 4 ]
[ 118, 77 ]
python
en
['en', 'error', 'th']
False
EpidemicDiscrete._update_env_state
(self)
Update the environment state.
Update the environment state.
def _update_env_state(self): """ Update the environment state. """ # Update env state self.env_state_labelled = dict(zip(self.model.internal_states_labels, self.model_state)) self.env_state_labelled.update(previous_lockdown_state=self.previous_lockdown_state, ...
[ "def", "_update_env_state", "(", "self", ")", ":", "# Update env state", "self", ".", "env_state_labelled", "=", "dict", "(", "zip", "(", "self", ".", "model", ".", "internal_states_labels", ",", "self", ".", "model_state", ")", ")", "self", ".", "env_state_la...
[ 120, 4 ]
[ 141, 77 ]
python
en
['en', 'error', 'th']
False
EpidemicDiscrete.reset_same_model
(self)
To call if you want to reset to the same model the next time you call reset. Will be cancelled after the first reset, it needs to be called again each time.
To call if you want to reset to the same model the next time you call reset. Will be cancelled after the first reset, it needs to be called again each time.
def reset_same_model(self): """ To call if you want to reset to the same model the next time you call reset. Will be cancelled after the first reset, it needs to be called again each time. """ self.reset_same = True
[ "def", "reset_same_model", "(", "self", ")", ":", "self", ".", "reset_same", "=", "True" ]
[ 143, 4 ]
[ 150, 30 ]
python
en
['en', 'error', 'th']
False
EpidemicDiscrete.reset
(self)
Reset the environment and the tracking of data. Returns ------- nd.array The initial environment state.
Reset the environment and the tracking of data.
def reset(self): """ Reset the environment and the tracking of data. Returns ------- nd.array The initial environment state. """ # initialize history of states, internal model states, actions, cost_functions, deaths self.history = dict(env_st...
[ "def", "reset", "(", "self", ")", ":", "# initialize history of states, internal model states, actions, cost_functions, deaths", "self", ".", "history", "=", "dict", "(", "env_states", "=", "[", "]", ",", "model_states", "=", "[", "]", ",", "env_timesteps", "=", "["...
[ 152, 4 ]
[ 200, 56 ]
python
en
['en', 'error', 'th']
False
EpidemicDiscrete.update_with_action
(self, action)
Implement effect of action on transmission rate. Parameters ---------- action: int Action is 0 (no lock-down) or 1 (lock-down).
Implement effect of action on transmission rate.
def update_with_action(self, action): """ Implement effect of action on transmission rate. Parameters ---------- action: int Action is 0 (no lock-down) or 1 (lock-down). """ # Translate actions self.previous_lockdown_state = self.lockdown_st...
[ "def", "update_with_action", "(", "self", ",", "action", ")", ":", "# Translate actions", "self", ".", "previous_lockdown_state", "=", "self", ".", "lockdown_state", "previous_count_start", "=", "self", ".", "count_since_start_lockdown", "previous_count_last", "=", "sel...
[ 202, 4 ]
[ 240, 60 ]
python
en
['en', 'error', 'th']
False
EpidemicDiscrete.step
(self, action)
Traditional step function from OpenAI Gym envs. Uses the action to update the environment. Parameters ---------- action: int Action is 0 (no lock-down) or 1 (lock-down). Returns ------- state: nd.array New environment state. cos...
Traditional step function from OpenAI Gym envs. Uses the action to update the environment.
def step(self, action): """ Traditional step function from OpenAI Gym envs. Uses the action to update the environment. Parameters ---------- action: int Action is 0 (no lock-down) or 1 (lock-down). Returns ------- state: nd.array ...
[ "def", "step", "(", "self", ",", "action", ")", ":", "action", "=", "int", "(", "action", ")", "assert", "0", "<=", "action", "<", "self", ".", "dim_action", "self", ".", "update_with_action", "(", "action", ")", "if", "self", ".", "lockdown_state", "=...
[ 242, 4 ]
[ 327, 137 ]
python
en
['en', 'error', 'th']
False
restart
(node=None, safe=False, timeout=300)
Restart ClickHouse server and wait for config to be reloaded.
Restart ClickHouse server and wait for config to be reloaded.
def restart(node=None, safe=False, timeout=300): """Restart ClickHouse server and wait for config to be reloaded. """ with When("I restart ClickHouse server node"): if node is None: node = current().context.node with node.cluster.shell(node.name) as bash: bash.expect...
[ "def", "restart", "(", "node", "=", "None", ",", "safe", "=", "False", ",", "timeout", "=", "300", ")", ":", "with", "When", "(", "\"I restart ClickHouse server node\"", ")", ":", "if", "node", "is", "None", ":", "node", "=", "current", "(", ")", ".", ...
[ 49, 0 ]
[ 78, 36 ]
python
en
['en', 'en', 'en']
True
add_config
(config, timeout=300, restart=False, modify=False)
Add dynamic configuration file to ClickHouse. :param node: node :param config: configuration file description :param timeout: timeout, default: 20 sec
Add dynamic configuration file to ClickHouse.
def add_config(config, timeout=300, restart=False, modify=False): """Add dynamic configuration file to ClickHouse. :param node: node :param config: configuration file description :param timeout: timeout, default: 20 sec """ node = current().context.node cluster = current().context.cluster ...
[ "def", "add_config", "(", "config", ",", "timeout", "=", "300", ",", "restart", "=", "False", ",", "modify", "=", "False", ")", ":", "node", "=", "current", "(", ")", ".", "context", ".", "node", "cluster", "=", "current", "(", ")", ".", "context", ...
[ 80, 0 ]
[ 181, 54 ]
python
en
['en', 'en', 'en']
True
create_ldap_servers_config_content
(servers, config_d_dir="/etc/clickhouse-server/config.d", config_file="ldap_servers.xml")
Create LDAP servers configuration content.
Create LDAP servers configuration content.
def create_ldap_servers_config_content(servers, config_d_dir="/etc/clickhouse-server/config.d", config_file="ldap_servers.xml"): """Create LDAP servers configuration content. """ uid = getuid() path = os.path.join(config_d_dir, config_file) name = config_file root = xmltree.fromstring("<yandex>...
[ "def", "create_ldap_servers_config_content", "(", "servers", ",", "config_d_dir", "=", "\"/etc/clickhouse-server/config.d\"", ",", "config_file", "=", "\"ldap_servers.xml\"", ")", ":", "uid", "=", "getuid", "(", ")", "path", "=", "os", ".", "path", ".", "join", "(...
[ 183, 0 ]
[ 203, 57 ]
python
en
['en', 'fr', 'en']
True
modify_config
(config, restart=False)
Apply updated configuration file.
Apply updated configuration file.
def modify_config(config, restart=False): """Apply updated configuration file. """ return add_config(config, restart=restart, modify=True)
[ "def", "modify_config", "(", "config", ",", "restart", "=", "False", ")", ":", "return", "add_config", "(", "config", ",", "restart", "=", "restart", ",", "modify", "=", "True", ")" ]
[ 206, 0 ]
[ 209, 59 ]
python
en
['en', 'en', 'en']
True
ldap_servers
(servers, config_d_dir="/etc/clickhouse-server/config.d", config_file="ldap_servers.xml", timeout=300, restart=False, config=None)
Add LDAP servers configuration.
Add LDAP servers configuration.
def ldap_servers(servers, config_d_dir="/etc/clickhouse-server/config.d", config_file="ldap_servers.xml", timeout=300, restart=False, config=None): """Add LDAP servers configuration. """ if config is None: config = create_ldap_servers_config_content(servers, config_d_dir, config_file) re...
[ "def", "ldap_servers", "(", "servers", ",", "config_d_dir", "=", "\"/etc/clickhouse-server/config.d\"", ",", "config_file", "=", "\"ldap_servers.xml\"", ",", "timeout", "=", "300", ",", "restart", "=", "False", ",", "config", "=", "None", ")", ":", "if", "config...
[ 212, 0 ]
[ 218, 46 ]
python
en
['en', 'zh', 'en']
True
create_ldap_users_config_content
(*users, config_d_dir="/etc/clickhouse-server/users.d", config_file="ldap_users.xml")
Create LDAP users configuration file content.
Create LDAP users configuration file content.
def create_ldap_users_config_content(*users, config_d_dir="/etc/clickhouse-server/users.d", config_file="ldap_users.xml"): """Create LDAP users configuration file content. """ uid = getuid() path = os.path.join(config_d_dir, config_file) name = config_file root = xmltree.fromstring("<yandex><us...
[ "def", "create_ldap_users_config_content", "(", "*", "users", ",", "config_d_dir", "=", "\"/etc/clickhouse-server/users.d\"", ",", "config_file", "=", "\"ldap_users.xml\"", ")", ":", "uid", "=", "getuid", "(", ")", "path", "=", "os", ".", "path", ".", "join", "(...
[ 220, 0 ]
[ 241, 56 ]
python
en
['en', 'en', 'en']
True
add_users_identified_with_ldap
(*users)
Add one or more users that are identified via an ldap server using RBAC.
Add one or more users that are identified via an ldap server using RBAC.
def add_users_identified_with_ldap(*users): """Add one or more users that are identified via an ldap server using RBAC. """ node = current().context.node try: with Given("I create users"): for user in users: node.query(f"CREATE USER '{user['username']}' IDENTIFIED...
[ "def", "add_users_identified_with_ldap", "(", "*", "users", ")", ":", "node", "=", "current", "(", ")", ".", "context", ".", "node", "try", ":", "with", "Given", "(", "\"I create users\"", ")", ":", "for", "user", "in", "users", ":", "node", ".", "query"...
[ 243, 0 ]
[ 257, 75 ]
python
en
['en', 'en', 'en']
True
ldap_authenticated_users
(*users, config_d_dir="/etc/clickhouse-server/users.d", config_file=None, timeout=300, restart=True, config=None, rbac=False)
Add LDAP authenticated users.
Add LDAP authenticated users.
def ldap_authenticated_users(*users, config_d_dir="/etc/clickhouse-server/users.d", config_file=None, timeout=300, restart=True, config=None, rbac=False): """Add LDAP authenticated users. """ if rbac: return add_users_identified_with_ldap(*users) else: if config_file is None: ...
[ "def", "ldap_authenticated_users", "(", "*", "users", ",", "config_d_dir", "=", "\"/etc/clickhouse-server/users.d\"", ",", "config_file", "=", "None", ",", "timeout", "=", "300", ",", "restart", "=", "True", ",", "config", "=", "None", ",", "rbac", "=", "False...
[ 260, 0 ]
[ 271, 67 ]
python
en
['en', 'en', 'en']
True
invalid_server_config
(servers, message=None, tail=30, timeout=300)
Check that ClickHouse errors when trying to load invalid LDAP servers configuration file.
Check that ClickHouse errors when trying to load invalid LDAP servers configuration file.
def invalid_server_config(servers, message=None, tail=30, timeout=300): """Check that ClickHouse errors when trying to load invalid LDAP servers configuration file. """ node = current().context.node if message is None: message = "Exception: Failed to merge config with '/etc/clickhouse-server/con...
[ "def", "invalid_server_config", "(", "servers", ",", "message", "=", "None", ",", "tail", "=", "30", ",", "timeout", "=", "300", ")", ":", "node", "=", "current", "(", ")", ".", "context", ".", "node", "if", "message", "is", "None", ":", "message", "...
[ 273, 0 ]
[ 300, 65 ]
python
en
['en', 'en', 'en']
True
invalid_user_config
(servers, config, message=None, tail=30, timeout=300)
Check that ClickHouse errors when trying to load invalid LDAP users configuration file.
Check that ClickHouse errors when trying to load invalid LDAP users configuration file.
def invalid_user_config(servers, config, message=None, tail=30, timeout=300): """Check that ClickHouse errors when trying to load invalid LDAP users configuration file. """ node = current().context.node if message is None: message = "Exception: Failed to merge config with '/etc/clickhouse-server...
[ "def", "invalid_user_config", "(", "servers", ",", "config", ",", "message", "=", "None", ",", "tail", "=", "30", ",", "timeout", "=", "300", ")", ":", "node", "=", "current", "(", ")", ".", "context", ".", "node", "if", "message", "is", "None", ":",...
[ 302, 0 ]
[ 328, 69 ]
python
en
['en', 'en', 'en']
True
add_user_to_ldap
(cn, userpassword, givenname=None, homedirectory=None, sn=None, uid=None, uidnumber=None, node=None)
Add user entry to LDAP.
Add user entry to LDAP.
def add_user_to_ldap(cn, userpassword, givenname=None, homedirectory=None, sn=None, uid=None, uidnumber=None, node=None): """Add user entry to LDAP.""" if node is None: node = current().context.ldap_node if uid is None: uid = cn if givenname is None: givenname = "John" if hom...
[ "def", "add_user_to_ldap", "(", "cn", ",", "userpassword", ",", "givenname", "=", "None", ",", "homedirectory", "=", "None", ",", "sn", "=", "None", ",", "uid", "=", "None", ",", "uidnumber", "=", "None", ",", "node", "=", "None", ")", ":", "if", "no...
[ 330, 0 ]
[ 376, 15 ]
python
en
['en', 'en', 'en']
True
delete_user_from_ldap
(user, node=None, exitcode=0)
Delete user entry from LDAP.
Delete user entry from LDAP.
def delete_user_from_ldap(user, node=None, exitcode=0): """Delete user entry from LDAP.""" if node is None: node = current().context.ldap_node r = node.command( f"ldapdelete -x -H ldap://localhost -D \"cn=admin,dc=company,dc=com\" -w admin \"{user['dn']}\"") if exitcode is not None: ...
[ "def", "delete_user_from_ldap", "(", "user", ",", "node", "=", "None", ",", "exitcode", "=", "0", ")", ":", "if", "node", "is", "None", ":", "node", "=", "current", "(", ")", ".", "context", ".", "ldap_node", "r", "=", "node", ".", "command", "(", ...
[ 378, 0 ]
[ 385, 46 ]
python
en
['en', 'en', 'en']
True
change_user_password_in_ldap
(user, new_password, node=None, exitcode=0)
Change user password in LDAP.
Change user password in LDAP.
def change_user_password_in_ldap(user, new_password, node=None, exitcode=0): """Change user password in LDAP.""" if node is None: node = current().context.ldap_node ldif = (f"dn: {user['dn']}\n" "changetype: modify\n" "replace: userpassword\n" f"userpassword: {new_password}"...
[ "def", "change_user_password_in_ldap", "(", "user", ",", "new_password", ",", "node", "=", "None", ",", "exitcode", "=", "0", ")", ":", "if", "node", "is", "None", ":", "node", "=", "current", "(", ")", ".", "context", ".", "ldap_node", "ldif", "=", "(...
[ 387, 0 ]
[ 401, 46 ]
python
en
['en', 'nl', 'en']
True
change_user_cn_in_ldap
(user, new_cn, node=None, exitcode=0)
Change user password in LDAP.
Change user password in LDAP.
def change_user_cn_in_ldap(user, new_cn, node=None, exitcode=0): """Change user password in LDAP.""" if node is None: node = current().context.ldap_node new_user = dict(user) new_user['dn'] = f"cn={new_cn},ou=users,dc=company,dc=com" new_user['cn'] = new_cn ldif = ( f"dn: {user...
[ "def", "change_user_cn_in_ldap", "(", "user", ",", "new_cn", ",", "node", "=", "None", ",", "exitcode", "=", "0", ")", ":", "if", "node", "is", "None", ":", "node", "=", "current", "(", ")", ".", "context", ".", "ldap_node", "new_user", "=", "dict", ...
[ 403, 0 ]
[ 425, 19 ]
python
en
['en', 'nl', 'en']
True
ldap_user
(cn, userpassword, givenname=None, homedirectory=None, sn=None, uid=None, uidnumber=None, node=None)
Add new user to the LDAP server.
Add new user to the LDAP server.
def ldap_user(cn, userpassword, givenname=None, homedirectory=None, sn=None, uid=None, uidnumber=None, node=None): """Add new user to the LDAP server.""" try: user = None with Given(f"I add user {cn} to LDAP"): user = add_user_to_ldap(cn, userpassword, givenname, homedirectory, sn, u...
[ "def", "ldap_user", "(", "cn", ",", "userpassword", ",", "givenname", "=", "None", ",", "homedirectory", "=", "None", ",", "sn", "=", "None", ",", "uid", "=", "None", ",", "uidnumber", "=", "None", ",", "node", "=", "None", ")", ":", "try", ":", "u...
[ 428, 0 ]
[ 438, 54 ]
python
en
['en', 'en', 'en']
True
ldap_users
(*users, node=None)
Add multiple new users to the LDAP server.
Add multiple new users to the LDAP server.
def ldap_users(*users, node=None): """Add multiple new users to the LDAP server.""" try: _users = [] with Given("I add users to LDAP"): for user in users: with By(f"adding user {user['cn']}"): _users.append(add_user_to_ldap(**user, node=node)) ...
[ "def", "ldap_users", "(", "*", "users", ",", "node", "=", "None", ")", ":", "try", ":", "_users", "=", "[", "]", "with", "Given", "(", "\"I add users to LDAP\"", ")", ":", "for", "user", "in", "users", ":", "with", "By", "(", "f\"adding user {user['cn']}...
[ 441, 0 ]
[ 453, 55 ]
python
en
['en', 'en', 'en']
True
login
(servers, *users, config=None)
Configure LDAP server and LDAP authenticated users and try to login and execute a query
Configure LDAP server and LDAP authenticated users and try to login and execute a query
def login(servers, *users, config=None): """Configure LDAP server and LDAP authenticated users and try to login and execute a query""" with ldap_servers(servers): with ldap_authenticated_users(*users, restart=True, config=config): for user in users: if user.get("login", F...
[ "def", "login", "(", "servers", ",", "*", "users", ",", "config", "=", "None", ")", ":", "with", "ldap_servers", "(", "servers", ")", ":", "with", "ldap_authenticated_users", "(", "*", "users", ",", "restart", "=", "True", ",", "config", "=", "config", ...
[ 455, 0 ]
[ 466, 62 ]
python
en
['en', 'en', 'en']
True
public_tables
(self, node=None)
Check that a user with no privilege is able to select from public tables.
Check that a user with no privilege is able to select from public tables.
def public_tables(self, node=None): """Check that a user with no privilege is able to select from public tables. """ user_name = f"user_{getuid()}" if node is None: node = self.context.node with user(node, f"{user_name}"): with When("I check the user is able to select on system.one...
[ "def", "public_tables", "(", "self", ",", "node", "=", "None", ")", ":", "user_name", "=", "f\"user_{getuid()}\"", "if", "node", "is", "None", ":", "node", "=", "self", ".", "context", ".", "node", "with", "user", "(", "node", ",", "f\"{user_name}\"", ")...
[ 12, 0 ]
[ 31, 96 ]
python
en
['en', 'en', 'en']
True
sensitive_tables
(self, node=None)
Check that a user with no privilege is not able to see from these tables.
Check that a user with no privilege is not able to see from these tables.
def sensitive_tables(self, node=None): """Check that a user with no privilege is not able to see from these tables. """ user_name = f"user_{getuid()}" if node is None: node = self.context.node with user(node, f"{user_name}"): with Given("I create a query"): node.query("S...
[ "def", "sensitive_tables", "(", "self", ",", "node", "=", "None", ")", ":", "user_name", "=", "f\"user_{getuid()}\"", "if", "node", "is", "None", ":", "node", "=", "self", ".", "context", ".", "node", "with", "user", "(", "node", ",", "f\"{user_name}\"", ...
[ 37, 0 ]
[ 90, 39 ]
python
en
['en', 'en', 'en']
True
feature
(self, node="clickhouse1")
Check set default role query syntax. ```sql SET DEFAULT ROLE {NONE | role [,...] | ALL | ALL EXCEPT role [,...]} TO {user|CURRENT_USER} [,...] ```
Check set default role query syntax.
def feature(self, node="clickhouse1"): """Check set default role query syntax. ```sql SET DEFAULT ROLE {NONE | role [,...] | ALL | ALL EXCEPT role [,...]} TO {user|CURRENT_USER} [,...] ``` """ node = self.context.cluster.node(node) @contextmanager def setup(users=2,roles=2): tr...
[ "def", "feature", "(", "self", ",", "node", "=", "\"clickhouse1\"", ")", ":", "node", "=", "self", ".", "context", ".", "cluster", ".", "node", "(", "node", ")", "@", "contextmanager", "def", "setup", "(", "users", "=", "2", ",", "roles", "=", "2", ...
[ 10, 0 ]
[ 119, 58 ]
python
en
['fr', 'en', 'en']
True
is_good_response
(resp)
Returns True if the response seems to be HTML, False otherwise.
Returns True if the response seems to be HTML, False otherwise.
def is_good_response(resp): """ Returns True if the response seems to be HTML, False otherwise. """ content_type = resp.headers['Content-Type'].lower() return (resp.status_code == 200 and content_type is not None and content_type.find('html') > -1)
[ "def", "is_good_response", "(", "resp", ")", ":", "content_type", "=", "resp", ".", "headers", "[", "'Content-Type'", "]", ".", "lower", "(", ")", "return", "(", "resp", ".", "status_code", "==", "200", "and", "content_type", "is", "not", "None", "and", ...
[ 41, 0 ]
[ 48, 47 ]
python
en
['en', 'error', 'th']
False
loadClusterFit
(pkl_file, npz_file, outPrefix = "", max_samples = 100000, use_gpu = False)
Call this to load a fitted model Args: pkl_file (str) Location of saved .pkl file on disk npz_file (str) Location of saved .npz file on disk outPrefix (str) Output prefix for model to save to (e.g. plots) max_samples (int) Maximum samp...
Call this to load a fitted model
def loadClusterFit(pkl_file, npz_file, outPrefix = "", max_samples = 100000, use_gpu = False): '''Call this to load a fitted model Args: pkl_file (str) Location of saved .pkl file on disk npz_file (str) Location of saved .npz file on disk outPr...
[ "def", "loadClusterFit", "(", "pkl_file", ",", "npz_file", ",", "outPrefix", "=", "\"\"", ",", "max_samples", "=", "100000", ",", "use_gpu", "=", "False", ")", ":", "with", "open", "(", "pkl_file", ",", "'rb'", ")", "as", "pickle_obj", ":", "fit_object", ...
[ 83, 0 ]
[ 142, 19 ]
python
en
['en', 'en', 'en']
True
assign_samples
(chunk, X, y, model, scale, chunk_size, values = False)
Runs a models assignment on a chunk of input Args: chunk (int) Index of chunk to process X (NumpyShared) n x 2 array of core and accessory distances for n samples y (NumpyShared) An n-vector to store results, with the most likely cluster memberships ...
Runs a models assignment on a chunk of input
def assign_samples(chunk, X, y, model, scale, chunk_size, values = False): """Runs a models assignment on a chunk of input Args: chunk (int) Index of chunk to process X (NumpyShared) n x 2 array of core and accessory distances for n samples y (NumpyShared) ...
[ "def", "assign_samples", "(", "chunk", ",", "X", ",", "y", ",", "model", ",", "scale", ",", "chunk_size", ",", "values", "=", "False", ")", ":", "# Make sure this is run single threaded", "with", "set_env", "(", "MKL_NUM_THREADS", "=", "'1'", ",", "NUMEXPR_NUM...
[ 144, 0 ]
[ 198, 91 ]
python
en
['en', 'en', 'en']
True
ClusterFit.fit
(self, X = None)
Initial steps for all fit functions. Creates output directory. If preprocess is set then subsamples passed X Args: X (numpy.array) The core and accessory distances to cluster. Must be set if preprocess is set. (default = None) de...
Initial steps for all fit functions.
def fit(self, X = None): '''Initial steps for all fit functions. Creates output directory. If preprocess is set then subsamples passed X Args: X (numpy.array) The core and accessory distances to cluster. Must be set if preprocess is set. ...
[ "def", "fit", "(", "self", ",", "X", "=", "None", ")", ":", "# set output dir", "if", "not", "os", ".", "path", ".", "isdir", "(", "self", ".", "outPrefix", ")", ":", "if", "not", "os", ".", "path", ".", "isfile", "(", "self", ".", "outPrefix", "...
[ 226, 4 ]
[ 260, 43 ]
python
en
['en', 'en', 'en']
True
ClusterFit.plot
(self, X=None)
Initial steps for all plot functions. Ensures model has been fitted. Args: X (numpy.array) The core and accessory distances to subsample. (default = None)
Initial steps for all plot functions.
def plot(self, X=None): '''Initial steps for all plot functions. Ensures model has been fitted. Args: X (numpy.array) The core and accessory distances to subsample. (default = None) ''' if not self.fitted: raise RuntimeEr...
[ "def", "plot", "(", "self", ",", "X", "=", "None", ")", ":", "if", "not", "self", ".", "fitted", ":", "raise", "RuntimeError", "(", "\"Trying to plot unfitted model\"", ")" ]
[ 262, 4 ]
[ 274, 63 ]
python
en
['en', 'en', 'en']
True
ClusterFit.no_scale
(self)
Turn off scaling (useful for refine, where optimization is done in the scaled space).
Turn off scaling (useful for refine, where optimization is done in the scaled space).
def no_scale(self): '''Turn off scaling (useful for refine, where optimization is done in the scaled space). ''' self.scale = np.array([1, 1], dtype = self.default_dtype)
[ "def", "no_scale", "(", "self", ")", ":", "self", ".", "scale", "=", "np", ".", "array", "(", "[", "1", ",", "1", "]", ",", "dtype", "=", "self", ".", "default_dtype", ")" ]
[ 276, 4 ]
[ 280, 65 ]
python
en
['en', 'en', 'en']
True
ClusterFit.copy
(self, prefix)
Copy the model to a new directory
Copy the model to a new directory
def copy(self, prefix): """Copy the model to a new directory """ self.outPrefix = prefix self.save()
[ "def", "copy", "(", "self", ",", "prefix", ")", ":", "self", ".", "outPrefix", "=", "prefix", "self", ".", "save", "(", ")" ]
[ 282, 4 ]
[ 286, 19 ]
python
en
['en', 'en', 'en']
True
BGMMFit.fit
(self, X, max_components)
Extends :func:`~ClusterFit.fit` Fits the BGMM and returns assignments by calling :func:`~PopPUNK.bgmm.fit2dMultiGaussian`. Fitted parameters are stored in the object. Args: X (numpy.array) The core and accessory distances to cluster. Must be set if ...
Extends :func:`~ClusterFit.fit`
def fit(self, X, max_components): '''Extends :func:`~ClusterFit.fit` Fits the BGMM and returns assignments by calling :func:`~PopPUNK.bgmm.fit2dMultiGaussian`. Fitted parameters are stored in the object. Args: X (numpy.array) The core and accessory ...
[ "def", "fit", "(", "self", ",", "X", ",", "max_components", ")", ":", "ClusterFit", ".", "fit", "(", "self", ",", "X", ")", "self", ".", "dpgmm", "=", "fit2dMultiGaussian", "(", "self", ".", "subsampled_X", ",", "max_components", ")", "self", ".", "wei...
[ 311, 4 ]
[ 340, 16 ]
python
et
['et', 'fr', 'nl']
False
BGMMFit.save
(self)
Save the model to disk, as an npz and pkl (using outPrefix).
Save the model to disk, as an npz and pkl (using outPrefix).
def save(self): '''Save the model to disk, as an npz and pkl (using outPrefix).''' if not self.fitted: raise RuntimeError("Trying to save unfitted model") else: np.savez(self.outPrefix + "/" + os.path.basename(self.outPrefix) + '_fit.npz', weights=self.weight...
[ "def", "save", "(", "self", ")", ":", "if", "not", "self", ".", "fitted", ":", "raise", "RuntimeError", "(", "\"Trying to save unfitted model\"", ")", "else", ":", "np", ".", "savez", "(", "self", ".", "outPrefix", "+", "\"/\"", "+", "os", ".", "path", ...
[ 343, 4 ]
[ 356, 65 ]
python
en
['en', 'en', 'en']
True
BGMMFit.load
(self, fit_npz, fit_obj)
Load the model from disk. Called from :func:`~loadClusterFit` Args: fit_npz (dict) Fit npz opened with :func:`numpy.load` fit_obj (sklearn.mixture.BayesianGaussianMixture) The saved fit object
Load the model from disk. Called from :func:`~loadClusterFit`
def load(self, fit_npz, fit_obj): '''Load the model from disk. Called from :func:`~loadClusterFit` Args: fit_npz (dict) Fit npz opened with :func:`numpy.load` fit_obj (sklearn.mixture.BayesianGaussianMixture) The saved fit object ''' ...
[ "def", "load", "(", "self", ",", "fit_npz", ",", "fit_obj", ")", ":", "self", ".", "dpgmm", "=", "fit_obj", "self", ".", "weights", "=", "fit_npz", "[", "'weights'", "]", "self", ".", "means", "=", "fit_npz", "[", "'means'", "]", "self", ".", "covari...
[ 359, 4 ]
[ 375, 26 ]
python
en
['en', 'en', 'en']
True
BGMMFit.plot
(self, X, y)
Extends :func:`~ClusterFit.plot` Write a summary of the fit, and plot the results using :func:`PopPUNK.plot.plot_results` and :func:`PopPUNK.plot.plot_contours` Args: X (numpy.array) Core and accessory distances y (numpy.array) Cluster as...
Extends :func:`~ClusterFit.plot`
def plot(self, X, y): '''Extends :func:`~ClusterFit.plot` Write a summary of the fit, and plot the results using :func:`PopPUNK.plot.plot_results` and :func:`PopPUNK.plot.plot_contours` Args: X (numpy.array) Core and accessory distances y (numpy....
[ "def", "plot", "(", "self", ",", "X", ",", "y", ")", ":", "ClusterFit", ".", "plot", "(", "self", ",", "X", ")", "# Generate a subsampling if one was not used in the fit", "if", "not", "hasattr", "(", "self", ",", "'subsampled_X'", ")", ":", "self", ".", "...
[ 378, 4 ]
[ 410, 85 ]
python
et
['et', 'fr', 'nl']
False
BGMMFit.assign
(self, X, values = False, progress=True)
Assign the clustering of new samples using :func:`~PopPUNK.bgmm.assign_samples` Args: X (numpy.array) Core and accessory distances values (bool) Return the responsibilities of assignment rather than most likely cluster num_processes (int) ...
Assign the clustering of new samples using :func:`~PopPUNK.bgmm.assign_samples`
def assign(self, X, values = False, progress=True): '''Assign the clustering of new samples using :func:`~PopPUNK.bgmm.assign_samples` Args: X (numpy.array) Core and accessory distances values (bool) Return the responsibilities of assignment rathe...
[ "def", "assign", "(", "self", ",", "X", ",", "values", "=", "False", ",", "progress", "=", "True", ")", ":", "if", "not", "self", ".", "fitted", ":", "raise", "RuntimeError", "(", "\"Trying to assign using an unfitted model\"", ")", "else", ":", "if", "pro...
[ 413, 4 ]
[ 466, 16 ]
python
en
['en', 'en', 'en']
True
DBSCANFit.fit
(self, X, max_num_clusters, min_cluster_prop)
Extends :func:`~ClusterFit.fit` Fits the distances with HDBSCAN and returns assignments by calling :func:`~PopPUNK.dbscan.fitDbScan`. Fitted parameters are stored in the object. Args: X (numpy.array) The core and accessory distances to cluster. Must be set ...
Extends :func:`~ClusterFit.fit`
def fit(self, X, max_num_clusters, min_cluster_prop): '''Extends :func:`~ClusterFit.fit` Fits the distances with HDBSCAN and returns assignments by calling :func:`~PopPUNK.dbscan.fitDbScan`. Fitted parameters are stored in the object. Args: X (numpy.array) ...
[ "def", "fit", "(", "self", ",", "X", ",", "max_num_clusters", ",", "min_cluster_prop", ")", ":", "ClusterFit", ".", "fit", "(", "self", ",", "X", ")", "# DBSCAN parameters", "cache_out", "=", "\"./\"", "+", "self", ".", "outPrefix", "+", "\"_cache\"", "min...
[ 491, 4 ]
[ 557, 16 ]
python
et
['et', 'fr', 'nl']
False
DBSCANFit.save
(self)
Save the model to disk, as an npz and pkl (using outPrefix).
Save the model to disk, as an npz and pkl (using outPrefix).
def save(self): '''Save the model to disk, as an npz and pkl (using outPrefix).''' if not self.fitted: raise RuntimeError("Trying to save unfitted model") else: np.savez(self.outPrefix + "/" + os.path.basename(self.outPrefix) + '_fit.npz', n_clusters=self.n_c...
[ "def", "save", "(", "self", ")", ":", "if", "not", "self", ".", "fitted", ":", "raise", "RuntimeError", "(", "\"Trying to save unfitted model\"", ")", "else", ":", "np", ".", "savez", "(", "self", ".", "outPrefix", "+", "\"/\"", "+", "os", ".", "path", ...
[ 560, 4 ]
[ 574, 63 ]
python
en
['en', 'en', 'en']
True
DBSCANFit.load
(self, fit_npz, fit_obj)
Load the model from disk. Called from :func:`~loadClusterFit` Args: fit_npz (dict) Fit npz opened with :func:`numpy.load` fit_obj (hdbscan.HDBSCAN) The saved fit object
Load the model from disk. Called from :func:`~loadClusterFit`
def load(self, fit_npz, fit_obj): '''Load the model from disk. Called from :func:`~loadClusterFit` Args: fit_npz (dict) Fit npz opened with :func:`numpy.load` fit_obj (hdbscan.HDBSCAN) The saved fit object ''' self.hdb = fit_obj ...
[ "def", "load", "(", "self", ",", "fit_npz", ",", "fit_obj", ")", ":", "self", ".", "hdb", "=", "fit_obj", "self", ".", "labels", "=", "self", ".", "hdb", ".", "labels_", "self", ".", "n_clusters", "=", "fit_npz", "[", "'n_clusters'", "]", "self", "."...
[ 577, 4 ]
[ 595, 26 ]
python
en
['en', 'en', 'en']
True
DBSCANFit.plot
(self, X=None, y=None)
Extends :func:`~ClusterFit.plot` Write a summary of the fit, and plot the results using :func:`PopPUNK.plot.plot_dbscan_results` Args: X (numpy.array) Core and accessory distances y (numpy.array) Cluster assignments from :func:`~BGMMFit.a...
Extends :func:`~ClusterFit.plot`
def plot(self, X=None, y=None): '''Extends :func:`~ClusterFit.plot` Write a summary of the fit, and plot the results using :func:`PopPUNK.plot.plot_dbscan_results` Args: X (numpy.array) Core and accessory distances y (numpy.array) ...
[ "def", "plot", "(", "self", ",", "X", "=", "None", ",", "y", "=", "None", ")", ":", "ClusterFit", ".", "plot", "(", "self", ",", "X", ")", "# Generate a subsampling if one was not used in the fit", "if", "not", "hasattr", "(", "self", ",", "'subsampled_X'", ...
[ 598, 4 ]
[ 628, 96 ]
python
et
['et', 'fr', 'nl']
False
DBSCANFit.assign
(self, X, no_scale = False, progress = True)
Assign the clustering of new samples using :func:`~PopPUNK.dbscan.assign_samples_dbscan` Args: X (numpy.array) Core and accessory distances no_scale (bool) Do not scale X [default = False] progress (bool) Show ...
Assign the clustering of new samples using :func:`~PopPUNK.dbscan.assign_samples_dbscan`
def assign(self, X, no_scale = False, progress = True): '''Assign the clustering of new samples using :func:`~PopPUNK.dbscan.assign_samples_dbscan` Args: X (numpy.array) Core and accessory distances no_scale (bool) Do not scale X ...
[ "def", "assign", "(", "self", ",", "X", ",", "no_scale", "=", "False", ",", "progress", "=", "True", ")", ":", "if", "not", "self", ".", "fitted", ":", "raise", "RuntimeError", "(", "\"Trying to assign using an unfitted model\"", ")", "else", ":", "if", "n...
[ 631, 4 ]
[ 688, 16 ]
python
en
['en', 'en', 'en']
True
RefineFit.fit
(self, X, sample_names, model, max_move, min_move, startFile = None, indiv_refine = False, unconstrained = False, score_idx = 0, no_local = False, betweenness_sample = betweenness_sample_default, use_gpu = False)
Extends :func:`~ClusterFit.fit` Fits the distances by optimising network score, by calling :func:`~PopPUNK.refine.refineFit2D`. Fitted parameters are stored in the object. Args: X (numpy.array) The core and accessory distances to cluster. Must be set if ...
Extends :func:`~ClusterFit.fit`
def fit(self, X, sample_names, model, max_move, min_move, startFile = None, indiv_refine = False, unconstrained = False, score_idx = 0, no_local = False, betweenness_sample = betweenness_sample_default, use_gpu = False): '''Extends :func:`~ClusterFit.fit` Fits the distances by o...
[ "def", "fit", "(", "self", ",", "X", ",", "sample_names", ",", "model", ",", "max_move", ",", "min_move", ",", "startFile", "=", "None", ",", "indiv_refine", "=", "False", ",", "unconstrained", "=", "False", ",", "score_idx", "=", "0", ",", "no_local", ...
[ 711, 4 ]
[ 834, 16 ]
python
et
['et', 'fr', 'nl']
False
RefineFit.apply_threshold
(self, X, threshold)
Applies a boundary threshold, given by user. Does not run optimisation. Args: X (numpy.array) The core and accessory distances to cluster. Must be set if preprocess is set. threshold (float) The value along the x-axis (core distanc...
Applies a boundary threshold, given by user. Does not run optimisation.
def apply_threshold(self, X, threshold): '''Applies a boundary threshold, given by user. Does not run optimisation. Args: X (numpy.array) The core and accessory distances to cluster. Must be set if preprocess is set. threshold (float) ...
[ "def", "apply_threshold", "(", "self", ",", "X", ",", "threshold", ")", ":", "self", ".", "scale", "=", "np", ".", "array", "(", "[", "1", ",", "1", "]", ",", "dtype", "=", "X", ".", "dtype", ")", "# Blank values to pass to plot", "self", ".", "mean0...
[ 836, 4 ]
[ 874, 16 ]
python
en
['en', 'en', 'en']
True
RefineFit.save
(self)
Save the model to disk, as an npz and pkl (using outPrefix).
Save the model to disk, as an npz and pkl (using outPrefix).
def save(self): '''Save the model to disk, as an npz and pkl (using outPrefix).''' if not self.fitted: raise RuntimeError("Trying to save unfitted model") else: np.savez(self.outPrefix + "/" + os.path.basename(self.outPrefix) + '_fit.npz', intercept=np.array(...
[ "def", "save", "(", "self", ")", ":", "if", "not", "self", ".", "fitted", ":", "raise", "RuntimeError", "(", "\"Trying to save unfitted model\"", ")", "else", ":", "np", ".", "savez", "(", "self", ".", "outPrefix", "+", "\"/\"", "+", "os", ".", "path", ...
[ 876, 4 ]
[ 887, 59 ]
python
en
['en', 'en', 'en']
True
RefineFit.load
(self, fit_npz, fit_obj)
Load the model from disk. Called from :func:`~loadClusterFit` Args: fit_npz (dict) Fit npz opened with :func:`numpy.load` fit_obj (None) The saved fit object (not used)
Load the model from disk. Called from :func:`~loadClusterFit`
def load(self, fit_npz, fit_obj): '''Load the model from disk. Called from :func:`~loadClusterFit` Args: fit_npz (dict) Fit npz opened with :func:`numpy.load` fit_obj (None) The saved fit object (not used) ''' self.optimal_x = fit_...
[ "def", "load", "(", "self", ",", "fit_npz", ",", "fit_obj", ")", ":", "self", ".", "optimal_x", "=", "fit_npz", "[", "'intercept'", "]", ".", "item", "(", "0", ")", "self", ".", "optimal_y", "=", "fit_npz", "[", "'intercept'", "]", ".", "item", "(", ...
[ 890, 4 ]
[ 916, 28 ]
python
en
['en', 'en', 'en']
True
RefineFit.plot
(self, X, y=None)
Extends :func:`~ClusterFit.plot` Write a summary of the fit, and plot the results using :func:`PopPUNK.plot.plot_refined_results` Args: X (numpy.array) Core and accessory distances y (numpy.array) Assignments (unused)
Extends :func:`~ClusterFit.plot`
def plot(self, X, y=None): '''Extends :func:`~ClusterFit.plot` Write a summary of the fit, and plot the results using :func:`PopPUNK.plot.plot_refined_results` Args: X (numpy.array) Core and accessory distances y (numpy.array) Ass...
[ "def", "plot", "(", "self", ",", "X", ",", "y", "=", "None", ")", ":", "ClusterFit", ".", "plot", "(", "self", ",", "X", ")", "# Subsamples huge plots to save on memory", "max_points", "=", "int", "(", "0.5", "*", "(", "5000", ")", "**", "2", ")", "i...
[ 918, 4 ]
[ 942, 109 ]
python
et
['et', 'fr', 'nl']
False
RefineFit.assign
(self, X, slope=None)
Assign the clustering of new samples Args: X (numpy.array) Core and accessory distances slope (int) Override self.slope. Default - use self.slope Set to 0 for a vertical line, 1 for a horizontal line, or 2 to use a slope ...
Assign the clustering of new samples
def assign(self, X, slope=None): '''Assign the clustering of new samples Args: X (numpy.array) Core and accessory distances slope (int) Override self.slope. Default - use self.slope Set to 0 for a vertical line, 1 for a horizontal ...
[ "def", "assign", "(", "self", ",", "X", ",", "slope", "=", "None", ")", ":", "if", "not", "self", ".", "fitted", ":", "raise", "RuntimeError", "(", "\"Trying to assign using an unfitted model\"", ")", "else", ":", "if", "slope", "==", "None", ":", "slope",...
[ 945, 4 ]
[ 971, 16 ]
python
en
['en', 'en', 'en']
True
LineageFit.__save_sparse__
(self, data, row, col, rank, n_samples, dtype)
Save a sparse matrix in coo format
Save a sparse matrix in coo format
def __save_sparse__(self, data, row, col, rank, n_samples, dtype): '''Save a sparse matrix in coo format ''' if self.use_gpu: data = cp.array(data) data[data < epsilon] = epsilon self.nn_dists[rank] = cupyx.scipy.sparse.coo_matrix((data, (cp.array(row), cp.array(col))), ...
[ "def", "__save_sparse__", "(", "self", ",", "data", ",", "row", ",", "col", ",", "rank", ",", "n_samples", ",", "dtype", ")", ":", "if", "self", ".", "use_gpu", ":", "data", "=", "cp", ".", "array", "(", "data", ")", "data", "[", "data", "<", "ep...
[ 1004, 4 ]
[ 1018, 60 ]
python
en
['en', 'en', 'it']
True
LineageFit.__reduce_rank__
(self, higher_rank_sparse_mat, lower_rank, n_samples, dtype)
Lowers the rank of a fit and saves it
Lowers the rank of a fit and saves it
def __reduce_rank__(self, higher_rank_sparse_mat, lower_rank, n_samples, dtype): '''Lowers the rank of a fit and saves it ''' lower_rank_sparse_mat = \ poppunk_refine.lowerRank( higher_rank_sparse_mat, n_samples, lower_rank) sel...
[ "def", "__reduce_rank__", "(", "self", ",", "higher_rank_sparse_mat", ",", "lower_rank", ",", "n_samples", ",", "dtype", ")", ":", "lower_rank_sparse_mat", "=", "poppunk_refine", ".", "lowerRank", "(", "higher_rank_sparse_mat", ",", "n_samples", ",", "lower_rank", "...
[ 1020, 4 ]
[ 1033, 35 ]
python
en
['en', 'en', 'en']
True
LineageFit.fit
(self, X, accessory)
Extends :func:`~ClusterFit.fit` Gets assignments by using nearest neigbours. Args: X (numpy.array) The core and accessory distances to cluster. Must be set if preprocess is set. accessory (bool) Use accessory rather than core dist...
Extends :func:`~ClusterFit.fit`
def fit(self, X, accessory): '''Extends :func:`~ClusterFit.fit` Gets assignments by using nearest neigbours. Args: X (numpy.array) The core and accessory distances to cluster. Must be set if preprocess is set. accessory (bool) ...
[ "def", "fit", "(", "self", ",", "X", ",", "accessory", ")", ":", "# Check if model requires GPU", "check_and_set_gpu", "(", "self", ".", "use_gpu", ",", "gpu_lib", ",", "quit_on_fail", "=", "True", ")", "ClusterFit", ".", "fit", "(", "self", ",", "X", ")",...
[ 1035, 4 ]
[ 1078, 16 ]
python
et
['et', 'fr', 'nl']
False
LineageFit.save
(self)
Save the model to disk, as an npz and pkl (using outPrefix).
Save the model to disk, as an npz and pkl (using outPrefix).
def save(self): '''Save the model to disk, as an npz and pkl (using outPrefix).''' if not self.fitted: raise RuntimeError("Trying to save unfitted model") else: for rank in self.ranks: scipy.sparse.save_npz( self.outPrefix + "/" + os.pa...
[ "def", "save", "(", "self", ")", ":", "if", "not", "self", ".", "fitted", ":", "raise", "RuntimeError", "(", "\"Trying to save unfitted model\"", ")", "else", ":", "for", "rank", "in", "self", ".", "ranks", ":", "scipy", ".", "sparse", ".", "save_npz", "...
[ 1080, 4 ]
[ 1092, 82 ]
python
en
['en', 'en', 'en']
True
LineageFit.load
(self, fit_npz, fit_obj)
Load the model from disk. Called from :func:`~loadClusterFit` Args: fit_npz (dict) Fit npz opened with :func:`numpy.load` fit_obj (sklearn.mixture.BayesianGaussianMixture) The saved fit object
Load the model from disk. Called from :func:`~loadClusterFit`
def load(self, fit_npz, fit_obj): '''Load the model from disk. Called from :func:`~loadClusterFit` Args: fit_npz (dict) Fit npz opened with :func:`numpy.load` fit_obj (sklearn.mixture.BayesianGaussianMixture) The saved fit object ''' ...
[ "def", "load", "(", "self", ",", "fit_npz", ",", "fit_obj", ")", ":", "self", ".", "ranks", ",", "self", ".", "dist_col", "=", "fit_obj", "self", ".", "nn_dists", "=", "fit_npz", "self", ".", "fitted", "=", "True" ]
[ 1094, 4 ]
[ 1105, 26 ]
python
en
['en', 'en', 'en']
True
LineageFit.plot
(self, X, y = None)
Extends :func:`~ClusterFit.plot` Write a summary of the fit, and plot the results using :func:`PopPUNK.plot.plot_results` and :func:`PopPUNK.plot.plot_contours` Args: X (numpy.array) Core and accessory distances y (any) Unused variable fo...
Extends :func:`~ClusterFit.plot`
def plot(self, X, y = None): '''Extends :func:`~ClusterFit.plot` Write a summary of the fit, and plot the results using :func:`PopPUNK.plot.plot_results` and :func:`PopPUNK.plot.plot_contours` Args: X (numpy.array) Core and accessory distances y ...
[ "def", "plot", "(", "self", ",", "X", ",", "y", "=", "None", ")", ":", "ClusterFit", ".", "plot", "(", "self", ",", "X", ")", "for", "rank", "in", "self", ".", "ranks", ":", "if", "self", ".", "use_gpu", ":", "hist_data", "=", "self", ".", "nn_...
[ 1107, 4 ]
[ 1128, 86 ]
python
et
['et', 'fr', 'nl']
False
LineageFit.assign
(self, rank)
Get the edges for the network. A little different from other methods, as it doesn't go through the long form distance vector (as coo_matrix is basically already in the correct gt format) Args: rank (int) Rank to assign at Returns: y (list of tuple...
Get the edges for the network. A little different from other methods, as it doesn't go through the long form distance vector (as coo_matrix is basically already in the correct gt format)
def assign(self, rank): '''Get the edges for the network. A little different from other methods, as it doesn't go through the long form distance vector (as coo_matrix is basically already in the correct gt format) Args: rank (int) Rank to assign at Re...
[ "def", "assign", "(", "self", ",", "rank", ")", ":", "if", "not", "self", ".", "fitted", ":", "raise", "RuntimeError", "(", "\"Trying to assign using an unfitted model\"", ")", "else", ":", "y", "=", "[", "]", "for", "row", ",", "col", "in", "zip", "(", ...
[ 1130, 4 ]
[ 1149, 16 ]
python
en
['en', 'en', 'en']
True
LineageFit.edge_weights
(self, rank)
Get the distances for each edge returned by assign Args: rank (int) Rank assigned at Returns: weights (list) Distance for each assignment
Get the distances for each edge returned by assign
def edge_weights(self, rank): '''Get the distances for each edge returned by assign Args: rank (int) Rank assigned at Returns: weights (list) Distance for each assignment ''' if not self.fitted: raise RuntimeErr...
[ "def", "edge_weights", "(", "self", ",", "rank", ")", ":", "if", "not", "self", ".", "fitted", ":", "raise", "RuntimeError", "(", "\"Trying to get weights from an unfitted model\"", ")", "else", ":", "return", "(", "self", ".", "nn_dists", "[", "rank", "]", ...
[ 1151, 4 ]
[ 1164, 45 ]
python
en
['en', 'en', 'en']
True
LineageFit.extend
(self, qqDists, qrDists)
Update the sparse distance matrix of nearest neighbours after querying Args: qqDists (numpy or cupy ndarray) Two column array of query-query distances qqDists (numpy or cupy ndarray) Two column array of reference-query distances Returns: ...
Update the sparse distance matrix of nearest neighbours after querying
def extend(self, qqDists, qrDists): '''Update the sparse distance matrix of nearest neighbours after querying Args: qqDists (numpy or cupy ndarray) Two column array of query-query distances qqDists (numpy or cupy ndarray) Two column array of refer...
[ "def", "extend", "(", "self", ",", "qqDists", ",", "qrDists", ")", ":", "# Check if model requires GPU", "check_and_set_gpu", "(", "self", ".", "use_gpu", ",", "gpu_lib", ",", "quit_on_fail", "=", "True", ")", "# Convert data structures if using GPU", "if", "self", ...
[ 1166, 4 ]
[ 1218, 16 ]
python
en
['en', 'en', 'en']
True
_set_seed
(self, seed)
set the seed we call both ``torch.manual_seed()`` and ``np.random.seed()`` we also set the ``self.seed`` attribute Parameters ---------- seed : int the seed to set
set the seed
def _set_seed(self, seed): """set the seed we call both ``torch.manual_seed()`` and ``np.random.seed()`` we also set the ``self.seed`` attribute Parameters ---------- seed : int the seed to set """ self.seed = seed if seed is not Non...
[ "def", "_set_seed", "(", "self", ",", "seed", ")", ":", "self", ".", "seed", "=", "seed", "if", "seed", "is", "not", "None", ":", "# random initialization", "torch", ".", "manual_seed", "(", "seed", ")", "np", ".", "random", ".", "seed", "(", "seed", ...
[ 112, 4 ]
[ 128, 32 ]
python
en
['en', 'en', 'en']
True
_init_synthesized_signal
(self, synthesized_signal_data, clamper=RangeClamper((0, 1)), clamp_each_iter=True)
initialize the synthesized image set the ``self.synthesized_signal`` attribute to be a parameter with the user-supplied data, making sure it's the right shape and calling clamper on it, if set also initialize the ``self.synthesized_representation`` attribute Parameters ...
initialize the synthesized image
def _init_synthesized_signal(self, synthesized_signal_data, clamper=RangeClamper((0, 1)), clamp_each_iter=True): """initialize the synthesized image set the ``self.synthesized_signal`` attribute to be a parameter with the user-supplied data, making sure it's the...
[ "def", "_init_synthesized_signal", "(", "self", ",", "synthesized_signal_data", ",", "clamper", "=", "RangeClamper", "(", "(", "0", ",", "1", ")", ")", ",", "clamp_each_iter", "=", "True", ")", ":", "self", ".", "synthesized_signal", "=", "torch", ".", "nn",...
[ 130, 4 ]
[ 159, 46 ]
python
en
['en', 'zu', 'en']
True
_init_ctf_and_randomizer
(self, loss_thresh=1e-4, fraction_removed=0, coarse_to_fine=False, loss_change_fraction=1, loss_change_thresh=1e-2, loss_change_iter=50)
initialize stuff related to randomization and coarse-to-fine Parameters ---------- loss_thresh : float, optional If the loss over the past ``loss_change_iter`` is less than ``loss_thresh``, we stop. fraction_removed: float, optional The fraction of th...
initialize stuff related to randomization and coarse-to-fine
def _init_ctf_and_randomizer(self, loss_thresh=1e-4, fraction_removed=0, coarse_to_fine=False, loss_change_fraction=1, loss_change_thresh=1e-2, loss_change_iter=50): """initialize stuff related to randomization and coarse-to-fine Paramet...
[ "def", "_init_ctf_and_randomizer", "(", "self", ",", "loss_thresh", "=", "1e-4", ",", "fraction_removed", "=", "0", ",", "coarse_to_fine", "=", "False", ",", "loss_change_fraction", "=", "1", ",", "loss_change_thresh", "=", "1e-2", ",", "loss_change_iter", "=", ...
[ 161, 4 ]
[ 237, 42 ]
python
en
['en', 'en', 'en']
True
_init_store_progress
(self, store_progress, save_progress, save_path)
initialize store_progress-related attributes sets the ``self.save_progress``, ``self.store_progress``, and ``self.save_path`` attributes, as well as changing ``saved_signal, saved_representation, saved_signal_gradient, saved_representation_gradient`` attibutes all to lists so we can ...
initialize store_progress-related attributes
def _init_store_progress(self, store_progress, save_progress, save_path): """initialize store_progress-related attributes sets the ``self.save_progress``, ``self.store_progress``, and ``self.save_path`` attributes, as well as changing ``saved_signal, saved_representation, saved_signal_g...
[ "def", "_init_store_progress", "(", "self", ",", "store_progress", ",", "save_progress", ",", "save_path", ")", ":", "# python's implicit boolean-ness means we can do this! it will evaluate to False for False", "# and 0, and True for True and every int >= 1", "if", "store_progress", ...
[ 239, 4 ]
[ 314, 34 ]
python
en
['en', 'en', 'en']
True
_check_nan_loss
(self, loss)
check if loss is nan and, if so, return True This checks if loss is NaN and, if so, updates synthesized_signal/representation to be several iterations ago (so they're meaningful) and then returns True Parameters ---------- loss : torch.Tensor the loss from t...
check if loss is nan and, if so, return True
def _check_nan_loss(self, loss): """check if loss is nan and, if so, return True This checks if loss is NaN and, if so, updates synthesized_signal/representation to be several iterations ago (so they're meaningful) and then returns True Parameters ---------- los...
[ "def", "_check_nan_loss", "(", "self", ",", "loss", ")", ":", "if", "np", ".", "isnan", "(", "loss", ".", "item", "(", ")", ")", ":", "warnings", ".", "warn", "(", "\"Loss is NaN, quitting out! We revert synthesized_signal / synthesized_\"", "\"representation to our...
[ 316, 4 ]
[ 351, 20 ]
python
en
['en', 'en', 'en']
True
_clamp_and_store
(self, i)
clamp synthesized_signal and store/save, if appropriate these all happen together because they all happen ``with torch.no_grad()`` if it's the right iteration, we update: ``saved_signal, saved_representation, saved_signal_gradient, saved_representation_gradient`` Param...
clamp synthesized_signal and store/save, if appropriate
def _clamp_and_store(self, i): """clamp synthesized_signal and store/save, if appropriate these all happen together because they all happen ``with torch.no_grad()`` if it's the right iteration, we update: ``saved_signal, saved_representation, saved_signal_gradient, save...
[ "def", "_clamp_and_store", "(", "self", ",", "i", ")", ":", "stored", "=", "False", "with", "torch", ".", "no_grad", "(", ")", ":", "if", "self", ".", "clamper", "is", "not", "None", "and", "self", ".", "clamp_each_iter", ":", "self", ".", "synthesized...
[ 353, 4 ]
[ 402, 21 ]
python
en
['en', 'en', 'en']
True
_check_for_stabilization
(self, i)
r"""Check whether the loss has stabilized and, if so, return True We check whether the loss has stopped decreasing and return True if so. We rely on a handful of attributes to do this, and take the following steps: 1. Check if we've been synthesizing for at least ``...
r"""Check whether the loss has stabilized and, if so, return True
def _check_for_stabilization(self, i): r"""Check whether the loss has stabilized and, if so, return True We check whether the loss has stopped decreasing and return True if so. We rely on a handful of attributes to do this, and take the following steps: 1. Check if we'...
[ "def", "_check_for_stabilization", "(", "self", ",", "i", ")", ":", "if", "len", "(", "self", ".", "loss", ")", ">", "self", ".", "loss_change_iter", ":", "if", "abs", "(", "self", ".", "loss", "[", "-", "self", ".", "loss_change_iter", "]", "-", "se...
[ 404, 4 ]
[ 450, 20 ]
python
en
['en', 'en', 'en']
True
_finalize_stored_progress
(self)
stack the saved_* attributes if we were storing progress, stack the ``saved_representation, saved_signal, saved_signal_gradient, saved_representation_gradient`` attributes so they're a single tensor we can't stack the gradients if we used coarse-to-fine optimization, be...
stack the saved_* attributes
def _finalize_stored_progress(self): """stack the saved_* attributes if we were storing progress, stack the ``saved_representation, saved_signal, saved_signal_gradient, saved_representation_gradient`` attributes so they're a single tensor we can't stack the gradients if...
[ "def", "_finalize_stored_progress", "(", "self", ")", ":", "if", "self", ".", "clamper", "is", "not", "None", ":", "try", ":", "# setting the data directly avoids the issue of setting", "# a non-Parameter tensor where a tensor should be", "self", ".", "synthesized_signal", ...
[ 452, 4 ]
[ 492, 20 ]
python
en
['en', 'en', 'en']
True
synthesize
(self, seed=0, max_iter=100, learning_rate=1, scheduler=True, optimizer='Adam', optimizer_kwargs={}, swa=False, swa_kwargs={}, clamper=RangeClamper((0, 1)), clamp_each_iter=True, store_progress=False, save_progress=False, save_path='synthesis.pt', loss_thresh=1e-...
r"""synthesize an image this is a skeleton of how synthesize() works, just to serve as a guide -- YOU SHOULD NOT CALL THIS FUNCTION. You should, however, copy the call signature and then add any extra arguments specific to the given synthesis method at the beginning FO...
r"""synthesize an image
def synthesize(self, seed=0, max_iter=100, learning_rate=1, scheduler=True, optimizer='Adam', optimizer_kwargs={}, swa=False, swa_kwargs={}, clamper=RangeClamper((0, 1)), clamp_each_iter=True, store_progress=False, save_progress=False, save_path='synthesis.pt', l...
[ "def", "synthesize", "(", "self", ",", "seed", "=", "0", ",", "max_iter", "=", "100", ",", "learning_rate", "=", "1", ",", "scheduler", "=", "True", ",", "optimizer", "=", "'Adam'", ",", "optimizer_kwargs", "=", "{", "}", ",", "swa", "=", "False", ",...
[ 495, 4 ]
[ 653, 81 ]
python
en
['en', 'en', 'tr']
True
analyze
(self, x, **kwargs)
r"""Analyze the image, that is, obtain the model's representation of it Any kwargs are passed to the model's forward method Parameters ---------- x : torch.Tensor The image to analyze Returns ------- y : torch.Tensor The model's represen...
r"""Analyze the image, that is, obtain the model's representation of it
def analyze(self, x, **kwargs): r"""Analyze the image, that is, obtain the model's representation of it Any kwargs are passed to the model's forward method Parameters ---------- x : torch.Tensor The image to analyze Returns ------- y : torch...
[ "def", "analyze", "(", "self", ",", "x", ",", "*", "*", "kwargs", ")", ":", "y", "=", "self", ".", "model", "(", "x", ",", "*", "*", "kwargs", ")", "if", "isinstance", "(", "y", ",", "list", ")", ":", "return", "torch", ".", "cat", "(", "[", ...
[ 655, 4 ]
[ 674, 20 ]
python
en
['en', 'en', 'en']
True
objective_function
(self, synth_rep, ref_rep, synth_img, ref_img)
r"""Calculate the loss This is what we minimize. We call ``self.loss_function(ref_rep=ref_rep, synth_rep=synth_rep, ref_img=ref_img, synth_img=synth_img)`` -- by default, this is the L2-norm of the difference between the two representations: ``torch.norm(ref_rep - synth_rep, p=2...
r"""Calculate the loss
def objective_function(self, synth_rep, ref_rep, synth_img, ref_img): r"""Calculate the loss This is what we minimize. We call ``self.loss_function(ref_rep=ref_rep, synth_rep=synth_rep, ref_img=ref_img, synth_img=synth_img)`` -- by default, this is the L2-norm of the difference ...
[ "def", "objective_function", "(", "self", ",", "synth_rep", ",", "ref_rep", ",", "synth_img", ",", "ref_img", ")", ":", "return", "self", ".", "loss_function", "(", "ref_rep", "=", "ref_rep", ",", "synth_rep", "=", "synth_rep", ",", "ref_img", "=", "ref_img"...
[ 676, 4 ]
[ 709, 54 ]
python
en
['en', 'en', 'en']
True
representation_error
(self, iteration=None, **kwargs)
r"""Get the representation error This is (synthesized_representation - base_representation). If ``iteration`` is not None, we use ``self.saved_representation[iteration]`` for synthesized_representation Any kwargs are passed through to self.analyze when computing the syn...
r"""Get the representation error
def representation_error(self, iteration=None, **kwargs): r"""Get the representation error This is (synthesized_representation - base_representation). If ``iteration`` is not None, we use ``self.saved_representation[iteration]`` for synthesized_representation Any kwargs...
[ "def", "representation_error", "(", "self", ",", "iteration", "=", "None", ",", "*", "*", "kwargs", ")", ":", "if", "self", ".", "_rep_warning", ":", "warnings", ".", "warn", "(", "\"Since at least one of your models is a metric, its representation_error\"", "\" will ...
[ 711, 4 ]
[ 751, 24 ]
python
en
['en', 'pt', 'en']
True