hexsha
string
size
int64
ext
string
lang
string
max_stars_repo_path
string
max_stars_repo_name
string
max_stars_repo_head_hexsha
string
max_stars_repo_licenses
list
max_stars_count
int64
max_stars_repo_stars_event_min_datetime
string
max_stars_repo_stars_event_max_datetime
string
max_issues_repo_path
string
max_issues_repo_name
string
max_issues_repo_head_hexsha
string
max_issues_repo_licenses
list
max_issues_count
int64
max_issues_repo_issues_event_min_datetime
string
max_issues_repo_issues_event_max_datetime
string
max_forks_repo_path
string
max_forks_repo_name
string
max_forks_repo_head_hexsha
string
max_forks_repo_licenses
list
max_forks_count
int64
max_forks_repo_forks_event_min_datetime
string
max_forks_repo_forks_event_max_datetime
string
content
string
avg_line_length
float64
max_line_length
int64
alphanum_fraction
float64
qsc_code_num_words_quality_signal
int64
qsc_code_num_chars_quality_signal
float64
qsc_code_mean_word_length_quality_signal
float64
qsc_code_frac_words_unique_quality_signal
float64
qsc_code_frac_chars_top_2grams_quality_signal
float64
qsc_code_frac_chars_top_3grams_quality_signal
float64
qsc_code_frac_chars_top_4grams_quality_signal
float64
qsc_code_frac_chars_dupe_5grams_quality_signal
float64
qsc_code_frac_chars_dupe_6grams_quality_signal
float64
qsc_code_frac_chars_dupe_7grams_quality_signal
float64
qsc_code_frac_chars_dupe_8grams_quality_signal
float64
qsc_code_frac_chars_dupe_9grams_quality_signal
float64
qsc_code_frac_chars_dupe_10grams_quality_signal
float64
qsc_code_frac_chars_replacement_symbols_quality_signal
float64
qsc_code_frac_chars_digital_quality_signal
float64
qsc_code_frac_chars_whitespace_quality_signal
float64
qsc_code_size_file_byte_quality_signal
float64
qsc_code_num_lines_quality_signal
float64
qsc_code_num_chars_line_max_quality_signal
float64
qsc_code_num_chars_line_mean_quality_signal
float64
qsc_code_frac_chars_alphabet_quality_signal
float64
qsc_code_frac_chars_comments_quality_signal
float64
qsc_code_cate_xml_start_quality_signal
float64
qsc_code_frac_lines_dupe_lines_quality_signal
float64
qsc_code_cate_autogen_quality_signal
float64
qsc_code_frac_lines_long_string_quality_signal
float64
qsc_code_frac_chars_string_length_quality_signal
float64
qsc_code_frac_chars_long_word_length_quality_signal
float64
qsc_code_frac_lines_string_concat_quality_signal
float64
qsc_code_cate_encoded_data_quality_signal
float64
qsc_code_frac_chars_hex_words_quality_signal
float64
qsc_code_frac_lines_prompt_comments_quality_signal
float64
qsc_code_frac_lines_assert_quality_signal
float64
qsc_codepython_cate_ast_quality_signal
float64
qsc_codepython_frac_lines_func_ratio_quality_signal
float64
qsc_codepython_cate_var_zero_quality_signal
bool
qsc_codepython_frac_lines_pass_quality_signal
float64
qsc_codepython_frac_lines_import_quality_signal
float64
qsc_codepython_frac_lines_simplefunc_quality_signal
float64
qsc_codepython_score_lines_no_logic_quality_signal
float64
qsc_codepython_frac_lines_print_quality_signal
float64
qsc_code_num_words
int64
qsc_code_num_chars
int64
qsc_code_mean_word_length
int64
qsc_code_frac_words_unique
null
qsc_code_frac_chars_top_2grams
int64
qsc_code_frac_chars_top_3grams
int64
qsc_code_frac_chars_top_4grams
int64
qsc_code_frac_chars_dupe_5grams
int64
qsc_code_frac_chars_dupe_6grams
int64
qsc_code_frac_chars_dupe_7grams
int64
qsc_code_frac_chars_dupe_8grams
int64
qsc_code_frac_chars_dupe_9grams
int64
qsc_code_frac_chars_dupe_10grams
int64
qsc_code_frac_chars_replacement_symbols
int64
qsc_code_frac_chars_digital
int64
qsc_code_frac_chars_whitespace
int64
qsc_code_size_file_byte
int64
qsc_code_num_lines
int64
qsc_code_num_chars_line_max
int64
qsc_code_num_chars_line_mean
int64
qsc_code_frac_chars_alphabet
int64
qsc_code_frac_chars_comments
int64
qsc_code_cate_xml_start
int64
qsc_code_frac_lines_dupe_lines
int64
qsc_code_cate_autogen
int64
qsc_code_frac_lines_long_string
int64
qsc_code_frac_chars_string_length
int64
qsc_code_frac_chars_long_word_length
int64
qsc_code_frac_lines_string_concat
null
qsc_code_cate_encoded_data
int64
qsc_code_frac_chars_hex_words
int64
qsc_code_frac_lines_prompt_comments
int64
qsc_code_frac_lines_assert
int64
qsc_codepython_cate_ast
int64
qsc_codepython_frac_lines_func_ratio
int64
qsc_codepython_cate_var_zero
int64
qsc_codepython_frac_lines_pass
int64
qsc_codepython_frac_lines_import
int64
qsc_codepython_frac_lines_simplefunc
int64
qsc_codepython_score_lines_no_logic
int64
qsc_codepython_frac_lines_print
int64
effective
string
hits
int64
a75bb275df734d4442fca2908582d64ffb3a5834
17
py
Python
testfile.py
jordanwimb/kbpython
01620098fb17df6b2b3b31a2c1b0b645df3a3e0a
[ "MIT" ]
null
null
null
testfile.py
jordanwimb/kbpython
01620098fb17df6b2b3b31a2c1b0b645df3a3e0a
[ "MIT" ]
null
null
null
testfile.py
jordanwimb/kbpython
01620098fb17df6b2b3b31a2c1b0b645df3a3e0a
[ "MIT" ]
null
null
null
print("Hellllo")
8.5
16
0.705882
2
17
6
1
0
0
0
0
0
0
0
0
0
0
0
0.058824
17
1
17
17
0.75
0
0
0
0
0
0.411765
0
0
0
0
0
0
1
0
true
0
0
0
0
1
1
1
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
1
0
0
0
0
1
0
5
a761cf5cd7b89bd8d37c30920e72b949ba856ea6
89,290
py
Python
tests/test_binary_quadratic_model.py
xpin/dimod
5e399317b0bfaae6ed20e22b9f2ef242f5fa5e6c
[ "Apache-2.0" ]
1
2019-07-12T18:43:48.000Z
2019-07-12T18:43:48.000Z
tests/test_binary_quadratic_model.py
xpin/dimod
5e399317b0bfaae6ed20e22b9f2ef242f5fa5e6c
[ "Apache-2.0" ]
null
null
null
tests/test_binary_quadratic_model.py
xpin/dimod
5e399317b0bfaae6ed20e22b9f2ef242f5fa5e6c
[ "Apache-2.0" ]
null
null
null
# Copyright 2018 D-Wave Systems Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # ================================================================================================ import collections import fractions import itertools import json import pickle import random import shutil import tempfile import unittest from os import path import numpy as np import dimod from dimod.exceptions import WriteableError from dimod.binary_quadratic_model import LockableDict try: import networkx as nx _networkx = True except ImportError: _networkx = False try: import pandas as pd _pandas = True except ImportError: _pandas = False class TestLockableDict(unittest.TestCase): def test__setitem__(self): d = LockableDict({'a': -1}) d.is_writeable = False with self.assertRaises(WriteableError): d['a'] = 5 def test__delitem__(self): d = LockableDict({'a': -1}) d.is_writeable = False with self.assertRaises(WriteableError): del d['a'] def test_clear(self): d = LockableDict({'a': -1}) d.is_writeable = False with self.assertRaises(WriteableError): d.clear() d.is_writeable = True d.clear() self.assertEqual(d, {}) def test_pop(self): d = LockableDict({'a': -1}) d.is_writeable = False with self.assertRaises(WriteableError): d.pop('a') def test_popitem(self): d = LockableDict({'a': -1, 'b': 2}) d.popitem() self.assertEqual(len(d), 1) d.is_writeable = False with self.assertRaises(WriteableError): d.popitem() def test_setdefault(self): d = LockableDict() d.setdefault('a') d.setdefault('b', 5) self.assertEqual(d, {'a': None, 'b': 5}) d.is_writeable = False with self.assertRaises(WriteableError): d.setdefault('c', None) def test_update(self): d = LockableDict() # check that it works normally d.update({'a': 1}) self.assertEqual(d, {'a': 1}) d.is_writeable = False with self.assertRaises(WriteableError): d.update({'b': -1}) class TestBinaryQuadraticModel(unittest.TestCase): def assertConsistentBQM(self, bqm): # adjacency and linear are self-consistent for v in bqm.linear: self.assertIn(v, bqm.adj) for v in bqm.adj: self.assertIn(v, bqm.linear) # adjacency and quadratic are self-consistent for u, v in bqm.quadratic: self.assertIn(v, bqm.linear) self.assertIn(v, bqm.adj) self.assertIn(u, bqm.adj[v]) self.assertIn(u, bqm.linear) self.assertIn(u, bqm.adj) self.assertIn(v, bqm.adj[u]) self.assertEqual(bqm.adj[u][v], bqm.quadratic[(u, v)]) self.assertEqual(bqm.adj[v][u], bqm.adj[u][v]) # self.assertNotIn((v, u), bqm.quadratic) for u in bqm.adj: for v in bqm.adj[u]: self.assertTrue((u, v) in bqm.quadratic and (v, u) in bqm.quadratic) # self.assertFalse((u, v) in bqm.quadratic and (v, u) in bqm.quadratic) self.assertEqual(len(bqm.quadratic), len(set(bqm.quadratic))) self.assertEqual(len(bqm.variables), len(bqm.linear)) def test_construction(self): # spin model linear = {0: 1, 1: -1, 2: .5} quadratic = {(0, 1): .5, (1, 2): 1.5} offset = 1.4 vartype = dimod.SPIN bqm = dimod.BinaryQuadraticModel(linear, quadratic, offset, vartype) self.assertConsistentBQM(bqm) for v, bias in linear.items(): self.assertEqual(bqm.linear[v], bias) for v in bqm.linear: self.assertIn(v, linear) for (u, v), bias in quadratic.items(): self.assertEqual(bqm.adj[u][v], bias) for interaction in bqm.quadratic: self.assertIn(interaction, quadratic) self.assertEqual(bqm.offset, offset) # # binary model linear = {0: 1, 1: -1, 2: .5} quadratic = {(0, 1): .5, (1, 2): 1.5} offset = 1.4 vartype = dimod.BINARY bqm = dimod.BinaryQuadraticModel(linear, quadratic, offset, vartype) self.assertConsistentBQM(bqm) for v, bias in linear.items(): self.assertEqual(bqm.linear[v], bias) for v in bqm.linear: self.assertIn(v, linear) for (u, v), bias in quadratic.items(): self.assertEqual(bqm.adj[u][v], bias) for interaction in bqm.quadratic: self.assertIn(interaction, quadratic) self.assertEqual(bqm.offset, offset) def test_construction_vartype(self): """Check that exceptions get thrown for broken inputs""" # this biases values are themselves not important, so just choose them randomly linear = {v: v * .01 for v in range(10)} quadratic = {(u, v): u * v * .01 for u, v in itertools.combinations(linear, 2)} offset = 1.2 with self.assertRaises(TypeError): dimod.BinaryQuadraticModel(linear, quadratic, offset, 147) with self.assertRaises(TypeError): dimod.BinaryQuadraticModel(linear, quadratic, offset, 'my made up type') self.assertEqual(dimod.BinaryQuadraticModel(linear, quadratic, offset, dimod.BINARY).vartype, dimod.BINARY) self.assertEqual(dimod.BinaryQuadraticModel(linear, quadratic, offset, {-1, 1}).vartype, dimod.SPIN) self.assertEqual(dimod.BinaryQuadraticModel(linear, quadratic, offset, 'BINARY').vartype, dimod.BINARY) def test_construction_quadratic(self): linear = {v: v * .01 for v in range(10)} quadratic = {(u, v): u * v * .01 for u, v in itertools.combinations(linear, 2)} offset = 1.2 vartype = dimod.SPIN self.assertEqual(dimod.BinaryQuadraticModel(linear, quadratic, offset, dimod.BINARY).quadratic, quadratic) # quadratic should be a dict or an iterable of 3-tuples with self.assertRaises(ValueError): dimod.BinaryQuadraticModel(linear, ['a'], offset, dimod.BINARY) with self.assertRaises(TypeError): dimod.BinaryQuadraticModel(linear, 1, offset, dimod.BINARY) # not 2-tuple with self.assertRaises(ValueError): dimod.BinaryQuadraticModel(linear, {'edge': .5}, offset, dimod.BINARY) # no self-loops with self.assertRaises(ValueError): dimod.BinaryQuadraticModel(linear, {(0, 0): .5}, offset, dimod.BINARY) def test__eq__(self): linear = {v: v * -.13 for v in range(10)} quadratic = {(u, v): u * v * .021 for u, v in itertools.combinations(linear, 2)} offset = 1.2 vartype = dimod.BINARY self.assertEqual(dimod.BinaryQuadraticModel(linear, quadratic, offset, vartype), dimod.BinaryQuadraticModel(linear, quadratic, offset, vartype)) # mismatched type self.assertNotEqual(dimod.BinaryQuadraticModel(linear, quadratic, offset, vartype), -1) # models of different type self.assertNotEqual(dimod.BinaryQuadraticModel({}, {}, 0.0, dimod.SPIN), dimod.BinaryQuadraticModel({}, {}, 0.0, dimod.BINARY)) # linear = {v: v * -.13 for v in range(10)} quadratic = {(u, v): u * v * .021 for u, v in itertools.combinations(linear, 2)} offset = -1.2 vartype = dimod.SPIN bqm = dimod.BinaryQuadraticModel(linear, quadratic, offset, vartype) reversed_quadratic = {(v, u): bias for (u, v), bias in quadratic.items()} reversed_bqm = dimod.BinaryQuadraticModel(linear, reversed_quadratic, offset, vartype) self.assertEqual(bqm, reversed_bqm) def test__repr__(self): bqm = dimod.BinaryQuadraticModel({0: 1, 1: -1}, {(0, 1): .5, (1, 2): 1.5}, 1.4, dimod.SPIN) # should recreate the model from dimod import BinaryQuadraticModel, Vartype new_bqm = eval(bqm.__repr__()) self.assertEqual(bqm, new_bqm) def test__len__(self): linear = {v: v * -.13 for v in range(10)} quadratic = {} offset = -1.2 vartype = dimod.SPIN bqm = dimod.BinaryQuadraticModel(linear, quadratic, offset, vartype) self.assertEqual(len(bqm), len(linear)) def test__contains__(self): bqm = dimod.BinaryQuadraticModel({'a': -1}, {}, 0.0, dimod.SPIN) self.assertIn('a', bqm) self.assertNotIn('b', bqm) bqm.add_interaction('a', 'b', .5) self.assertIn('b', bqm) def test__iter__(self): bqm = dimod.BinaryQuadraticModel.empty(dimod.BINARY) self.assertEqual(set(bqm), set()) bqm.add_interaction('a', 'b', -1) self.assertEqual(set(bqm), {'a', 'b'}) def test_variables(self): bqm = dimod.BinaryQuadraticModel.empty(dimod.BINARY) self.assertEqual(set(bqm.variables), set()) bqm.add_interaction('a', 'b', -1) self.assertEqual(set(bqm.variables), {'a', 'b'}) self.assertIn('a', bqm.variables) self.assertEqual(bqm.variables & {'b'}, {'b'}) self.assertEqual(bqm.variables | {'c'}, {'a', 'b', 'c'}) def test_add_variable(self): bqm = dimod.BinaryQuadraticModel({}, {('a', 'b'): -1}, 0.0, dimod.SPIN) bqm.add_variable('a', .5) self.assertEqual(bqm.linear['a'], .5) # add a single variable of a different type bqm = dimod.BinaryQuadraticModel({}, {('a', 'b'): -1}, 0.0, dimod.SPIN) bqm.add_variable('a', .5, vartype=dimod.BINARY) self.assertEqual(bqm.energy({'a': -1, 'b': -1}), -1) self.assertEqual(bqm.energy({'a': 1, 'b': 1}), -.5) # and again bqm = dimod.BinaryQuadraticModel({}, {('a', 'b'): -1}, 0.0, dimod.BINARY) bqm.add_variable('a', .4, vartype=dimod.SPIN) self.assertEqual(bqm.energy({'a': 0, 'b': 0}), -.4) self.assertEqual(bqm.energy({'a': 1, 'b': 1}), -.6) # add a new variable bqm = dimod.BinaryQuadraticModel({}, {('a', 'b'): -1}, 0.0, dimod.SPIN) bqm.add_variable('c', .5) self.assertEqual({'a': 0, 'b': 0, 'c': .5}, bqm.linear) bqm.add_variable('c', .5) self.assertEqual({'a': 0, 'b': 0, 'c': 1}, bqm.linear) # bad type with self.assertRaises(ValueError): bqm.add_variable('a', 1.2, -1) def test_add_variable_counterpart(self): # spin bqm = dimod.BinaryQuadraticModel({}, {('a', 'b'): -1}, 0.0, dimod.SPIN) bqm.add_variable('a', .5) for av, bv in itertools.product((0, 1), repeat=2): self.assertEqual(bqm.energy({'a': 2 * av - 1, 'b': 2 * bv - 1}), bqm.binary.energy({'a': av, 'b': bv})) # # spin bqm = dimod.BinaryQuadraticModel({}, {('a', 'b'): -1}, 0.0, dimod.SPIN) __ = bqm.binary # create counterpart bqm.add_variable('a', .5) for av, bv in itertools.product((0, 1), repeat=2): self.assertEqual(bqm.energy({'a': 2 * av - 1, 'b': 2 * bv - 1}), bqm.binary.energy({'a': av, 'b': bv})) # # binary bqm = dimod.BinaryQuadraticModel({}, {('a', 'b'): -1}, 0.0, dimod.BINARY) bqm.add_variable('a', .5) for av, bv in itertools.product((0, 1), repeat=2): self.assertEqual(bqm.spin.energy({'a': 2 * av - 1, 'b': 2 * bv - 1}), bqm.energy({'a': av, 'b': bv})) # # binary bqm = dimod.BinaryQuadraticModel({}, {('a', 'b'): -1}, 0.0, dimod.BINARY) __ = bqm.spin # create counterpart bqm.add_variable('a', .5) for av, bv in itertools.product((0, 1), repeat=2): self.assertEqual(bqm.spin.energy({'a': 2 * av - 1, 'b': 2 * bv - 1}), bqm.energy({'a': av, 'b': bv})) # bqm = dimod.BinaryQuadraticModel({'a': 1.}, {}, 0, dimod.SPIN) self.assertEqual(bqm.energy({'a': -1}), bqm.binary.energy({'a': 0})) bqm.add_variables_from({'a': .5, 'b': -2}) self.assertEqual(bqm.linear, {'a': 1.5, 'b': -2}) self.assertEqual(bqm.energy({'a': -1, 'b': -1}), bqm.binary.energy({'a': 0, 'b': 0})) self.assertEqual(bqm.energy({'a': +1, 'b': -1}), bqm.binary.energy({'a': 1, 'b': 0})) self.assertEqual(bqm.energy({'a': -1, 'b': +1}), bqm.binary.energy({'a': 0, 'b': 1})) self.assertEqual(bqm.energy({'a': +1, 'b': +1}), bqm.binary.energy({'a': 1, 'b': 1})) def test_add_variables_from(self): linear = {'a': .5, 'b': -.5} offset = 0.0 vartype = dimod.SPIN # create an empty model then add linear bqm = dimod.BinaryQuadraticModel({}, {}, 0.0, vartype) bqm.add_variables_from(linear) self.assertEqual(bqm, dimod.BinaryQuadraticModel(linear, {}, 0.0, vartype)) # add from 2-tuples bqm = dimod.BinaryQuadraticModel({}, {}, 0.0, vartype) bqm.add_variables_from((key, value) for key, value in linear.items()) self.assertEqual(bqm, dimod.BinaryQuadraticModel(linear, {}, 0.0, vartype)) with self.assertRaises(TypeError): bqm.add_variables_from(1) def test_add_interaction(self): # spin-to-binary bqm = dimod.BinaryQuadraticModel({'a': 0, 'b': 0}, {}, 0.0, dimod.BINARY) bqm.add_interaction('a', 'b', -1, vartype=dimod.SPIN) # add a chain link self.assertEqual(bqm.energy({'a': 0, 'b': 0}), -1) self.assertEqual(bqm.energy({'a': 1, 'b': 1}), -1) self.assertConsistentBQM(bqm) bqm = dimod.BinaryQuadraticModel({'b': 0}, {}, 0.0, dimod.BINARY) bqm.add_interaction('a', 'b', -1, vartype=dimod.SPIN) # add a chain link self.assertEqual(bqm.energy({'a': 0, 'b': 0}), -1) self.assertEqual(bqm.energy({'a': 1, 'b': 1}), -1) self.assertConsistentBQM(bqm) bqm = dimod.BinaryQuadraticModel({'a': 0}, {}, 0.0, dimod.BINARY) bqm.add_interaction('a', 'b', -1, vartype=dimod.SPIN) # add a chain link self.assertEqual(bqm.energy({'a': 0, 'b': 0}), -1) self.assertEqual(bqm.energy({'a': 1, 'b': 1}), -1) self.assertConsistentBQM(bqm) # binary-to-spin bqm = dimod.BinaryQuadraticModel({'a': 0, 'b': 0}, {}, 0.0, dimod.SPIN) bqm.add_interaction('a', 'b', -1, vartype=dimod.BINARY) # add a chain link self.assertEqual(bqm.energy({'a': +1, 'b': +1}), -1) self.assertEqual(bqm.energy({'a': -1, 'b': +1}), 0) self.assertEqual(bqm.energy({'a': +1, 'b': -1}), 0) self.assertEqual(bqm.energy({'a': -1, 'b': -1}), 0) self.assertConsistentBQM(bqm) bqm = dimod.BinaryQuadraticModel({'b': 0}, {}, 0.0, dimod.SPIN) bqm.add_interaction('a', 'b', -1, vartype=dimod.BINARY) # add a chain link self.assertEqual(bqm.energy({'a': +1, 'b': +1}), -1) self.assertEqual(bqm.energy({'a': -1, 'b': +1}), 0) self.assertEqual(bqm.energy({'a': +1, 'b': -1}), 0) self.assertEqual(bqm.energy({'a': -1, 'b': -1}), 0) self.assertConsistentBQM(bqm) bqm = dimod.BinaryQuadraticModel({'a': 0}, {}, 0.0, dimod.SPIN) bqm.add_interaction('a', 'b', -1, vartype=dimod.BINARY) # add a chain link self.assertEqual(bqm.energy({'a': +1, 'b': +1}), -1) self.assertEqual(bqm.energy({'a': -1, 'b': +1}), 0) self.assertEqual(bqm.energy({'a': +1, 'b': -1}), 0) self.assertEqual(bqm.energy({'a': -1, 'b': -1}), 0) self.assertConsistentBQM(bqm) # no type specified bqm = dimod.BinaryQuadraticModel({'a': 0, 'b': 0}, {}, 0.0, dimod.SPIN) bqm.add_interaction('a', 'b', -1) self.assertEqual(bqm.adj, {'a': {'b': -1}, 'b': {'a': -1}}) self.assertConsistentBQM(bqm) # add to empty bqm = dimod.BinaryQuadraticModel({}, {}, 0.0, dimod.SPIN) bqm.add_interaction('a', 'b', -1) self.assertEqual(bqm.adj, {'a': {'b': -1}, 'b': {'a': -1}}) self.assertConsistentBQM(bqm) # existing biases bqm = dimod.BinaryQuadraticModel({}, {('a', 'b'): -1}, 0.0, dimod.SPIN) bqm.add_interaction('a', 'b', -1) self.assertEqual(bqm.adj, {'a': {'b': -2}, 'b': {'a': -2}}) bqm.add_interaction('b', 'a', -1) self.assertEqual(bqm.adj, {'a': {'b': -3}, 'b': {'a': -3}}) self.assertConsistentBQM(bqm) # unknown vartype bqm = dimod.BinaryQuadraticModel({}, {('a', 'b'): -1}, 0.0, dimod.SPIN) with self.assertRaises(ValueError): bqm.add_interaction('a', 'b', -1, vartype=-1) def test_add_interaction_counterpart(self): # spin bqm = dimod.BinaryQuadraticModel({}, {}, 0.0, dimod.SPIN) bqm.add_interaction('a', 'b', .5) self.assertConsistentBQM(bqm) for av, bv in itertools.product((0, 1), repeat=2): self.assertEqual(bqm.energy({'a': 2 * av - 1, 'b': 2 * bv - 1}), bqm.binary.energy({'a': av, 'b': bv})) bqm.add_interaction('a', 'b', .5) self.assertConsistentBQM(bqm) for av, bv in itertools.product((0, 1), repeat=2): self.assertEqual(bqm.energy({'a': 2 * av - 1, 'b': 2 * bv - 1}), bqm.binary.energy({'a': av, 'b': bv})) # # spin bqm = dimod.BinaryQuadraticModel({}, {}, 0.0, dimod.SPIN) __ = bqm.binary # create counterpart bqm.add_interaction('a', 'b', -1) self.assertConsistentBQM(bqm) for av, bv in itertools.product((0, 1), repeat=2): self.assertEqual(bqm.energy({'a': 2 * av - 1, 'b': 2 * bv - 1}), bqm.binary.energy({'a': av, 'b': bv})) # # binary bqm = dimod.BinaryQuadraticModel({}, {('a', 'b'): -1}, 0.0, dimod.BINARY) bqm.add_interaction('a', 'b', .5) self.assertConsistentBQM(bqm) for av, bv in itertools.product((0, 1), repeat=2): self.assertEqual(bqm.spin.energy({'a': 2 * av - 1, 'b': 2 * bv - 1}), bqm.energy({'a': av, 'b': bv})) # # binary bqm = dimod.BinaryQuadraticModel({}, {('a', 'b'): -1}, 0.0, dimod.BINARY) __ = bqm.spin # create counterpart bqm.add_interaction('a', 'b', -1) self.assertConsistentBQM(bqm) for av, bv in itertools.product((0, 1), repeat=2): self.assertEqual(bqm.spin.energy({'a': 2 * av - 1, 'b': 2 * bv - 1}), bqm.energy({'a': av, 'b': bv})) def test_add_interactions_from(self): bqm = dimod.BinaryQuadraticModel({}, {}, 0.0, dimod.SPIN) bqm.add_interactions_from({('a', 'b'): -.5}) self.assertEqual(bqm, dimod.BinaryQuadraticModel({}, {('a', 'b'): -.5}, 0.0, dimod.SPIN)) bqm.add_interactions_from([('a', 'b', -.5), ('a', 'b', -.5)]) self.assertEqual(bqm.adj['a']['b'], -1.5) self.assertConsistentBQM(bqm) def test_remove_variable(self): linear = {v: v * -.13 for v in range(10)} quadratic = {(u, v): u * v * .021 for u, v in itertools.combinations(linear, 2)} offset = -1.2 vartype = dimod.SPIN bqm = dimod.BinaryQuadraticModel(linear, quadratic, offset, vartype) bqm.remove_variable(2) self.assertNotIn(2, bqm.linear) self.assertConsistentBQM(bqm) # checks the other stuff self.assertNotIn(2, bqm.binary.linear) self.assertConsistentBQM(bqm.binary) self.assertAlmostEqual(bqm.binary.energy({v: v % 2 for v in bqm.linear}), bqm.energy({v: 2 * (v % 2) - 1 for v in bqm.linear})) # linear = {v: v * -.13 for v in range(10)} quadratic = {(u, v): u * v * .021 for u, v in itertools.combinations(linear, 2)} offset = -1.2 vartype = dimod.BINARY bqm = dimod.BinaryQuadraticModel(linear, quadratic, offset, vartype) bqm.remove_variable(2) self.assertNotIn(2, bqm.linear) self.assertConsistentBQM(bqm) # checks the other stuff self.assertNotIn(2, bqm.spin.linear) self.assertConsistentBQM(bqm.spin) self.assertAlmostEqual(bqm.energy({v: v % 2 for v in bqm.linear}), bqm.spin.energy({v: 2 * (v % 2) - 1 for v in bqm.linear})) # linear = {v: v * -.13 for v in range(10)} quadratic = {(u, v): u * v * .021 for u, v in itertools.combinations(linear, 2)} offset = -1.2 vartype = dimod.SPIN bqm = dimod.BinaryQuadraticModel(linear, quadratic, offset, vartype) __ = bqm.binary # create counterpart bqm.remove_variable(2) self.assertNotIn(2, bqm.linear) self.assertConsistentBQM(bqm) # checks the other stuff self.assertNotIn(2, bqm.binary.linear) self.assertConsistentBQM(bqm.binary) self.assertAlmostEqual(bqm.binary.energy({v: v % 2 for v in bqm.linear}), bqm.energy({v: 2 * (v % 2) - 1 for v in bqm.linear})) # linear = {v: v * -.13 for v in range(10)} quadratic = {(u, v): u * v * .021 for u, v in itertools.combinations(linear, 2)} offset = -1.2 vartype = dimod.BINARY bqm = dimod.BinaryQuadraticModel(linear, quadratic, offset, vartype) __ = bqm.spin # create counterpart bqm.remove_variable(2) self.assertNotIn(2, bqm.linear) self.assertConsistentBQM(bqm) # checks the other stuff self.assertNotIn(2, bqm.spin.linear) self.assertConsistentBQM(bqm.spin) self.assertAlmostEqual(bqm.energy({v: v % 2 for v in bqm.linear}), bqm.spin.energy({v: 2 * (v % 2) - 1 for v in bqm.linear})) # bqm = dimod.BinaryQuadraticModel({}, {}, 0.0, dimod.BINARY) bqm.remove_variable(3) # silent fail def test_remove_variables_from(self): linear = {v: v * -.13 for v in range(10)} quadratic = {(u, v): u * v * .021 for u, v in itertools.combinations(linear, 2)} offset = -1.2 vartype = dimod.BINARY bqm = dimod.BinaryQuadraticModel(linear, quadratic, offset, vartype) bqm.remove_variables_from([0, 1]) self.assertNotIn(0, bqm.linear) self.assertNotIn(1, bqm.linear) self.assertConsistentBQM(bqm) def test_remove_interaction(self): linear = {v: v * -.13 for v in range(10)} quadratic = {(u, v): u * v * .021 for u, v in itertools.combinations(linear, 2)} offset = -1.2 vartype = dimod.BINARY bqm = dimod.BinaryQuadraticModel(linear, quadratic, offset, vartype) bqm.remove_interaction(1, 4) self.assertNotIn((1, 4), bqm.quadratic) self.assertNotIn((4, 1), bqm.quadratic) self.assertConsistentBQM(bqm) bqm.remove_interaction(5, 3) self.assertNotIn((5, 3), bqm.quadratic) self.assertNotIn((3, 5), bqm.quadratic) self.assertConsistentBQM(bqm) bqm.remove_interaction('a', 1) # silent fail # remove all interactions interactions = list(bqm.quadratic) for u, v in interactions: bqm.remove_interaction(u, v) for v in range(10): self.assertIn(v, bqm.linear) # all variables should still be there self.assertFalse(len(bqm.quadratic)) self.assertConsistentBQM(bqm) # linear = {v: v * -.13 for v in range(10)} quadratic = {(u, v): u * v * .021 for u, v in itertools.combinations(linear, 2)} offset = -1.2 vartype = dimod.SPIN bqm = dimod.BinaryQuadraticModel(linear, quadratic, offset, vartype) bqm.remove_interaction(1, 4) self.assertAlmostEqual(bqm.binary.energy({v: v % 2 for v in bqm.linear}), bqm.energy({v: 2 * (v % 2) - 1 for v in bqm.linear})) # linear = {v: v * -.13 for v in range(10)} quadratic = {(u, v): u * v * .021 for u, v in itertools.combinations(linear, 2)} offset = -1.2 vartype = dimod.SPIN bqm = dimod.BinaryQuadraticModel(linear, quadratic, offset, vartype) __ = bqm.binary # create counterpart bqm.remove_interaction(1, 4) assert len(linear) == 10 # should not effect linear self.assertAlmostEqual(bqm.binary.energy({v: v % 2 for v in bqm.linear}), bqm.energy({v: 2 * (v % 2) - 1 for v in bqm.linear})) # linear = {v: v * -.13 for v in range(10)} quadratic = {(u, v): u * v * .021 for u, v in itertools.combinations(linear, 2)} offset = -1.2 vartype = dimod.BINARY bqm = dimod.BinaryQuadraticModel(linear, quadratic, offset, vartype) bqm.remove_interaction(1, 4) self.assertAlmostEqual(bqm.energy({v: v % 2 for v in bqm.linear}), bqm.spin.energy({v: 2 * (v % 2) - 1 for v in bqm.linear})) # linear = {v: v * -.13 for v in range(10)} quadratic = {(u, v): u * v * .021 for u, v in itertools.combinations(linear, 2)} offset = -1.2 vartype = dimod.BINARY bqm = dimod.BinaryQuadraticModel(linear, quadratic, offset, vartype) __ = bqm.spin # create counterpart bqm.remove_interaction(1, 4) assert len(linear) == 10 # should not effect linear self.assertAlmostEqual(bqm.energy({v: v % 2 for v in bqm.linear}), bqm.spin.energy({v: 2 * (v % 2) - 1 for v in bqm.linear})) def test_remove_interactions_from(self): linear = {v: v * -.43 for v in range(10)} quadratic = {(u, v): u * v * -.021 for u, v in itertools.combinations(linear, 2)} offset = -1.2 vartype = dimod.BINARY bqm = dimod.BinaryQuadraticModel(linear, quadratic, offset, vartype) bqm.remove_interactions_from(quadratic.copy()) for v in range(10): self.assertIn(v, bqm.linear) # all variables should still be there self.assertFalse(len(bqm.quadratic)) self.assertConsistentBQM(bqm) def test_add_offset(self): bqm = dimod.BinaryQuadraticModel({0: 1.4, 1: -1}, {(1, 0): 1}, 1.2, dimod.SPIN) bqm.add_offset(-1.3) self.assertAlmostEqual(bqm.offset, -.1) self.assertAlmostEqual(bqm.binary.energy({v: v % 2 for v in bqm.linear}), bqm.spin.energy({v: 2 * (v % 2) - 1 for v in bqm.linear})) # bqm = dimod.BinaryQuadraticModel({0: 1.4, 1: -1}, {(1, 0): 1}, 1.2, dimod.SPIN) __ = bqm.binary bqm.add_offset(-1.3) self.assertAlmostEqual(bqm.offset, -.1) self.assertAlmostEqual(bqm.binary.energy({v: v % 2 for v in bqm.linear}), bqm.spin.energy({v: 2 * (v % 2) - 1 for v in bqm.linear})) def test_remove_offset(self): linear = {v: v * -.43 for v in range(10)} quadratic = {(u, v): u * v * -.021 for u, v in itertools.combinations(linear, 2)} offset = -1.2 vartype = dimod.BINARY bqm = dimod.BinaryQuadraticModel(linear, quadratic, offset, vartype) bqm.remove_offset() self.assertAlmostEqual(bqm.offset, 0.0) def test_scale(self): bqm = dimod.BinaryQuadraticModel({0: -2, 1: 2}, {(0, 1): -1}, 1., dimod.SPIN) bqm.scale(.5) self.assertAlmostEqual(bqm.linear, {0: -1., 1: 1.}) self.assertAlmostEqual(bqm.quadratic, {(0, 1): -.5}) self.assertAlmostEqual(bqm.offset, .5) self.assertConsistentBQM(bqm) self.assertAlmostEqual(bqm.binary.energy({v: v % 2 for v in bqm.linear}), bqm.spin.energy({v: 2 * (v % 2) - 1 for v in bqm.linear})) # bqm = dimod.BinaryQuadraticModel({0: -2, 1: 2}, {(0, 1): -1}, 1., dimod.SPIN) __ = bqm.binary bqm.scale(.5) self.assertAlmostEqual(bqm.linear, {0: -1., 1: 1.}) self.assertAlmostEqual(bqm.quadratic, {(0, 1): -.5}) self.assertAlmostEqual(bqm.offset, .5) self.assertConsistentBQM(bqm) self.assertAlmostEqual(bqm.binary.energy({v: v % 2 for v in bqm.linear}), bqm.spin.energy({v: 2 * (v % 2) - 1 for v in bqm.linear})) # with self.assertRaises(TypeError): bqm.scale('a') def test_normalize(self): bqm = dimod.BinaryQuadraticModel({0: -2, 1: 2}, {(0, 1): -1}, 1., dimod.SPIN) bqm.normalize(.5) self.assertAlmostEqual(bqm.linear, {0: -.5, 1: .5}) self.assertAlmostEqual(bqm.quadratic, {(0, 1): -.25}) self.assertAlmostEqual(bqm.offset, .25) self.assertConsistentBQM(bqm) self.assertAlmostEqual(bqm.binary.energy({v: v % 2 for v in bqm.linear}), bqm.spin.energy({v: 2 * (v % 2) - 1 for v in bqm.linear})) # with self.assertRaises(TypeError): bqm.scale('a') def test_normalize_exclusions(self): bqm = dimod.BinaryQuadraticModel({0: -2, 1: 2}, {(0, 1): -1}, 1., dimod.SPIN) bqm.normalize(.5, ignored_variables=[0]) self.assertAlmostEqual(bqm.linear, {0: -2, 1: .5}) self.assertAlmostEqual(bqm.quadratic, {(0, 1): -.25}) self.assertAlmostEqual(bqm.offset, .25) self.assertConsistentBQM(bqm) bqm = dimod.BinaryQuadraticModel({0: -2, 1: 2}, {(0, 1): -1}, 1., dimod.SPIN) bqm.normalize(.5, ignored_interactions=[(1, 0)]) self.assertAlmostEqual(bqm.linear, {0: -.5, 1: .5}) self.assertAlmostEqual(bqm.quadratic, {(0, 1): -1}) self.assertAlmostEqual(bqm.offset, .25) self.assertConsistentBQM(bqm) bqm = dimod.BinaryQuadraticModel({0: -2, 1: 2}, {(0, 1): -1}, 1., dimod.SPIN) bqm.normalize(.5, ignore_offset=True) self.assertAlmostEqual(bqm.linear, {0: -.5, 1: .5}) self.assertAlmostEqual(bqm.quadratic, {(0, 1): -.25}) self.assertAlmostEqual(bqm.offset, 1.) self.assertConsistentBQM(bqm) bqm = dimod.BinaryQuadraticModel({0: -2, 1: 2}, {(0, 1): -5}, 1., dimod.SPIN) bqm.normalize(0.5, ignored_interactions=[(0, 1)]) self.assertAlmostEqual(bqm.linear, {0: -.5, 1: .5}) self.assertAlmostEqual(bqm.quadratic, {(0, 1): -5}) self.assertAlmostEqual(bqm.offset, 0.25) self.assertConsistentBQM(bqm) def test_scale_exclusions(self): bqm = dimod.BinaryQuadraticModel({0: -2, 1: 2}, {(0, 1): -1}, 1., dimod.SPIN) bqm.scale(.5, ignored_variables=[0]) self.assertConsistentBQM(bqm) self.assertEqual(bqm, dimod.BinaryQuadraticModel({0: -2, 1: 1}, {(0, 1): -.5}, .5, dimod.SPIN)) bqm = dimod.BinaryQuadraticModel({0: -2, 1: 2}, {(0, 1): -1}, 1., dimod.SPIN) bqm.scale(.5, ignored_interactions=[(1, 0)]) self.assertConsistentBQM(bqm) self.assertEqual(bqm, dimod.BinaryQuadraticModel({0: -1, 1: 1}, {(0, 1): -1.}, .5, dimod.SPIN)) bqm = dimod.BinaryQuadraticModel({0: -2, 1: 2}, {(0, 1): -1}, 1., dimod.SPIN) bqm.scale(.5, ignore_offset=True) self.assertConsistentBQM(bqm) self.assertEqual(bqm, dimod.BinaryQuadraticModel({0: -1, 1: 1}, {(0, 1): -.5}, 1., dimod.SPIN)) def test_fix_variables(self): bqm = dimod.BinaryQuadraticModel({'a': .3}, {('a', 'b'): -1}, 1.2, dimod.SPIN) bqm.fix_variables({'a': -1, 'b': +1}) def test_fix_variable(self): # spin model, fix variable to +1 bqm = dimod.BinaryQuadraticModel({'a': .3}, {('a', 'b'): -1}, 1.2, dimod.SPIN) original_bqm = dimod.BinaryQuadraticModel({'a': .3}, {('a', 'b'): -1}, 1.2, dimod.SPIN) bqm.fix_variable('a', +1) self.assertEqual(bqm.energy({'b': +1}), original_bqm.energy({'b': +1, 'a': +1})) self.assertEqual(bqm.energy({'b': -1}), original_bqm.energy({'b': -1, 'a': +1})) self.assertEqual(bqm.binary.energy({'b': 1}), original_bqm.binary.energy({'b': 1, 'a': 1})) self.assertEqual(bqm.binary.energy({'b': 0}), original_bqm.binary.energy({'b': 0, 'a': 1})) # # spin model with binary built, fix variable to +1 bqm = dimod.BinaryQuadraticModel({'a': .3}, {('a', 'b'): -1}, 1.2, dimod.SPIN) original_bqm = dimod.BinaryQuadraticModel({'a': .3}, {('a', 'b'): -1}, 1.2, dimod.SPIN) __ = bqm.binary # create the binary version bqm.fix_variable('a', +1) self.assertEqual(bqm.energy({'b': +1}), original_bqm.energy({'b': +1, 'a': +1})) self.assertEqual(bqm.energy({'b': -1}), original_bqm.energy({'b': -1, 'a': +1})) self.assertEqual(bqm.binary.energy({'b': 1}), original_bqm.binary.energy({'b': 1, 'a': 1})) self.assertEqual(bqm.binary.energy({'b': 0}), original_bqm.binary.energy({'b': 0, 'a': 1})) # # spin model, fix variable to -1 bqm = dimod.BinaryQuadraticModel({'a': .3}, {('a', 'b'): -1}, 1.2, dimod.SPIN) original_bqm = dimod.BinaryQuadraticModel({'a': .3}, {('a', 'b'): -1}, 1.2, dimod.SPIN) bqm.fix_variable('a', -1) self.assertEqual(bqm.energy({'b': +1}), original_bqm.energy({'b': +1, 'a': -1})) self.assertEqual(bqm.energy({'b': -1}), original_bqm.energy({'b': -1, 'a': -1})) self.assertEqual(bqm.binary.energy({'b': 1}), original_bqm.binary.energy({'b': 1, 'a': 0})) self.assertEqual(bqm.binary.energy({'b': 0}), original_bqm.binary.energy({'b': 0, 'a': 0})) # # spin model with binary built, fix variable to -1 bqm = dimod.BinaryQuadraticModel({'a': .3}, {('a', 'b'): -1}, 1.2, dimod.SPIN) original_bqm = dimod.BinaryQuadraticModel({'a': .3}, {('a', 'b'): -1}, 1.2, dimod.SPIN) __ = bqm.binary # create the binary version bqm.fix_variable('a', -1) self.assertEqual(bqm.energy({'b': +1}), original_bqm.energy({'b': +1, 'a': -1})) self.assertEqual(bqm.energy({'b': -1}), original_bqm.energy({'b': -1, 'a': -1})) self.assertEqual(bqm.binary.energy({'b': 1}), original_bqm.binary.energy({'b': 1, 'a': 0})) self.assertEqual(bqm.binary.energy({'b': 0}), original_bqm.binary.energy({'b': 0, 'a': 0})) # # binary model, fix variable to +1 bqm = dimod.BinaryQuadraticModel({'a': .3}, {('a', 'b'): -1}, 1.2, dimod.BINARY) original_bqm = dimod.BinaryQuadraticModel({'a': .3}, {('a', 'b'): -1}, 1.2, dimod.BINARY) bqm.fix_variable('a', 1) self.assertEqual(bqm.spin.energy({'b': +1}), original_bqm.energy({'b': 1, 'a': 1})) self.assertEqual(bqm.spin.energy({'b': -1}), original_bqm.energy({'b': 0, 'a': 1})) self.assertAlmostEqual(bqm.spin.energy({'b': +1}), original_bqm.spin.energy({'b': +1, 'a': +1})) self.assertAlmostEqual(bqm.spin.energy({'b': -1}), original_bqm.spin.energy({'b': -1, 'a': +1})) # bqm = dimod.BinaryQuadraticModel({'a': .3}, {('a', 'b'): -1}, 1.2, dimod.BINARY) original_bqm = dimod.BinaryQuadraticModel({'a': .3}, {('a', 'b'): -1}, 1.2, dimod.BINARY) __ = bqm.spin bqm.fix_variable('a', 1) self.assertEqual(bqm.spin.energy({'b': +1}), original_bqm.energy({'b': 1, 'a': 1})) self.assertEqual(bqm.spin.energy({'b': -1}), original_bqm.energy({'b': 0, 'a': 1})) self.assertAlmostEqual(bqm.spin.energy({'b': +1}), original_bqm.spin.energy({'b': +1, 'a': +1})) self.assertAlmostEqual(bqm.spin.energy({'b': -1}), original_bqm.spin.energy({'b': -1, 'a': +1})) # # binary model, fix variable to 0 bqm = dimod.BinaryQuadraticModel({'a': .3}, {('a', 'b'): -1}, 1.2, dimod.BINARY) original_bqm = dimod.BinaryQuadraticModel({'a': .3}, {('a', 'b'): -1}, 1.2, dimod.BINARY) bqm.fix_variable('a', 0) self.assertEqual(bqm.spin.energy({'b': +1}), original_bqm.energy({'b': 1, 'a': 0})) self.assertEqual(bqm.spin.energy({'b': -1}), original_bqm.energy({'b': 0, 'a': 0})) self.assertAlmostEqual(bqm.spin.energy({'b': +1}), original_bqm.spin.energy({'b': +1, 'a': -1})) self.assertAlmostEqual(bqm.spin.energy({'b': -1}), original_bqm.spin.energy({'b': -1, 'a': -1})) # bqm = dimod.BinaryQuadraticModel({'a': .3}, {('a', 'b'): -1}, 1.2, dimod.BINARY) original_bqm = dimod.BinaryQuadraticModel({'a': .3}, {('a', 'b'): -1}, 1.2, dimod.BINARY) __ = bqm.spin bqm.fix_variable('a', 0) self.assertEqual(bqm.spin.energy({'b': +1}), original_bqm.energy({'b': 1, 'a': 0})) self.assertEqual(bqm.spin.energy({'b': -1}), original_bqm.energy({'b': 0, 'a': 0})) self.assertAlmostEqual(bqm.spin.energy({'b': +1}), original_bqm.spin.energy({'b': +1, 'a': -1})) self.assertAlmostEqual(bqm.spin.energy({'b': -1}), original_bqm.spin.energy({'b': -1, 'a': -1})) # with self.assertRaises(ValueError): bqm.fix_variable('b', -1) # spin for binary def test_flip_variable(self): # single spin variable, trivial bqm = dimod.BinaryQuadraticModel({'a': -1}, {}, 0.0, dimod.SPIN) original_bqm = dimod.BinaryQuadraticModel({'a': -1}, {}, 0.0, dimod.SPIN) bqm.flip_variable('a') self.assertAlmostEqual(bqm.energy({'a': +1}), original_bqm.energy({'a': -1})) self.assertAlmostEqual(bqm.energy({'a': -1}), original_bqm.energy({'a': +1})) self.assertConsistentBQM(bqm) bqm.flip_variable('a') # should return to original self.assertEqual(bqm, original_bqm) # # more complicated spin model linear = {v: v * -.43 for v in range(10)} quadratic = {(u, v): u * v * -.021 for u, v in itertools.combinations(linear, 2)} offset = -1.2 vartype = dimod.SPIN bqm = dimod.BinaryQuadraticModel(linear, quadratic, offset, vartype) original_bqm = dimod.BinaryQuadraticModel(linear, quadratic, offset, vartype) bqm.flip_variable(4) self.assertConsistentBQM(bqm) self.assertEqual(linear[4], bqm.linear[4] * -1) self.assertNotEqual(bqm, original_bqm) sample = {v: 1 for v in linear} flipped_sample = sample.copy() flipped_sample[4] = -1 self.assertAlmostEqual(bqm.energy(flipped_sample), original_bqm.energy(sample)) bqm.flip_variable(4) # should return to original self.assertEqual(bqm, original_bqm) # # single binary variable bqm = dimod.BinaryQuadraticModel({'a': -1}, {}, 0.0, dimod.BINARY) original_bqm = dimod.BinaryQuadraticModel({'a': -1}, {}, 0.0, dimod.BINARY) bqm.flip_variable('a') self.assertAlmostEqual(bqm.energy({'a': 1}), original_bqm.energy({'a': 0})) self.assertAlmostEqual(bqm.energy({'a': 0}), original_bqm.energy({'a': 1})) self.assertConsistentBQM(bqm) bqm.flip_variable('a') # should return to original self.assertEqual(bqm, original_bqm) # linear = {v: v * -.43 for v in range(10)} quadratic = {(u, v): u * v * -.021 for u, v in itertools.combinations(linear, 2)} offset = -1.2 vartype = dimod.BINARY bqm = dimod.BinaryQuadraticModel(linear, quadratic, offset, vartype) original_bqm = dimod.BinaryQuadraticModel(linear, quadratic, offset, vartype) bqm.flip_variable(4) self.assertConsistentBQM(bqm) self.assertNotEqual(bqm, original_bqm) sample = {v: 1 for v in linear} flipped_sample = sample.copy() flipped_sample[4] = 0 self.assertAlmostEqual(bqm.energy(flipped_sample), original_bqm.energy(sample)) bqm.flip_variable(4) # should return to original self.assertEqual(bqm, original_bqm) # bqm.flip_variable(100000) # silent fail def test_update(self): binary_bqm = dimod.BinaryQuadraticModel({'a': .3}, {('a', 'b'): -1}, 0, dimod.BINARY) spin_bqm = dimod.BinaryQuadraticModel({'c': -1}, {('b', 'c'): 1}, 1.2, dimod.SPIN) binary_bqm.update(spin_bqm) # binary contribution is 0.0 self.assertEqual(binary_bqm.energy({'a': 0, 'b': 0, 'c': 0}), spin_bqm.energy({'c': -1, 'b': -1})) def test_contract_variables(self): bqm = dimod.BinaryQuadraticModel({'a': .3}, {('a', 'b'): -1, ('b', 'c'): 1}, 1.2, dimod.BINARY) original_bqm = bqm.copy() bqm.contract_variables('a', 'b') self.assertNotIn('b', bqm.linear) self.assertConsistentBQM(bqm) self.assertAlmostEqual(bqm.energy({'a': 0, 'c': 1}), original_bqm.energy({'a': 0, 'b': 0, 'c': 1})) self.assertAlmostEqual(bqm.energy({'a': 1, 'c': 1}), original_bqm.energy({'a': 1, 'b': 1, 'c': 1})) self.assertAlmostEqual(bqm.energy({'a': 0, 'c': 0}), original_bqm.energy({'a': 0, 'b': 0, 'c': 0})) self.assertAlmostEqual(bqm.energy({'a': 1, 'c': 0}), original_bqm.energy({'a': 1, 'b': 1, 'c': 0})) # bqm = dimod.BinaryQuadraticModel({'a': .3}, {('a', 'b'): -1, ('b', 'c'): 1}, 1.2, dimod.SPIN) original_bqm = bqm.copy() bqm.contract_variables('a', 'b') self.assertNotIn('b', bqm.linear) self.assertConsistentBQM(bqm) self.assertAlmostEqual(bqm.energy({'a': -1, 'c': +1}), original_bqm.energy({'a': -1, 'b': -1, 'c': +1})) self.assertAlmostEqual(bqm.energy({'a': +1, 'c': +1}), original_bqm.energy({'a': +1, 'b': +1, 'c': +1})) self.assertAlmostEqual(bqm.energy({'a': -1, 'c': -1}), original_bqm.energy({'a': -1, 'b': -1, 'c': -1})) self.assertAlmostEqual(bqm.energy({'a': +1, 'c': -1}), original_bqm.energy({'a': +1, 'b': +1, 'c': -1})) # with self.assertRaises(ValueError): bqm.contract_variables(0, 1) with self.assertRaises(ValueError): bqm.contract_variables('a', 1) def test_relabel_typical(self): linear = {0: .5, 1: 1.3} quadratic = {(0, 1): -.435} offset = 1.2 vartype = dimod.SPIN model = dimod.BinaryQuadraticModel(linear, quadratic, offset, vartype) mapping = {0: 'a', 1: 'b'} newmodel = model.relabel_variables(mapping, inplace=False) # check that new model is the same as old model linear = {'a': .5, 'b': 1.3} quadratic = {('a', 'b'): -.435} offset = 1.2 vartype = dimod.SPIN testmodel = dimod.BinaryQuadraticModel(linear, quadratic, offset, vartype) self.assertEqual(newmodel, testmodel) def test_relabel_typical_copy(self): linear = {0: .5, 1: 1.3} quadratic = {(0, 1): -.435} offset = 1.2 vartype = dimod.SPIN model = dimod.BinaryQuadraticModel(linear, quadratic, offset, vartype) mapping = {0: 'a', 1: 'b'} newmodel = model.relabel_variables(mapping, inplace=False) self.assertNotEqual(id(model), id(newmodel)) self.assertNotEqual(id(model.linear), id(newmodel.linear)) self.assertNotEqual(id(model.quadratic), id(newmodel.quadratic)) # check that new model is the same as old model linear = {'a': .5, 'b': 1.3} quadratic = {('a', 'b'): -.435} offset = 1.2 vartype = dimod.SPIN testmodel = dimod.BinaryQuadraticModel(linear, quadratic, offset, vartype) self.assertEqual(newmodel, testmodel) def test_relabel_typical_inplace(self): linear = {0: .5, 1: 1.3} quadratic = {(0, 1): -.435} offset = 1.2 vartype = dimod.SPIN model = dimod.BinaryQuadraticModel(linear, quadratic, offset, vartype) mapping = {0: 'a', 1: 'b'} newmodel = model.relabel_variables(mapping) self.assertEqual(id(model), id(newmodel)) self.assertEqual(id(model.linear), id(newmodel.linear)) self.assertEqual(id(model.quadratic), id(newmodel.quadratic)) # check that model is the same as old model linear = {'a': .5, 'b': 1.3} quadratic = {('a', 'b'): -.435} offset = 1.2 vartype = dimod.SPIN testmodel = dimod.BinaryQuadraticModel(linear, quadratic, offset, vartype) self.assertEqual(model, testmodel) self.assertEqual(model.adj, testmodel.adj) def test_relabel_with_overlap(self): linear = {v: .1 * v for v in range(-5, 4)} quadratic = {(u, v): .1 * u * v for u, v in itertools.combinations(linear, 2)} offset = 1.2 vartype = dimod.SPIN model = dimod.BinaryQuadraticModel(linear, quadratic, offset, vartype) partial_overlap_mapping = {v: -v for v in linear} # has variables mapped to other old labels # construct a test model by using copy testmodel = model.relabel_variables(partial_overlap_mapping, inplace=False) # now apply in place model.relabel_variables(partial_overlap_mapping, inplace=True) # should have stayed the same self.assertEqual(testmodel, model) self.assertEqual(testmodel.adj, model.adj) def test_relabel_with_identity(self): linear = {v: .1 * v for v in range(-5, 4)} quadratic = {(u, v): .1 * u * v for u, v in itertools.combinations(linear, 2)} offset = 1.2 vartype = dimod.SPIN model = dimod.BinaryQuadraticModel(linear, quadratic, offset, vartype) old_model = model.copy() identity_mapping = {v: v for v in linear} model.relabel_variables(identity_mapping, inplace=True) # should have stayed the same self.assertEqual(old_model, model) self.assertEqual(old_model.adj, model.adj) def test_partial_relabel_copy(self): linear = {v: .1 * v for v in range(-5, 5)} quadratic = {(u, v): .1 * u * v for u, v in itertools.combinations(linear, 2)} offset = 1.2 vartype = dimod.SPIN model = dimod.BinaryQuadraticModel(linear, quadratic, offset, vartype) mapping = {0: 'a', 1: 'b'} # partial mapping newmodel = model.relabel_variables(mapping, inplace=False) newlinear = linear.copy() newlinear['a'] = newlinear[0] newlinear['b'] = newlinear[1] del newlinear[0] del newlinear[1] self.assertEqual(newlinear, newmodel.linear) def test_partial_relabel_inplace(self): linear = {v: .1 * v for v in range(-5, 5)} quadratic = {(u, v): .1 * u * v for u, v in itertools.combinations(linear, 2)} offset = 1.2 vartype = dimod.SPIN model = dimod.BinaryQuadraticModel(linear, quadratic, offset, vartype) newlinear = linear.copy() newlinear['a'] = newlinear[0] newlinear['b'] = newlinear[1] del newlinear[0] del newlinear[1] mapping = {0: 'a', 1: 'b'} # partial mapping model.relabel_variables(mapping, inplace=True) self.assertEqual(newlinear, model.linear) def test_copy(self): linear = {0: .5, 1: 1.3} quadratic = {(0, 1): -.435} offset = 1.2 vartype = dimod.SPIN bqm = dimod.BinaryQuadraticModel(linear, quadratic, offset, vartype) new_bqm = bqm.copy() # everything should have a new id self.assertNotEqual(id(bqm.linear), id(new_bqm.linear)) self.assertNotEqual(id(bqm.quadratic), id(new_bqm.quadratic)) self.assertNotEqual(id(bqm.adj), id(new_bqm.adj)) for v in bqm.linear: self.assertIsNot(bqm.adj[v], new_bqm.adj[v]) # values should all be equal self.assertEqual(bqm.linear, new_bqm.linear) self.assertEqual(bqm.quadratic, new_bqm.quadratic) self.assertEqual(bqm.adj, new_bqm.adj) for v in bqm.linear: self.assertEqual(bqm.adj[v], new_bqm.adj[v]) self.assertEqual(bqm, new_bqm) def test_change_vartype(self): # # copy # linear = {0: 1, 1: -1, 2: .5} quadratic = {(0, 1): .5, (1, 2): 1.5} offset = 1.4 vartype = dimod.BINARY bqm = dimod.BinaryQuadraticModel(linear, quadratic, offset, vartype) # should not change new_model = bqm.change_vartype(dimod.BINARY, inplace=False) self.assertEqual(bqm, new_model) self.assertNotEqual(id(bqm), id(new_model)) # change vartype new_model = bqm.change_vartype(dimod.SPIN, inplace=False) # check all of the energies for spins in itertools.product((-1, 1), repeat=len(linear)): spin_sample = {v: spins[v] for v in linear} binary_sample = {v: (spins[v] + 1) // 2 for v in linear} self.assertAlmostEqual(bqm.energy(binary_sample), new_model.energy(spin_sample)) linear = {0: 1, 1: -1, 2: .5} quadratic = {(0, 1): .5, (1, 2): 1.5} offset = -1.4 vartype = dimod.SPIN bqm = dimod.BinaryQuadraticModel(linear, quadratic, offset, vartype) # should not change new_model = bqm.change_vartype(dimod.SPIN, inplace=False) self.assertEqual(bqm, new_model) self.assertNotEqual(id(bqm), id(new_model)) # change vartype new_model = bqm.change_vartype(dimod.BINARY, inplace=False) # check all of the energies for spins in itertools.product((-1, 1), repeat=len(linear)): spin_sample = {v: spins[v] for v in linear} binary_sample = {v: (spins[v] + 1) // 2 for v in linear} self.assertAlmostEqual(bqm.energy(spin_sample), new_model.energy(binary_sample)) with self.assertRaises(TypeError): bqm.change_vartype('BOOLEAN') # # in place # linear = {0: 1, 1: -1, 2: .5} quadratic = {(0, 1): .5, (1, 2): 1.5} offset = 1.4 vartype = dimod.BINARY bqm = dimod.BinaryQuadraticModel(linear, quadratic, offset, vartype) original_bqm = bqm.copy() # should not change new_model = bqm.change_vartype(dimod.BINARY) self.assertEqual(bqm, new_model) self.assertEqual(id(bqm), id(new_model)) new_model = bqm.change_vartype(dimod.BINARY, inplace=True) self.assertEqual(bqm, new_model) self.assertEqual(id(bqm), id(new_model)) # change vartype bqm.change_vartype(dimod.SPIN) # check all of the energies for spins in itertools.product((-1, 1), repeat=len(linear)): spin_sample = {v: spins[v] for v in linear} binary_sample = {v: (spins[v] + 1) // 2 for v in linear} self.assertAlmostEqual(bqm.energy(spin_sample), original_bqm.energy(binary_sample)) # SPIN model linear = {0: 1, 1: -1, 2: .5} quadratic = {(0, 1): .5, (1, 2): 1.5} offset = -1.4 vartype = dimod.SPIN bqm = dimod.BinaryQuadraticModel(linear, quadratic, offset, vartype) original_bqm = bqm.copy() # should not change new_model = bqm.change_vartype(dimod.SPIN) self.assertEqual(bqm, new_model) self.assertEqual(id(bqm), id(new_model)) # change vartype bqm.change_vartype(dimod.BINARY) # check all of the energies for spins in itertools.product((-1, 1), repeat=len(linear)): spin_sample = {v: spins[v] for v in linear} binary_sample = {v: (spins[v] + 1) // 2 for v in linear} self.assertAlmostEqual(original_bqm.energy(spin_sample), bqm.energy(binary_sample)) def test_spin_property(self): linear = {0: 1, 1: -1, 2: .5} quadratic = {(0, 1): .5, (1, 2): 1.5} offset = -1.4 vartype = dimod.SPIN model = dimod.BinaryQuadraticModel(linear, quadratic, offset, vartype) self.assertIs(model, model.spin) # # create a binary model linear = {0: 1, 1: -1, 2: .5} quadratic = {(0, 1): .5, (1, 2): 1.5} offset = -1.4 vartype = dimod.BINARY model = dimod.BinaryQuadraticModel(linear, quadratic, offset, vartype) # get a new spin-model from binary spin_model = model.change_vartype(dimod.SPIN, inplace=False) # this spin model should be equal to model.spin self.assertEqual(model.spin, spin_model) # we don't want to make the spin model anew each time, so make sure they # are the same object self.assertEqual(model.spin, model.spin) # should always be equal self.assertEqual(id(model.spin), id(model.spin)) # should always refer to the same object # make sure that model.spin.binary == model self.assertEqual(model.spin.binary, model) self.assertEqual(id(model.spin.binary), id(model)) def test_binary_property(self): linear = {0: 1, 1: -1, 2: .5} quadratic = {(0, 1): .5, (1, 2): 1.5} offset = -1.4 vartype = dimod.BINARY model = dimod.BinaryQuadraticModel(linear, quadratic, offset, vartype) self.assertIs(model, model.binary) # # create a binary model linear = {0: 1, 1: -1, 2: .5} quadratic = {(0, 1): .5, (1, 2): 1.5} offset = -1.4 vartype = dimod.SPIN model = dimod.BinaryQuadraticModel(linear, quadratic, offset, vartype) binary_model = model.change_vartype(dimod.BINARY, inplace=False) self.assertEqual(model.binary, binary_model) self.assertEqual(model.binary, model.binary) # should always be equal self.assertEqual(id(model.binary), id(model.binary)) # should always refer to the same object self.assertEqual(model.binary.spin, model) self.assertEqual(id(model.binary.spin), id(model)) def test_spin_property_relabel(self): # create a spin model linear = {v: .1 * v for v in range(-5, 5)} quadratic = {(u, v): .1 * u * v for u, v in itertools.combinations(linear, 2)} offset = 1.2 vartype = dimod.SPIN model = dimod.BinaryQuadraticModel(linear, quadratic, offset, vartype) __ = model.binary # change a variable label in place model.relabel_variables({0: 'a'}) self.assertIn('a', model.binary.linear) self.assertNotIn(0, model.binary.linear) def test_binary_property_relabel(self): # create a spin model linear = {v: .1 * v for v in range(-5, 5)} quadratic = {(u, v): .1 * u * v for u, v in itertools.combinations(linear, 2)} offset = 1.2 vartype = dimod.BINARY model = dimod.BinaryQuadraticModel(linear, quadratic, offset, vartype) __ = model.spin # change a variable label in place model.relabel_variables({0: 'a'}) self.assertIn('a', model.spin.linear) self.assertNotIn(0, model.spin.linear) def test_pickle_empty(self): bqm = dimod.BinaryQuadraticModel.empty(dimod.SPIN) retrieved = pickle.loads(pickle.dumps(bqm)) self.assertEqual(bqm, retrieved) def test_consistency_after_retrieve(self): bqm = dimod.BinaryQuadraticModel.empty(dimod.SPIN) retrieved = pickle.loads(pickle.dumps(bqm)) # make sure the retrieved one was reconstructed properly retrieved.add_variable('a', -1) bqm.add_variable('a', -1) retrieved.add_interaction(0, 1, -.5) bqm.add_interaction(0, 1, -.5) self.assertEqual(bqm, retrieved) self.assertConsistentBQM(retrieved) def test_pickle_full(self): bqm = dimod.BinaryQuadraticModel.from_ising({'a': -1}, {'ab': 1, 'bc': -1}) retrieved = pickle.loads(pickle.dumps(bqm)) self.assertEqual(bqm, retrieved) class TestConvert(unittest.TestCase): @unittest.skipUnless(_networkx, "No networkx installed") def test_to_networkx_graph(self): graph = nx.barbell_graph(7, 6) # build a BQM model = dimod.BinaryQuadraticModel({v: -.1 for v in graph}, {edge: -.4 for edge in graph.edges}, 1.3, vartype=dimod.SPIN) # get the graph BQM = model.to_networkx_graph() self.assertEqual(set(graph), set(BQM)) for u, v in graph.edges: self.assertIn(u, BQM[v]) for v, bias in model.linear.items(): self.assertEqual(bias, BQM.nodes[v]['bias']) def test_to_ising_spin_to_ising(self): linear = {0: 7.1, 1: 103} quadratic = {(0, 1): .97} offset = 0.3 vartype = dimod.SPIN model = dimod.BinaryQuadraticModel(linear, quadratic, offset, vartype) h, J, off = model.to_ising() self.assertEqual(off, offset) self.assertEqual(linear, h) self.assertEqual(quadratic, J) def test_to_ising_binary_to_ising(self): """binary model's to_ising method""" linear = {0: 7.1, 1: 103} quadratic = {(0, 1): .97} offset = 0.3 vartype = dimod.BINARY model = dimod.BinaryQuadraticModel(linear, quadratic, offset, vartype) h, J, off = model.to_ising() for spins in itertools.product((-1, 1), repeat=len(model)): spin_sample = dict(zip(range(len(spins)), spins)) bin_sample = {v: (s + 1) // 2 for v, s in spin_sample.items()} # calculate the qubo's energy energy = off for (u, v), bias in J.items(): energy += spin_sample[u] * spin_sample[v] * bias for v, bias in h.items(): energy += spin_sample[v] * bias # and the energy of the model self.assertAlmostEqual(energy, model.energy(bin_sample)) def test_to_qubo_binary_to_qubo(self): """Binary model's to_qubo method""" linear = {0: 0, 1: 0} quadratic = {(0, 1): 1} offset = 0.0 vartype = dimod.BINARY model = dimod.BinaryQuadraticModel(linear, quadratic, offset, vartype) Q, off = model.to_qubo() self.assertEqual(off, offset) self.assertEqual({(0, 0): 0, (1, 1): 0, (0, 1): 1}, Q) def test_to_qubo_spin_to_qubo(self): """Spin model's to_qubo method""" linear = {0: .5, 1: 1.3} quadratic = {(0, 1): -.435} offset = 1.2 vartype = dimod.SPIN model = dimod.BinaryQuadraticModel(linear, quadratic, offset, vartype) Q, off = model.to_qubo() for spins in itertools.product((-1, 1), repeat=len(model)): spin_sample = dict(zip(range(len(spins)), spins)) bin_sample = {v: (s + 1) // 2 for v, s in spin_sample.items()} # calculate the qubo's energy energy = off for (u, v), bias in Q.items(): energy += bin_sample[u] * bin_sample[v] * bias # and the energy of the model self.assertAlmostEqual(energy, model.energy(spin_sample)) def test_to_numpy_matrix(self): # integer-indexed, binary bqm linear = {v: v * .01 for v in range(10)} quadratic = {(v, u): u * v * .01 for u, v in itertools.combinations(linear, 2)} quadratic[(0, 1)] = quadratic[(1, 0)] del quadratic[(1, 0)] offset = 1.2 vartype = dimod.BINARY bqm = dimod.BinaryQuadraticModel(linear, quadratic, offset, vartype) M = bqm.to_numpy_matrix() self.assertTrue(np.array_equal(M, np.triu(M))) # upper triangular for (row, col), bias in np.ndenumerate(M): if row == col: self.assertEqual(bias, linear[row]) else: self.assertTrue((row, col) in quadratic or (col, row) in quadratic) self.assertFalse((row, col) in quadratic and (col, row) in quadratic) if row > col: self.assertEqual(bias, 0) else: if (row, col) in quadratic: self.assertEqual(quadratic[(row, col)], bias) else: self.assertEqual(quadratic[(col, row)], bias) # # integer-indexed, not contiguous bqm = dimod.BinaryQuadraticModel({}, {(0, 3): -1}, 0.0, dimod.BINARY) with self.assertRaises(ValueError): M = bqm.to_numpy_matrix() # # string-labeled, variable_order provided linear = {'a': -1} quadratic = {('a', 'c'): 1.2, ('b', 'c'): .3} bqm = dimod.BinaryQuadraticModel(linear, quadratic, 0.0, dimod.BINARY) with self.assertRaises(ValueError): bqm.to_numpy_matrix(['a', 'c']) # incomplete variable order M = bqm.to_numpy_matrix(['a', 'c', 'b']) self.assertTrue(np.array_equal(M, [[-1., 1.2, 0.], [0., 0., 0.3], [0., 0., 0.]])) def test_from_numpy_matrix(self): linear = {'a': -1} quadratic = {('a', 'c'): 1.2, ('b', 'c'): .3} bqm = dimod.BinaryQuadraticModel(linear, quadratic, 0.0, dimod.BINARY) variable_order = ['a', 'c', 'b'] M = bqm.to_numpy_matrix(variable_order=variable_order) new_bqm = dimod.BinaryQuadraticModel.from_numpy_matrix(M, variable_order=variable_order) self.assertEqual(bqm, new_bqm) # # zero-interactions get ignored unless provided in interactions linear = {'a': -1} quadratic = {('a', 'c'): 1.2, ('b', 'c'): .3, ('a', 'b'): 0} bqm = dimod.BinaryQuadraticModel(linear, quadratic, 0.0, dimod.BINARY) variable_order = ['a', 'c', 'b'] M = bqm.to_numpy_matrix(variable_order=variable_order) new_bqm = dimod.BinaryQuadraticModel.from_numpy_matrix(M, variable_order=variable_order) self.assertNotIn(('a', 'b'), new_bqm.quadratic) self.assertNotIn(('b', 'a'), new_bqm.quadratic) new_bqm = dimod.BinaryQuadraticModel.from_numpy_matrix(M, variable_order=variable_order, interactions=quadratic) self.assertEqual(bqm, new_bqm) # M = np.asarray([[0, 1], [0, 0]]) bqm = dimod.BinaryQuadraticModel.from_numpy_matrix(M) self.assertEqual(bqm, dimod.BinaryQuadraticModel({0: 0, 1: 0}, {(0, 1): 1}, 0, dimod.BINARY)) def test_to_numpy_vectors(self): bqm = dimod.BinaryQuadraticModel.from_ising({}, {(0, 1): .5, (2, 3): -1, (0, 3): 1.5}) h, (i, j, values), off = bqm.to_numpy_vectors() self.assertEqual(len(h), len(bqm.linear)) for idx, bias in enumerate(h): self.assertAlmostEqual(bias, bqm.linear[idx]) self.assertEqual(len(i), len(j)) self.assertEqual(len(j), len(values)) self.assertEqual(len(values), len(bqm.quadratic)) for u, v, bias in zip(i, j, values): self.assertIn(u, bqm.adj) self.assertIn(v, bqm.adj[u]) self.assertAlmostEqual(bias, bqm.adj[u][v]) def test_to_numpy_vectors_sorted(self): bqm = dimod.BinaryQuadraticModel.from_ising({}, {(0, 1): .5, (3, 2): -1, (0, 3): 1.5}) h, (i, j, values), off = bqm.to_numpy_vectors(sort_indices=True) np.testing.assert_array_equal(h, [0, 0, 0, 0]) np.testing.assert_array_equal(i, [0, 0, 2]) np.testing.assert_array_equal(j, [1, 3, 3]) np.testing.assert_array_equal(values, [.5, 1.5, -1]) def test_to_numpy_vectors_labels_sorted(self): bqm = dimod.BinaryQuadraticModel.from_ising({}, {('a', 'b'): .5, ('d', 'c'): -1, ('a', 'd'): 1.5}) with self.assertRaises(ValueError): bqm.to_numpy_vectors(sort_indices=True) h, (i, j, values), off = bqm.to_numpy_vectors(sort_indices=True, variable_order=['a', 'b', 'c', 'd']) np.testing.assert_array_equal(h, [0, 0, 0, 0]) np.testing.assert_array_equal(i, [0, 0, 2]) np.testing.assert_array_equal(j, [1, 3, 3]) np.testing.assert_array_equal(values, [.5, 1.5, -1]) def test_from_numpy_vectors(self): h = np.array([-1, 1, 5]) heads = np.array([0, 1]) tails = np.array([1, 2]) values = np.array([-1, +1]) bqm = dimod.BinaryQuadraticModel.from_numpy_vectors(h, (heads, tails, values), 0.0, dimod.SPIN) self.assertEqual(bqm, dimod.BinaryQuadraticModel.from_ising([-1, 1, 5], {(0, 1): -1, (1, 2): 1})) def test_from_numpy_vectors_labels(self): h = np.array([-1, 1, 5]) heads = np.array([0, 1]) tails = np.array([1, 2]) values = np.array([-1, +1]) bqm = dimod.BinaryQuadraticModel.from_numpy_vectors(h, (heads, tails, values), 0.0, dimod.SPIN, variable_order=['a', 'b', 'c']) self.assertEqual(bqm, dimod.BinaryQuadraticModel.from_ising({'a': -1, 'b': 1, 'c': 5}, {('a', 'b'): -1, ('b', 'c'): 1})) def test_energies_cpp(self): num_variables = 25 p = .1 num_samples = 10 linear = np.random.rand(num_variables) row, col = zip(*(pair for pair in itertools.combinations(range(num_variables), 2) if np.random.rand() < p)) quad = np.random.rand(len(row)) h = dict(enumerate(linear)) J = {(u, v): b for u, v, b in zip(row, col, quad)} bqm = dimod.BinaryQuadraticModel(h, J, np.random.rand(), dimod.BINARY) samples = np.random.randint(2, size=(num_samples, num_variables)) def _energies(bqm, samples): row, col = samples.shape energies=[] for r in range(row): sample = {c: samples[r, c] for c in range(col)} energies.append(bqm.energy(sample)) return energies np.testing.assert_array_almost_equal(bqm.energies(samples), _energies(bqm, samples)) def test_energies_misordered(self): h = {0: -2.5, 1: -2.5, 3: -2.5, 4: -5.0, 2: 0.0} J = {(0, 1): 2.5, (0, 3): 2.5, (0, 4): 5.0, (1, 3): 2.5, (1, 4): 5.0, (3, 4): 5.0, (2, 3): -1.0} bqm = dimod.BinaryQuadraticModel(h, J, 10.0, 'SPIN') bqm.relabel_variables(dict(enumerate('abcde')), inplace=True) sample = collections.OrderedDict([('a', -1), ('b', -1), ('e', -1), ('c', -1), ('d', 1)]) en = 10 en += sum(sample[v] * b for v, b in bqm.linear.items()) en += sum(sample[u] * sample[v] * b for (u, v), b in bqm.quadratic.items()) self.assertAlmostEqual(en, bqm.energies(sample)) def test_energies_all_ordering(self): h = {0: -2.5, 1: -2.5, 3: -2.5, 4: -5.0, 2: 0.0} J = {(0, 1): 2.5, (0, 3): 2.5, (0, 4): 5.0, (1, 3): 2.5, (1, 4): 5.0, (3, 4): 5.0, (2, 3): -1.0} bqm = dimod.BinaryQuadraticModel(h, J, 10.0, 'SPIN') for variables in itertools.permutations(bqm.variables, len(bqm)): for config in itertools.product((-1, 1), repeat=len(bqm)): sample = collections.OrderedDict(zip(variables, config)) en = 10 en += sum(sample[v] * b for v, b in h.items()) en += sum(sample[u] * sample[v] * b for (u, v), b in J.items()) self.assertAlmostEqual(en, bqm.energies(sample)) def test_from_qubo(self): Q = {('a', 'a'): 1, ('a', 'b'): -1} bqm = dimod.BinaryQuadraticModel.from_qubo(Q) self.assertEqual(bqm, dimod.BinaryQuadraticModel({'a': 1}, {('a', 'b'): -1}, 0.0, dimod.BINARY)) def test_from_ising(self): h = {'a': 1} J = {('a', 'b'): -1} bqm = dimod.BinaryQuadraticModel.from_ising(h, J) self.assertEqual(bqm, dimod.BinaryQuadraticModel({'a': 1}, {('a', 'b'): -1}, 0.0, dimod.SPIN)) # # h list h = [-1, 1] J = {(0, 1): 1} bqm = dimod.BinaryQuadraticModel.from_ising(h, J, offset=1) self.assertEqual(bqm, dimod.BinaryQuadraticModel({0: -1, 1: 1}, {(0, 1): 1}, 1, dimod.SPIN)) @unittest.skipUnless(_pandas, "No pandas installed") def test_to_pandas_dataframe(self): linear = {'a': -1} quadratic = {('a', 'c'): 1.2, ('b', 'c'): .3, ('a', 'b'): 0} bqm = dimod.BinaryQuadraticModel(linear, quadratic, 0.0, dimod.BINARY) bqm_df = bqm.to_pandas_dataframe() for config in itertools.product((0, 1), repeat=3): sample = dict(zip('abc', config)) sample_series = pd.Series(sample) self.assertAlmostEqual(bqm.energy(sample), sample_series.dot(bqm_df.dot(sample_series))) bqm_new = dimod.BinaryQuadraticModel.from_pandas_dataframe(bqm_df, interactions=quadratic) self.assertAlmostEqual(bqm.linear, bqm_new.linear) for u in bqm.adj: for v in bqm.adj[u]: self.assertAlmostEqual(bqm.adj[u][v], bqm_new.adj[u][v]) # # unlike var names linear = {'a': -1, 16: 0.} quadratic = {('a', 'c'): 1.2, ('b', 'c'): .3, ('a', 'b'): 0} bqm = dimod.BinaryQuadraticModel(linear, quadratic, 0.0, dimod.BINARY) bqm_df = bqm.to_pandas_dataframe() variables = list(bqm_df) for config in itertools.product((0, 1), repeat=4): sample = dict(zip(variables, config)) # Note: explicitly set the index of Series object to be equal (in same order) # to the column list of the DataFrame multiplied later, to avoid sorting of # indexes with mixed types. See https://github.com/dwavesystems/dimod/pull/167. sample_series = pd.Series(data=sample, index=variables) self.assertAlmostEqual(bqm.energy(sample), sample_series.dot(bqm_df.dot(sample_series))) bqm_new = dimod.BinaryQuadraticModel.from_pandas_dataframe(bqm_df, interactions=quadratic) self.assertAlmostEqual(bqm.linear, bqm_new.linear) for u in bqm.adj: for v in bqm.adj[u]: self.assertAlmostEqual(bqm.adj[u][v], bqm_new.adj[u][v]) def test_info(self): bqm = dimod.BinaryQuadraticModel({}, {}, 0.0, dimod.SPIN, tag=1) self.assertIn('tag', bqm.info) self.assertEqual(bqm.info['tag'], 1) new_bqm = bqm.copy() self.assertIn('tag', new_bqm.info) self.assertEqual(new_bqm.info['tag'], 1) another_bqm = dimod.BinaryQuadraticModel({}, {}, 0.0, dimod.SPIN, id=5) bqm.update(another_bqm, ignore_info=False) self.assertIn('tag', bqm.info) self.assertEqual(bqm.info['tag'], 1) self.assertIn('id', bqm.info) self.assertEqual(bqm.info['id'], 5) new_bqm.update(another_bqm, ignore_info=True) self.assertIn('tag', new_bqm.info) self.assertEqual(new_bqm.info['tag'], 1) self.assertNotIn('id', new_bqm.info) def test_empty(self): bqm = dimod.BinaryQuadraticModel.empty(dimod.SPIN) self.assertEqual(bqm, dimod.BinaryQuadraticModel({}, {}, 0.0, dimod.SPIN)) def test_to_coo_string_empty_BINARY(self): bqm = dimod.BinaryQuadraticModel.empty(dimod.BINARY) bqm_str = bqm.to_coo() self.assertIsInstance(bqm_str, str) self.assertEqual(bqm_str, '') def test_to_coo_string_empty_SPIN(self): bqm = dimod.BinaryQuadraticModel.empty(dimod.SPIN) bqm_str = bqm.to_coo() self.assertIsInstance(bqm_str, str) self.assertEqual(bqm_str, '') def test_to_coo_string_typical_SPIN(self): bqm = dimod.BinaryQuadraticModel.from_ising({0: 1.}, {(0, 1): 2, (2, 3): .4}) s = bqm.to_coo() contents = "0 0 1.000000\n0 1 2.000000\n2 3 0.400000" self.assertEqual(s, contents) def test_to_coo_string_typical_BINARY(self): bqm = dimod.BinaryQuadraticModel.from_qubo({(0, 0): 1, (0, 1): 2, (2, 3): .4}) s = bqm.to_coo() contents = "0 0 1.000000\n0 1 2.000000\n2 3 0.400000" self.assertEqual(s, contents) def test_from_coo_file(self): filepath = path.join(path.dirname(path.abspath(__file__)), 'data', 'coo_qubo.qubo') with open(filepath, 'r') as fp: bqm = dimod.BinaryQuadraticModel.from_coo(fp, dimod.BINARY) self.assertEqual(bqm, dimod.BinaryQuadraticModel.from_qubo({(0, 0): -1, (1, 1): -1, (2, 2): -1, (3, 3): -1})) def test_from_coo_string(self): contents = "0 0 1.000000\n0 1 2.000000\n2 3 0.400000" bqm = dimod.BinaryQuadraticModel.from_coo(contents, dimod.SPIN) self.assertEqual(bqm, dimod.BinaryQuadraticModel.from_ising({0: 1.}, {(0, 1): 2, (2, 3): .4})) def test_coo_functional_file_empty_BINARY(self): bqm = dimod.BinaryQuadraticModel.empty(dimod.BINARY) tmpdir = tempfile.mkdtemp() filename = path.join(tmpdir, 'test.qubo') with open(filename, 'w') as file: bqm.to_coo(file) with open(filename, 'r') as file: new_bqm = dimod.BinaryQuadraticModel.from_coo(file, dimod.BINARY) shutil.rmtree(tmpdir) self.assertEqual(bqm, new_bqm) def test_coo_functional_file_empty_SPIN(self): bqm = dimod.BinaryQuadraticModel.empty(dimod.SPIN) tmpdir = tempfile.mkdtemp() filename = path.join(tmpdir, 'test.qubo') with open(filename, 'w') as file: bqm.to_coo(file) with open(filename, 'r') as file: new_bqm = dimod.BinaryQuadraticModel.from_coo(file, dimod.SPIN) shutil.rmtree(tmpdir) self.assertEqual(bqm, new_bqm) def test_coo_functional_file_BINARY(self): bqm = dimod.BinaryQuadraticModel({0: 1.}, {(0, 1): 2, (2, 3): .4}, 0.0, dimod.BINARY) tmpdir = tempfile.mkdtemp() filename = path.join(tmpdir, 'test.qubo') with open(filename, 'w') as file: bqm.to_coo(file) with open(filename, 'r') as file: new_bqm = dimod.BinaryQuadraticModel.from_coo(file, dimod.BINARY) shutil.rmtree(tmpdir) self.assertEqual(bqm, new_bqm) def test_coo_functional_file_SPIN(self): bqm = dimod.BinaryQuadraticModel({0: 1.}, {(0, 1): 2, (2, 3): .4}, 0.0, dimod.SPIN) tmpdir = tempfile.mkdtemp() filename = path.join(tmpdir, 'test.qubo') with open(filename, 'w') as file: bqm.to_coo(file) with open(filename, 'r') as file: new_bqm = dimod.BinaryQuadraticModel.from_coo(file, dimod.SPIN) shutil.rmtree(tmpdir) self.assertEqual(bqm, new_bqm) def test_coo_functional_string_empty_BINARY(self): bqm = dimod.BinaryQuadraticModel.empty(dimod.BINARY) s = bqm.to_coo() new_bqm = dimod.BinaryQuadraticModel.from_coo(s, dimod.BINARY) self.assertEqual(bqm, new_bqm) def test_coo_functional_string_empty_SPIN(self): bqm = dimod.BinaryQuadraticModel.empty(dimod.SPIN) s = bqm.to_coo() new_bqm = dimod.BinaryQuadraticModel.from_coo(s, dimod.SPIN) self.assertEqual(bqm, new_bqm) def test_coo_functional_string_BINARY(self): bqm = dimod.BinaryQuadraticModel({0: 1.}, {(0, 1): 2, (2, 3): .4}, 0.0, dimod.BINARY) s = bqm.to_coo() new_bqm = dimod.BinaryQuadraticModel.from_coo(s, dimod.BINARY) self.assertEqual(bqm, new_bqm) def test_coo_functional_two_digit_integers_string(self): bqm = dimod.BinaryQuadraticModel.from_ising({12: .5, 0: 1}, {(0, 12): .5}) s = bqm.to_coo() new_bqm = dimod.BinaryQuadraticModel.from_coo(s, dimod.SPIN) self.assertEqual(bqm, new_bqm) def test_coo_functional_string_SPIN(self): bqm = dimod.BinaryQuadraticModel({0: 1.}, {(0, 1): 2, (2, 3): .4}, 0.0, dimod.SPIN) s = bqm.to_coo() new_bqm = dimod.BinaryQuadraticModel.from_coo(s, dimod.SPIN) self.assertEqual(bqm, new_bqm) class TestSerialization(unittest.TestCase): def test_from_serializable_empty_v1(self): bqm = dimod.BinaryQuadraticModel.empty(dimod.SPIN) s = {'linear_terms': [], 'quadratic_terms': [], 'offset': 0.0, 'variable_type': 'SPIN', 'version': {'dimod': '0.8.5', 'bqm_schema': '1.0.0'}, 'variable_labels': [], 'info': {}} self.assertEqual(bqm, dimod.BinaryQuadraticModel.from_serializable(s)) def test_from_serializable_v1(self): linear = {'a': -1, 4: 1, ('a', "complex key"): 3} quadratic = {('a', 'c'): 1.2, ('b', 'c'): .3, ('a', 3): -1} bqm = dimod.BinaryQuadraticModel(linear, quadratic, 3, dimod.SPIN) s = {'linear_terms': [{'bias': -1, 'label': 'a'}, {'bias': 1, 'label': 4}, {'bias': 3, 'label': ['a', 'complex key']}, {'bias': 0, 'label': 'c'}, {'bias': 0, 'label': 'b'}, {'bias': 0, 'label': 3}], 'quadratic_terms': [{'bias': 1.2, 'label_head': 'a', 'label_tail': 'c'}, {'bias': -1, 'label_head': 'a', 'label_tail': 3}, {'bias': 0.3, 'label_head': 'c', 'label_tail': 'b'}], 'offset': 3, 'variable_type': 'SPIN', 'version': {'dimod': '0.8.5', 'bqm_schema': '1.0.0'}, 'variable_labels': ['a', 4, ['a', 'complex key'], 'c', 'b', 3], 'info': {}} self.assertEqual(dimod.BinaryQuadraticModel.from_serializable(s), bqm) def test_from_serializable_bytes_empty_v1(self): bqm = dimod.BinaryQuadraticModel.empty(dimod.SPIN) s = {'as_complete': False, 'linear': b'', 'quadratic_vals': b'', 'variable_type': 'SPIN', 'offset': 0.0, 'variable_order': [], 'index_dtype': '<u2', 'bias_dtype': '<f4', 'quadratic_head': b'', 'quadratic_tail': b''} self.assertEqual(bqm, dimod.BinaryQuadraticModel.from_serializable(s)) def test_from_serializable_bytes_v1(self): linear = {'a': -1, 4: 1, ('a', "complex key"): 3} quadratic = {('a', 'c'): 1, ('b', 'c'): 3.0, ('a', 3): -1} bqm = dimod.BinaryQuadraticModel(linear, quadratic, 3, dimod.SPIN) s = {'as_complete': False, 'linear': b'\x00\x00\x80\xbf\x00\x00\x80?\x00\x00@@\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 'quadratic_vals': b'\x00\x00\x80?\x00\x00\x80\xbf\x00\x00@@', 'variable_type': 'SPIN', 'offset': 3.0, 'variable_order': ['a', 4, ('a', 'complex key'), 'c', 'b', 3], 'index_dtype': '<u2', 'bias_dtype': '<f4', 'quadratic_head': b'\x00\x00\x00\x00\x03\x00', 'quadratic_tail': b'\x03\x00\x05\x00\x04\x00'} self.assertEqual(dimod.BinaryQuadraticModel.from_serializable(s), bqm) def test_from_serializable_empty_v2(self): bqm = dimod.BinaryQuadraticModel.empty(dimod.SPIN) s = {'basetype': 'BinaryQuadraticModel', 'type': 'BinaryQuadraticModel', 'version': {'dimod': '0.8.5', 'bqm_schema': '2.0.0'}, 'variable_labels': [], 'variable_type': 'SPIN', 'info': {}, 'offset': 0.0, 'use_bytes': False, 'linear_biases': [], 'quadratic_biases': [], 'quadratic_head': [], 'quadratic_tail': []} self.assertEqual(bqm, dimod.BinaryQuadraticModel.from_serializable(s)) def test_from_serializable_v2(self): linear = {'a': -1, 4: 1, ('a', "complex key"): 3} quadratic = {('a', 'c'): 1, ('b', 'c'): 3.0, ('a', 3): -1} bqm = dimod.BinaryQuadraticModel(linear, quadratic, 3, dimod.SPIN) s = {'basetype': 'BinaryQuadraticModel', 'type': 'BinaryQuadraticModel', 'version': {'dimod': '0.8.5', 'bqm_schema': '2.0.0'}, 'variable_labels': ['a', 4, ('a', 'complex key'), 'c', 'b', 3], 'variable_type': 'SPIN', 'info': {}, 'offset': 3.0, 'use_bytes': False, 'linear_biases': [-1.0, 1.0, 3.0, 0.0, 0.0, 0.0], 'quadratic_biases': [1.0, 3.0, -1.0], 'quadratic_head': [0, 3, 0], 'quadratic_tail': [3, 4, 5]} self.assertEqual(dimod.BinaryQuadraticModel.from_serializable(s), bqm) def test_from_serializable_bytes_empty_v2(self): bqm = dimod.BinaryQuadraticModel.empty(dimod.SPIN) s = {'basetype': 'BinaryQuadraticModel', 'type': 'BinaryQuadraticModel', 'version': {'dimod': '0.8.5', 'bqm_schema': '2.0.0'}, 'variable_labels': [], 'variable_type': 'SPIN', 'info': {}, 'offset': 0.0, 'use_bytes': True, 'linear_biases': b"\x93NUMPY\x01\x00v\x00{'descr': '<f4', 'fortran_order': False, 'shape': (0,), } \n", 'quadratic_biases': b"\x93NUMPY\x01\x00v\x00{'descr': '<f4', 'fortran_order': False, 'shape': (0,), } \n", 'quadratic_head': b"\x93NUMPY\x01\x00v\x00{'descr': '<u2', 'fortran_order': False, 'shape': (0,), } \n", 'quadratic_tail': b"\x93NUMPY\x01\x00v\x00{'descr': '<u2', 'fortran_order': False, 'shape': (0,), } \n"} self.assertEqual(bqm, dimod.BinaryQuadraticModel.from_serializable(s)) def test_from_serializable_bytes_v2(self): linear = {'a': -1, 4: 1, ('a', "complex key"): 3} quadratic = {('a', 'c'): 1, ('b', 'c'): 3.0, ('a', 3): -1} bqm = dimod.BinaryQuadraticModel(linear, quadratic, 3, dimod.SPIN) s = {'basetype': 'BinaryQuadraticModel', 'type': 'BinaryQuadraticModel', 'version': {'dimod': '0.8.5', 'bqm_schema': '2.0.0'}, 'variable_labels': ['a', 4, ('a', 'complex key'), 'c', 'b', 3], 'variable_type': 'SPIN', 'info': {}, 'offset': 3.0, 'use_bytes': True, 'linear_biases': b"\x93NUMPY\x01\x00v\x00{'descr': '<f4', 'fortran_order': False, 'shape': (6,), } \n\x00\x00\x80\xbf\x00\x00\x80?\x00\x00@@\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 'quadratic_biases': b"\x93NUMPY\x01\x00v\x00{'descr': '<f4', 'fortran_order': False, 'shape': (3,), } \n\x00\x00\x80?\x00\x00@@\x00\x00\x80\xbf", 'quadratic_head': b"\x93NUMPY\x01\x00v\x00{'descr': '<u2', 'fortran_order': False, 'shape': (3,), } \n\x00\x00\x03\x00\x00\x00", 'quadratic_tail': b"\x93NUMPY\x01\x00v\x00{'descr': '<u2', 'fortran_order': False, 'shape': (3,), } \n\x03\x00\x04\x00\x05\x00"} self.assertEqual(dimod.BinaryQuadraticModel.from_serializable(s), bqm) def test_functional_empty(self): # round trip bqm = dimod.BinaryQuadraticModel.empty(dimod.SPIN) new = dimod.BinaryQuadraticModel.from_serializable(bqm.to_serializable()) self.assertEqual(bqm, new) def test_functional(self): linear = {'a': -1, 4: 1, ('a', "complex key"): 3} quadratic = {('a', 'c'): 1.5, ('b', 'c'): 3., ('a', 3): -1} bqm = dimod.BinaryQuadraticModel(linear, quadratic, 3, dimod.SPIN) new = dimod.BinaryQuadraticModel.from_serializable(bqm.to_serializable()) self.assertEqual(bqm, new) def test_functional_info(self): linear = {'a': -1, 4: 1, ('a', "complex key"): 3} quadratic = {('a', 'c'): 1.5, ('b', 'c'): 3., ('a', 3): -1} bqm = dimod.BinaryQuadraticModel(linear, quadratic, 3, dimod.SPIN, tag=5) new = dimod.BinaryQuadraticModel.from_serializable(bqm.to_serializable()) self.assertEqual(bqm, new) self.assertEqual(bqm.info, {"tag": 5}) def test_functional_bytes_empty(self): bqm = dimod.BinaryQuadraticModel.empty(dimod.SPIN) new = dimod.BinaryQuadraticModel.from_serializable(bqm.to_serializable(use_bytes=True)) self.assertEqual(bqm, new) def test_functional_bytes(self): linear = {'a': -1, 4: 1, ('a', "complex key"): 3} quadratic = {('a', 'c'): 1.5, ('b', 'c'): 3., ('a', 3): -1} bqm = dimod.BinaryQuadraticModel(linear, quadratic, 3, dimod.SPIN) new = dimod.BinaryQuadraticModel.from_serializable(bqm.to_serializable(use_bytes=True)) self.assertEqual(bqm, new) def test_functional_bytes_info(self): linear = {'a': -1, 4: 1, ('a', "complex key"): 3} quadratic = {('a', 'c'): 1.5, ('b', 'c'): 3., ('a', 3): -1} bqm = dimod.BinaryQuadraticModel(linear, quadratic, 3, dimod.SPIN, tag=5) new = dimod.BinaryQuadraticModel.from_serializable(bqm.to_serializable(use_bytes=True)) self.assertEqual(bqm, new) self.assertEqual(new.info, {"tag": 5}) def test_variable_labels(self): h = {0: 0, 1: 1, np.int64(2): 2, np.float(3): 3, fractions.Fraction(4, 1): 4, fractions.Fraction(5, 2): 5, '6': 6} J = {} bqm = dimod.BinaryQuadraticModel.from_ising(h, J) json.dumps(bqm.to_serializable()) class TestZeroField(unittest.TestCase): # test when there are only quadratic biases def test_one_interaction(self): bqm = dimod.BinaryQuadraticModel({}, {'ab': -1}, 0, dimod.SPIN) self.assertEqual(bqm.linear, {'a': 0, 'b': 0}) self.assertEqual(bqm.adj, {'a': {'b': -1}, 'b': {'a': -1}}) self.assertEqual(set(bqm.linear.keys()), {'a', 'b'}) self.assertEqual(set(bqm.linear.items()), {('a', 0), ('b', 0)}) @unittest.skipUnless(_networkx, "NetworkX is not installed") class TestFromNetworkxGraph(unittest.TestCase): def test_empty(self): G = nx.Graph() G.vartype = 'SPIN' bqm = dimod.BinaryQuadraticModel.from_networkx_graph(G) self.assertEqual(len(bqm), 0) self.assertIs(bqm.vartype, dimod.SPIN) def test_no_biases(self): G = nx.complete_graph(5) G.vartype = 'BINARY' bqm = dimod.BinaryQuadraticModel.from_networkx_graph(G) self.assertIs(bqm.vartype, dimod.BINARY) self.assertEqual(set(bqm.variables), set(range(5))) for u, v in itertools.combinations(range(5), 2): self.assertEqual(bqm.adj[u][v], 0) self.assertEqual(bqm.linear[v], 0) self.assertEqual(len(bqm.quadratic), len(G.edges)) def test_functional(self): bqm = dimod.BinaryQuadraticModel.from_ising({'a': .5}, {'bc': 1, 'cd': -4}, offset=6) new = dimod.BinaryQuadraticModel.from_networkx_graph(bqm.to_networkx_graph()) self.assertEqual(bqm, new) class TestIsWriteable(unittest.TestCase): def test_offset(self): bqm = dimod.BinaryQuadraticModel.empty(dimod.SPIN) bqm.is_writeable = False with self.assertRaises(WriteableError): bqm.offset = 5 def test_info(self): bqm = dimod.BinaryQuadraticModel.empty(dimod.SPIN) bqm.is_writeable = False with self.assertRaises(WriteableError): bqm.info['a'] = 1 def test_biases(self): bqm = dimod.BinaryQuadraticModel.empty(dimod.SPIN) bqm.is_writeable = False with self.assertRaises(WriteableError): bqm.linear['a'] = 5 with self.assertRaises(WriteableError): bqm.add_variable('a', 5) with self.assertRaises(WriteableError): bqm.add_interaction('a', 'b', 5) def test_already_existing_biases(self): bqm = dimod.BinaryQuadraticModel.from_ising({}, {'ab': -1}) bqm.is_writeable = False with self.assertRaises(WriteableError): bqm.add_variable('a', 1) with self.assertRaises(WriteableError): bqm.add_interaction('a', 'b', 1) with self.assertRaises(WriteableError): bqm.linear['a'] += 6 with self.assertRaises(WriteableError): bqm.adj['a']['b'] += 5
38.487069
262
0.567286
11,380
89,290
4.366257
0.042531
0.119244
0.105941
0.054742
0.818789
0.779524
0.746176
0.712265
0.683787
0.6571
0
0.038172
0.270321
89,290
2,319
263
38.503665
0.724464
0.049636
0
0.626701
0
0.005833
0.047698
0.007136
0
0
0
0
0.298769
1
0.073234
false
0
0.012314
0
0.090732
0
0
0
0
null
0
0
0
1
1
1
1
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
5
a788569f294a04ff0c79d5ad4a1124b69627df24
8,749
py
Python
spdx/parsers/validations.py
quaresmajose/tools-python
53c917a1a2491a373efa23e4ef8570b5e863fabc
[ "Apache-2.0" ]
74
2015-12-25T09:43:18.000Z
2022-03-30T00:23:30.000Z
spdx/parsers/validations.py
quaresmajose/tools-python
53c917a1a2491a373efa23e4ef8570b5e863fabc
[ "Apache-2.0" ]
184
2016-11-23T15:57:16.000Z
2022-03-15T05:25:59.000Z
spdx/parsers/validations.py
quaresmajose/tools-python
53c917a1a2491a373efa23e4ef8570b5e863fabc
[ "Apache-2.0" ]
98
2015-12-13T12:20:34.000Z
2022-03-18T15:28:35.000Z
# Copyright (c) 2014 Ahmed H. Ismail # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # http://www.apache.org/licenses/LICENSE-2.0 # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import re import rdflib from spdx import creationinfo from spdx import utils from spdx import document def validate_is_free_form_text(value, optional=False): TEXT_RE = re.compile(r"<text>(.|\n)*</text>", re.UNICODE) if value is None: return optional else: return TEXT_RE.match(value) is not None def validate_tool_name(value, optional=False): striped_value = value.strip() if optional: if len(striped_value) == 0: return True else: return False else: return not (len(striped_value) == 0) def validate_person_name(value, optional=False): return validate_tool_name(value, optional) def validate_org_name(value, optional=False): return validate_tool_name(value, optional) def validate_data_lics(value): return value == "CC0-1.0" def validate_doc_name(value, optional=False): return validate_tool_name(value, optional) def validate_pkg_supplier(value, optional=False): if optional and value is None: return True elif isinstance( value, (utils.NoAssert, creationinfo.Person, creationinfo.Organization) ): return True else: return False def validate_pkg_originator(value, optional=False): return validate_pkg_supplier(value, optional) def validate_pkg_homepage(value, optional=False): if value is None: return optional elif isinstance(value, (str, utils.NoAssert, utils.SPDXNone)): return True else: return False def validate_pkg_cr_text(value, optional=False): if isinstance(value, (utils.NoAssert, utils.SPDXNone)): return True elif validate_is_free_form_text(value, optional): return True elif value is None: return optional else: return False def validate_pkg_summary(value, optional=False): return validate_is_free_form_text(value, optional) def validate_pkg_desc(value, optional=False): return validate_is_free_form_text(value, optional) def validate_pkg_comment(value, optional=False): return validate_is_free_form_text(value, optional) def validate_pkg_attribution_text(value, optional=False): return validate_is_free_form_text(value, optional) def validate_file_attribution_text(value, optional=False): return validate_is_free_form_text(value, optional) def validate_snippet_attribution_text(value, optional=False): return validate_is_free_form_text(value, optional) def validate_pkg_ext_ref_category(value, optional=False): if value.upper() in ["SECURITY", "OTHER", "PACKAGE-MANAGER"]: return True else: return False def validate_pkg_ext_ref_type(value, optional=False): if re.match(r"^[A-Za-z0-9.\-]+$", value) is not None: return True else: return False def validate_pkg_ext_ref_comment(value, optional=False): return validate_is_free_form_text(value, optional) def validate_doc_comment(value, optional=False): return validate_is_free_form_text(value, optional) def validate_doc_spdx_id(value, optional=False): if value is None: return optional elif value.endswith("#SPDXRef-DOCUMENT"): return True else: return False def validate_doc_namespace(value, optional=False): if value is None: return optional elif ( value.startswith("http://") or value.startswith("https://") or value.startswith("ftp://") ) and ("#" not in value): return True else: return False def validate_creator(value, optional=False): if value is None: return optional else: return isinstance(value, creationinfo.Creator) def validate_creation_comment(value, optional=False): return validate_is_free_form_text(value, optional) def validate_reviewer(value, optional=False): return validate_creator(value, optional) def validate_review_comment(value, optional=False): return validate_is_free_form_text(value, optional) def validate_annotator(value, optional=False): return validate_creator(value, optional) def validate_annotation_comment(value, optional=False): return validate_is_free_form_text(value, optional) def validate_annotation_type(value, optional=False): value = value.strip() if value == "REVIEW" or value == "OTHER": return True else: return False def validate_relationship_comment(value, optional=False): return validate_is_free_form_text(value, optional) def validate_pkg_spdx_id(value, optional=False): value = value.split("#")[-1] TEXT_RE = re.compile(r"SPDXRef-([A-Za-z0-9\.\-]+)", re.UNICODE) if value is None: return optional else: return TEXT_RE.match(value) is not None def validate_pkg_files_analyzed(value, optional=False): if value in ["True", "true", "False", "false", True, False]: return True else: return optional def validate_pkg_src_info(value, optional=False): return validate_is_free_form_text(value, optional) def validate_pkg_lics_comment(value, optional=False): return validate_is_free_form_text(value, optional) def validate_file_spdx_id(value, optional=False): value = value.split("#")[-1] TEXT_RE = re.compile(r"SPDXRef-([A-Za-z0-9.\-]+)", re.UNICODE) if value is None: return optional else: return TEXT_RE.match(value) is not None def validate_file_comment(value, optional=False): return validate_is_free_form_text(value, optional) def validate_file_lics_comment(value, optional=False): return validate_is_free_form_text(value, optional) def validate_file_cpyright(value, optional=False): if isinstance(value, (utils.NoAssert, utils.SPDXNone)): return True elif validate_is_free_form_text(value, optional): return True else: return False def validate_lics_from_file(value, optional=False): if value is None: return optional elif isinstance(value, (document.License, utils.SPDXNone, utils.NoAssert)): return True else: return False def validate_file_notice(value, optional=False): return validate_is_free_form_text(value, optional) def validate_lics_conc(value, optional=False): if value is None: return optional elif isinstance(value, (utils.NoAssert, utils.SPDXNone, document.License)): return True else: return False def validate_file_lics_in_file(value, optional=False): if value is None: return optional elif isinstance(value, (utils.NoAssert, utils.SPDXNone, document.License)): return True else: return False def validate_extracted_lic_id(value, optional=False): if value is None: return optional else: return value.startswith("LicenseRef-") def validate_extr_lic_name(value, optional=False): if value is None: return optional else: return isinstance(value, (str, utils.NoAssert, rdflib.Literal)) def validate_snippet_spdx_id(value, optional=False): value = value.split("#")[-1] if re.match(r"^SPDXRef[A-Za-z0-9.\-]+$", value) is not None: return True else: return False def validate_snip_comment(value, optional=False): return validate_is_free_form_text(value, optional) def validate_snippet_copyright(value, optional=False): if validate_is_free_form_text(value, optional): return True elif isinstance(value, (utils.NoAssert, utils.SPDXNone)): return True elif value is None: return optional else: return False def validate_snip_lic_comment(value, optional=False): return validate_is_free_form_text(value, optional) def validate_snip_file_spdxid(value, optional=False): if ( re.match(r"(DocumentRef[A-Za-z0-9.\-]+:){0,1}SPDXRef[A-Za-z0-9.\-]+", value) is not None ): return True else: return False def validate_snip_lics_info(value, optional=False): if value is None: return optional elif isinstance(value, (utils.NoAssert, utils.SPDXNone, document.License)): return True else: return False
26.03869
84
0.705452
1,167
8,749
5.089974
0.137104
0.168519
0.148485
0.10101
0.762626
0.714983
0.709259
0.66431
0.643771
0.630135
0
0.004304
0.203338
8,749
335
85
26.116418
0.84792
0.06355
0
0.600897
0
0.004484
0.034833
0.016011
0
0
0
0
0.044843
1
0.224215
false
0
0.022422
0.116592
0.641256
0
0
0
0
null
0
0
0
0
1
1
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
1
0
0
0
1
0
0
0
5
a79d90a812886d926d234dc998252b71ed724cf5
52
py
Python
lib/socket/exceptions.py
mrcrgl/gge-storage
a8471624c1a865d4f7eeb00415bd4cd2a91ea310
[ "MIT" ]
null
null
null
lib/socket/exceptions.py
mrcrgl/gge-storage
a8471624c1a865d4f7eeb00415bd4cd2a91ea310
[ "MIT" ]
1
2015-04-09T15:58:19.000Z
2015-04-14T06:37:02.000Z
lib/socket/exceptions.py
mrcrgl/gge-storage
a8471624c1a865d4f7eeb00415bd4cd2a91ea310
[ "MIT" ]
null
null
null
class DeadConnectionException(Exception): pass
13
41
0.788462
4
52
10.25
1
0
0
0
0
0
0
0
0
0
0
0
0.153846
52
4
42
13
0.931818
0
0
0
0
0
0
0
0
0
0
0
0
1
0
true
0.5
0
0
0.5
0
1
0
1
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
1
1
0
0
0
0
0
5
38f379d29289c0ebf5a4572e5d30e6ee3a5f582d
174
py
Python
ipc_mngr/__init__.py
justengel/ipc_mngr
3883857e701600105cba93473dd7731ff55d1bad
[ "MIT" ]
null
null
null
ipc_mngr/__init__.py
justengel/ipc_mngr
3883857e701600105cba93473dd7731ff55d1bad
[ "MIT" ]
null
null
null
ipc_mngr/__init__.py
justengel/ipc_mngr
3883857e701600105cba93473dd7731ff55d1bad
[ "MIT" ]
null
null
null
from .com_mngr import IPCError, MY_IP, get_local_addrs, Listener, Client from .streamer import Streamer, StreamClient from .cmd_parser import CommandParser, CommandInterface
43.5
72
0.844828
23
174
6.173913
0.782609
0
0
0
0
0
0
0
0
0
0
0
0.103448
174
3
73
58
0.910256
0
0
0
0
0
0
0
0
0
0
0
0
1
0
true
0
1
0
1
0
1
0
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
1
0
1
0
1
0
0
5
ac02f36b31e335d869ea2082af193994ad23c8d4
188
py
Python
playground/tablemobilenumberes.py
sagarsetru/fiberviewCameraSimulation
a3f72158580e0d588bf8f2ed0792cb1c2d7e478b
[ "MIT" ]
null
null
null
playground/tablemobilenumberes.py
sagarsetru/fiberviewCameraSimulation
a3f72158580e0d588bf8f2ed0792cb1c2d7e478b
[ "MIT" ]
null
null
null
playground/tablemobilenumberes.py
sagarsetru/fiberviewCameraSimulation
a3f72158580e0d588bf8f2ed0792cb1c2d7e478b
[ "MIT" ]
null
null
null
table = {'Sagar': 9142756069, 'Suhas': 7185789224, 'Mom': 3472377887, 'Dad': 9176089335} for name, phone in table.items() print "Name: {0:10} ==> Mobile: {1:10d}".format(name, phone)
47
89
0.648936
25
188
4.88
0.84
0.147541
0
0
0
0
0
0
0
0
0
0.285714
0.143617
188
4
90
47
0.47205
0
0
0
0
0
0.258065
0
0
0
0
0
0
0
null
null
0
0
null
null
0.333333
1
0
0
null
0
0
0
0
0
0
0
0
0
0
1
0
0
1
0
0
1
0
0
0
0
0
0
0
null
0
0
0
0
1
0
0
0
0
0
0
0
0
5
3bc0ccfd1620f8e518beea8484320826b89cbfc9
262
py
Python
sparepo/__init__.py
JBorrow/sparepo
03594c1d45b5838d06b8207e15597cb98217b9c2
[ "MIT" ]
1
2021-10-04T01:03:59.000Z
2021-10-04T01:03:59.000Z
sparepo/__init__.py
JBorrow/sparepo
03594c1d45b5838d06b8207e15597cb98217b9c2
[ "MIT" ]
1
2021-10-03T12:39:59.000Z
2021-10-04T12:50:33.000Z
sparepo/__init__.py
JBorrow/sparepo
03594c1d45b5838d06b8207e15597cb98217b9c2
[ "MIT" ]
1
2021-10-02T22:52:29.000Z
2021-10-02T22:52:29.000Z
""" SpAREPO: Spatial Loading for AREPO. """ from sparepo.build import create_hashtable from sparepo.particle_types import ParticleType from sparepo.read import SpatialLoader, FullLoader from sparepo.regions import CartesianSpatialRegion, SphericalSpatialRegion
29.111111
74
0.847328
29
262
7.586207
0.655172
0.2
0
0
0
0
0
0
0
0
0
0
0.099237
262
8
75
32.75
0.932203
0.133588
0
0
0
0
0
0
0
0
0
0
0
1
0
true
0
1
0
1
0
1
0
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
1
0
1
0
1
0
0
5
3be67d5d94f40328d36d287bc040db2ea82cd7d6
100
py
Python
src/__init__.py
johannchopin/htw-m1-softwarearchitecture
85256c5643b0b8b3016f007ca56ade37e048c683
[ "Apache-2.0" ]
null
null
null
src/__init__.py
johannchopin/htw-m1-softwarearchitecture
85256c5643b0b8b3016f007ca56ade37e048c683
[ "Apache-2.0" ]
1
2021-01-20T21:48:22.000Z
2021-01-20T21:50:42.000Z
src/__init__.py
johannchopin/htw-m1-softwarearchitecture
85256c5643b0b8b3016f007ca56ade37e048c683
[ "Apache-2.0" ]
null
null
null
from .batch import CassandraWrapper from .entry import Email from .EmailChecker import EmailChecker
25
38
0.85
12
100
7.083333
0.583333
0
0
0
0
0
0
0
0
0
0
0
0.12
100
3
39
33.333333
0.965909
0
0
0
0
0
0
0
0
0
0
0
0
1
0
true
0
1
0
1
0
1
0
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
1
0
1
0
1
0
0
5
3be8e0e473c40cb11ce7331096f5f95dfe4acb0b
217
py
Python
interfaces/python/bable_interface/models/__init__.py
iotile/baBLE-linux
faedca2c70b7fe91ea8ae0c3d8aff6bf843bd9db
[ "MIT" ]
13
2018-07-04T16:35:37.000Z
2021-03-03T10:41:07.000Z
interfaces/python/bable_interface/models/__init__.py
iotile/baBLE
faedca2c70b7fe91ea8ae0c3d8aff6bf843bd9db
[ "MIT" ]
11
2018-06-01T20:32:32.000Z
2019-01-21T17:03:47.000Z
interfaces/python/bable_interface/models/__init__.py
iotile/baBLE-linux
faedca2c70b7fe91ea8ae0c3d8aff6bf843bd9db
[ "MIT" ]
null
null
null
from .bable_exception import BaBLEException from .characteristic import Characteristic from .controller import Controller from .device import Device from .packet import Packet, PacketUuid from .service import Service
31
43
0.852535
26
217
7.076923
0.423077
0
0
0
0
0
0
0
0
0
0
0
0.115207
217
6
44
36.166667
0.958333
0
0
0
0
0
0
0
0
0
0
0
0
1
0
true
0
1
0
1
0
1
0
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
1
0
1
0
1
0
0
5
ce3f41d155bde919533a9e635e9d0f95ef2c56d9
1,800
py
Python
vylint/tests/accumulator/test_accumulator.py
sambacha/vylint
a2c6c3d7ce446f0c18e567aa4bf881f8ee2252ef
[ "Apache-2.0" ]
null
null
null
vylint/tests/accumulator/test_accumulator.py
sambacha/vylint
a2c6c3d7ce446f0c18e567aa4bf881f8ee2252ef
[ "Apache-2.0" ]
null
null
null
vylint/tests/accumulator/test_accumulator.py
sambacha/vylint
a2c6c3d7ce446f0c18e567aa4bf881f8ee2252ef
[ "Apache-2.0" ]
null
null
null
import pytest from web3 import Web3 N = [ 80946312435742893162269182027286168982458258986392013602913524631232064034484, 67809251382290146368857461934422217270315634662502738506896957186896411395852, 32432476295143674333647052353281846215904064919090353517923267849072571109732, 97985650512097174582438390172123096127310964532713997866929284351410268860683, 13154304360276038533660786005217728908375598918815057353003252289874621170548, 60855634196609600593208184699147768610531128140436496744405829196935973449422, 2514693881447445838798831742432506661944046185460035613540755019117283127655, 79405065668804699346261014168718981824460403581712392556422464031573372741133, ] N_HEX = 0xB2F5FD3F9F0917112CE42F8BF87ED676E15258BE443F36DEAFB0B69BDE2496B495EAAD1B01CAD84271B014E96F79386C636D348516DA74A68A8C70FBA882870C47B4218D8F49186DDF72727B9D80C21911C3E337C6E407FFB47C2F2767B0D164D8A1E9AF95F6481BF8D9EDFB2E3904B2529268C460256FAFD0A677D29898F10B1D15128A695839FC08EDD584E8335615B1D1D7277BE65C532DCA92DDC7050374868B117EA9154914EF9292B8443F13696E4FAD50DED6BD90E5A6F7ED33BE2ECE31C6DD7A4253EE6CDC56787DDD1D5CD776614022DB87D03BB22F23285B5A3167AF8DACABBEA40004471337D3781E8C5CCA0EA5E27799B510E4EF938C61CAA60D G = 3 @pytest.fixture def c(get_contract): with open("../contracts/accumulator/RSAAccumulator.vy") as f: code = f.read() # FIXME: eth.exceptions.OutOfGas: Contract code size exceeds EIP170 limit of 24577. c = get_contract(code, N) return c def test_init_state(c): assert uint256_list_to_int(c.N) == N_HEX assert uint256_list_to_int(c.initialAccumulator) == G assert uint256_list_to_int(c.accumulator) == G def uint256_list_to_int(l): out = 0 for i in range(len(l)): out += l[i] * 2 ** (32 * i) return out
45
522
0.854444
108
1,800
14.074074
0.574074
0.028947
0.034211
0.042105
0.045395
0.045395
0
0
0
0
0
0.596415
0.101111
1,800
39
523
46.153846
0.343016
0.045
0
0
0
0
0.024461
0.024461
0
1
0.299359
0.025641
0.103448
1
0.103448
false
0
0.068966
0
0.241379
0
0
0
1
null
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
1
0
0
0
0
0
0
0
null
1
0
1
0
0
0
0
0
0
0
0
0
0
5
cbf5595787f4d252d427043bd1a7665062edddd8
40
py
Python
tests/__init__.py
AstraZeneca/jazzy
d06a5848165d2a256b52b75c3365715da0d36c4d
[ "Apache-2.0" ]
null
null
null
tests/__init__.py
AstraZeneca/jazzy
d06a5848165d2a256b52b75c3365715da0d36c4d
[ "Apache-2.0" ]
null
null
null
tests/__init__.py
AstraZeneca/jazzy
d06a5848165d2a256b52b75c3365715da0d36c4d
[ "Apache-2.0" ]
null
null
null
"""Test suite for the jazzy package."""
20
39
0.675
6
40
4.5
1
0
0
0
0
0
0
0
0
0
0
0
0.15
40
1
40
40
0.794118
0.825
0
null
0
null
0
0
null
0
0
0
null
1
null
true
0
0
null
null
null
1
1
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
1
0
0
0
0
0
0
null
0
0
0
0
0
0
1
0
0
0
0
0
0
5
021868c428c104ed173ddc2bd157bddf5fff2a93
203
py
Python
hatfieldcmr/ingest/__init__.py
bcgov/nr_rfc_processing
7e414b97a29ed5bae8ba3c6decea39733be9a2db
[ "Apache-2.0" ]
null
null
null
hatfieldcmr/ingest/__init__.py
bcgov/nr_rfc_processing
7e414b97a29ed5bae8ba3c6decea39733be9a2db
[ "Apache-2.0" ]
6
2021-02-08T16:47:02.000Z
2022-01-30T21:58:18.000Z
hatfieldcmr/ingest/__init__.py
bcgov/rfc_processing
7e414b97a29ed5bae8ba3c6decea39733be9a2db
[ "Apache-2.0" ]
2
2021-02-22T19:13:26.000Z
2021-05-03T23:58:56.000Z
from .name import format_object_name from .push import AbstractStorageClientWrapper #from .gcs import GCSClientWrapper from .local import LocalStorageWrapper from .ingest_exception import IngestException
40.6
46
0.876847
23
203
7.608696
0.608696
0
0
0
0
0
0
0
0
0
0
0
0.093596
203
5
47
40.6
0.951087
0.162562
0
0
0
0
0
0
0
0
0
0
0
1
0
true
0
1
0
1
0
1
0
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
1
0
1
0
1
0
0
5
02793314a095e6d67f30ae9a4d6ea3444d146006
21
py
Python
edsnlp/pipelines/ner/scores/tnm/__init__.py
aphp/edsnlp
a39ea23ff193764a8b1a42c5de463cd43202c134
[ "BSD-3-Clause" ]
32
2022-03-08T16:45:09.000Z
2022-03-31T15:21:00.000Z
edsnlp/pipelines/ner/scores/tnm/__init__.py
aphp/edsnlp
a39ea23ff193764a8b1a42c5de463cd43202c134
[ "BSD-3-Clause" ]
19
2022-03-09T11:44:43.000Z
2022-03-31T14:32:06.000Z
edsnlp/pipelines/ner/scores/tnm/__init__.py
aphp/edsnlp
a39ea23ff193764a8b1a42c5de463cd43202c134
[ "BSD-3-Clause" ]
1
2022-03-11T16:14:21.000Z
2022-03-11T16:14:21.000Z
from .tnm import TNM
10.5
20
0.761905
4
21
4
0.75
0
0
0
0
0
0
0
0
0
0
0
0.190476
21
1
21
21
0.941176
0
0
0
0
0
0
0
0
0
0
0
0
1
0
true
0
1
0
1
0
1
1
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
1
0
1
0
0
0
0
5
02797c49bb9f978eea068fd9fc4700b28b217434
110
py
Python
1 Python Basics/7_dictionary.py
narayanants/python-mega-course
2ba2980ab21dfbed5f86f00695559f7831b5c566
[ "MIT" ]
null
null
null
1 Python Basics/7_dictionary.py
narayanants/python-mega-course
2ba2980ab21dfbed5f86f00695559f7831b5c566
[ "MIT" ]
null
null
null
1 Python Basics/7_dictionary.py
narayanants/python-mega-course
2ba2980ab21dfbed5f86f00695559f7831b5c566
[ "MIT" ]
null
null
null
student_names = {"Raj":8.2,"Madhan":9.0,"Mani":10.0} print(student_names.keys()) print(student_names.values())
36.666667
52
0.718182
19
110
4
0.684211
0.473684
0.447368
0
0
0
0
0
0
0
0
0.066038
0.036364
110
3
53
36.666667
0.650943
0
0
0
0
0
0.117117
0
0
0
0
0
0
1
0
false
0
0
0
0
0.666667
1
0
0
null
1
1
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
0
0
0
0
0
1
0
5
027bf6c35655c800e5419f33512ac85927e37da5
233
py
Python
config.py
pceuropa/PyEmailServerDown
6252d440148d3438b81bc3d852411c0756c553bd
[ "MIT" ]
12
2017-02-07T23:55:48.000Z
2021-01-22T05:09:44.000Z
config.py
pceuropa/PyEmailServerDown
6252d440148d3438b81bc3d852411c0756c553bd
[ "MIT" ]
null
null
null
config.py
pceuropa/PyEmailServerDown
6252d440148d3438b81bc3d852411c0756c553bd
[ "MIT" ]
1
2022-02-14T17:37:58.000Z
2022-02-14T17:37:58.000Z
sites = [ 'https://yii2-menu.pceuropa.net/', 'https://pceuropa.net', ] smtp = { 'server': 'smtp@example.com:587', 'login': 'info@example.com', 'password': 'pass', 'From': 'info@example.com', 'to': 'info@example.com', }
15.533333
35
0.587983
29
233
4.724138
0.586207
0.291971
0.306569
0
0
0
0
0
0
0
0
0.020101
0.145923
233
14
36
16.642857
0.668342
0
0
0
0
0
0.635193
0
0
0
0
0
0
1
0
false
0.090909
0
0
0
0
1
0
0
null
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
null
0
0
0
0
0
0
0
1
0
0
0
0
0
5
5a0e30f4bacee52e023a17f43a2e29a631b416df
43
py
Python
tests/__init__.py
iacopy/coveragepy
2f4b4431cbb561aed3ade025da2720a670ba2dd2
[ "Apache-2.0" ]
2
2021-03-29T19:55:15.000Z
2021-11-15T12:30:19.000Z
coverage-3.7.1/tests/__init__.py
I-Valchev/UrPas
7babb5208fab6975891fba440e633cc9ad6e8718
[ "Apache-2.0" ]
null
null
null
coverage-3.7.1/tests/__init__.py
I-Valchev/UrPas
7babb5208fab6975891fba440e633cc9ad6e8718
[ "Apache-2.0" ]
null
null
null
"""Automated tests. Run with nosetests."""
21.5
42
0.697674
5
43
6
1
0
0
0
0
0
0
0
0
0
0
0
0.116279
43
1
43
43
0.789474
0.837209
0
null
0
null
0
0
null
0
0
0
null
1
null
true
0
0
null
null
null
1
1
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
1
0
0
0
0
0
0
null
0
0
0
0
0
0
1
0
0
0
0
0
0
5
5a831929832eac5124bed2fb7a33b6a4c64a5c05
282
py
Python
python/django/app/views.py
mattiapenati/web-frameworks
44c4df8e4529ae187629ace47886aba679a52545
[ "MIT" ]
5,710
2018-08-02T12:26:18.000Z
2022-03-29T15:54:24.000Z
python/django/app/views.py
mattiapenati/web-frameworks
44c4df8e4529ae187629ace47886aba679a52545
[ "MIT" ]
2,573
2018-08-01T14:29:35.000Z
2022-03-29T09:58:21.000Z
python/django/app/views.py
mattiapenati/web-frameworks
44c4df8e4529ae187629ace47886aba679a52545
[ "MIT" ]
721
2018-08-01T17:51:20.000Z
2022-03-28T15:56:31.000Z
from django.http import HttpResponse from django.views.decorators.csrf import csrf_exempt def index(request): return HttpResponse(status=200) def get_user(request, id): return HttpResponse(id) @csrf_exempt def create_user(request): return HttpResponse(status=200)
17.625
52
0.776596
38
282
5.657895
0.5
0.251163
0.12093
0.288372
0.316279
0
0
0
0
0
0
0.024793
0.141844
282
15
53
18.8
0.863636
0
0
0.222222
0
0
0
0
0
0
0
0
0
1
0.333333
false
0
0.222222
0.333333
0.888889
0
0
0
0
null
1
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
1
0
0
0
1
1
0
0
5
ce8c875c5760013d21c1678ddb3df40c3166fbc0
424
py
Python
plastex/plasTeX/Base/LaTeX/Alignment.py
lisiynos/lisiynos.github.io
5900ee6ab0055a8047dd2b54b8667d05f3a145c2
[ "MIT" ]
1
2019-03-02T17:20:25.000Z
2019-03-02T17:20:25.000Z
plastex/plasTeX/Base/LaTeX/Alignment.py
lisiynos/lisiynos.github.io
5900ee6ab0055a8047dd2b54b8667d05f3a145c2
[ "MIT" ]
null
null
null
plastex/plasTeX/Base/LaTeX/Alignment.py
lisiynos/lisiynos.github.io
5900ee6ab0055a8047dd2b54b8667d05f3a145c2
[ "MIT" ]
null
null
null
#!/usr/bin/env python """ """ from plasTeX import Command, Environment class center(Environment): blockType = True class centering(center): blockType = True class flushleft(Environment): blockType = True class raggedright(flushleft): blockType = True class flushright(Environment): blockType = True class raggedleft(flushright): blockType = True class raggedbottom(Environment): pass
14.133333
40
0.714623
43
424
7.046512
0.465116
0.257426
0.356436
0.287129
0
0
0
0
0
0
0
0
0.193396
424
29
41
14.62069
0.885965
0.04717
0
0.4
0
0
0
0
0
0
0
0
0
1
0
false
0.066667
0.066667
0
0.933333
0
0
0
0
null
1
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
0
1
0
0
1
0
0
5
ce8cecd83197601fb7e410cebad22acb90ec0c29
94
py
Python
app/logic/gitrepo/controllers/__init__.py
imvu/bluesteel
ab52133249a693b3cd2d8593c5d47408a3b0fce6
[ "MIT" ]
10
2017-01-13T06:28:04.000Z
2020-11-18T13:00:26.000Z
app/logic/gitrepo/controllers/__init__.py
imvu/bluesteel
ab52133249a693b3cd2d8593c5d47408a3b0fce6
[ "MIT" ]
null
null
null
app/logic/gitrepo/controllers/__init__.py
imvu/bluesteel
ab52133249a693b3cd2d8593c5d47408a3b0fce6
[ "MIT" ]
2
2018-03-29T14:10:53.000Z
2019-11-20T08:21:57.000Z
""" Automatic file """ from app.logic.gitrepo.controllers.GitController import GitController
23.5
69
0.797872
10
94
7.5
0.9
0
0
0
0
0
0
0
0
0
0
0
0.095745
94
3
70
31.333333
0.882353
0.148936
0
0
0
0
0
0
0
0
0
0
0
1
0
true
0
1
0
1
0
1
0
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
1
0
1
0
1
0
0
5
cebdca9e4f290cae8598a977c92083bdcc178162
25
py
Python
tests.py
calebschmidt/superfluid
8328c51b7f3447bb3b5628d2e2fbeffa42ed68f8
[ "MIT" ]
null
null
null
tests.py
calebschmidt/superfluid
8328c51b7f3447bb3b5628d2e2fbeffa42ed68f8
[ "MIT" ]
null
null
null
tests.py
calebschmidt/superfluid
8328c51b7f3447bb3b5628d2e2fbeffa42ed68f8
[ "MIT" ]
null
null
null
# Placeholder for now...
12.5
24
0.68
3
25
5.666667
1
0
0
0
0
0
0
0
0
0
0
0
0.16
25
1
25
25
0.809524
0.88
0
null
0
null
0
0
null
0
0
0
null
1
null
true
0
0
null
null
null
1
1
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
1
0
0
0
0
0
0
null
0
0
0
0
0
0
1
0
0
0
0
0
0
5
cec324bf28673f71040fb509df5723e50a2f69af
44
py
Python
tests/start_server.py
joshijayesh/conplyent
7b73b91b1000e23bd46369c769271ef6df63e1d6
[ "MIT" ]
null
null
null
tests/start_server.py
joshijayesh/conplyent
7b73b91b1000e23bd46369c769271ef6df63e1d6
[ "MIT" ]
1
2019-03-15T15:20:11.000Z
2019-03-28T08:21:06.000Z
tests/start_server.py
joshijayesh/conplyent
7b73b91b1000e23bd46369c769271ef6df63e1d6
[ "MIT" ]
1
2021-09-03T14:34:46.000Z
2021-09-03T14:34:46.000Z
import conplyent conplyent.server.start()
8.8
24
0.795455
5
44
7
0.8
0
0
0
0
0
0
0
0
0
0
0
0.113636
44
4
25
11
0.897436
0
0
0
0
0
0
0
0
0
0
0
0
1
0
true
0
0.5
0
0.5
0
1
1
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
1
0
1
0
0
0
0
5
cecb3d012291bf9955abb7c90f000a31aec6e212
706
py
Python
models/__init__.py
theshanky/Fingerprint-Liveness
4a303cc5043e8aef1bea59b581cf2943b773b97f
[ "MIT" ]
1
2020-07-10T08:50:23.000Z
2020-07-10T08:50:23.000Z
models/__init__.py
theshanky/Fingerprint-Liveness
4a303cc5043e8aef1bea59b581cf2943b773b97f
[ "MIT" ]
null
null
null
models/__init__.py
theshanky/Fingerprint-Liveness
4a303cc5043e8aef1bea59b581cf2943b773b97f
[ "MIT" ]
null
null
null
from .BasicModule import MyVggNet11 from .BasicModule import MyVggNet13 from .BasicModule import MyVggNet16 from .BasicModule import MyVggNet19 from .BasicModule import MyresNet18 from .BasicModule import MyresNet34 from .BasicModule import MyresNet50 from .BasicModule import MyInceptionV3 from .BasicModule import MydenseNet121 from .BasicModule import MydenseNet161 from .BasicModule import MydenseNet169 from .BasicModule import MydenseNet201 from .BasicModule import MyseNet1_0 from .BasicModule import MyseNet1_1 from .BasicModule import Myxception from .BasicModule import MydetNet59 from .BasicModule import MyMobilenet from .BasicModule import MynasNet from .BasicModule import MultiscaleresNet18
35.3
43
0.865439
78
706
7.807692
0.294872
0.46798
0.655172
0.095238
0
0
0
0
0
0
0
0.055556
0.107649
706
19
44
37.157895
0.911111
0
0
0
0
0
0
0
0
0
0
0
0
1
0
true
0
1
0
1
0
0
0
0
null
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
1
0
1
0
1
0
0
5
0c7c3718500288a4616e4a22f834cb4979c294f2
111
py
Python
src/sparnn/optimizers/__init__.py
JoeinChina/DeepWeather
2677edc16d9865ec98401aaf121aaabd24974aaf
[ "MIT" ]
1
2020-07-23T04:13:02.000Z
2020-07-23T04:13:02.000Z
src/sparnn/optimizers/__init__.py
JoeBuzh/DeepWeather
2677edc16d9865ec98401aaf121aaabd24974aaf
[ "MIT" ]
null
null
null
src/sparnn/optimizers/__init__.py
JoeBuzh/DeepWeather
2677edc16d9865ec98401aaf121aaabd24974aaf
[ "MIT" ]
null
null
null
from optimizer import Optimizer from sgd import SGD from adadelta import AdaDelta from rmsprop import RMSProp
18.5
31
0.846847
16
111
5.875
0.375
0
0
0
0
0
0
0
0
0
0
0
0.153153
111
5
32
22.2
1
0
0
0
0
0
0
0
0
0
0
0
0
1
0
true
0
1
0
1
0
1
0
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
1
0
1
0
1
0
0
5
0c7c999548441f6f0a7a5893008b3ed35656f00b
189
py
Python
server/anoixo-server/translation_providers/TranslationProvider.py
sheesania/anoixo
29e059ad95ceee07566e2722a7c1343823f4ff5f
[ "MIT" ]
3
2020-01-08T22:20:57.000Z
2021-01-03T08:44:31.000Z
server/anoixo-server/translation_providers/TranslationProvider.py
sheesania/anoixo
29e059ad95ceee07566e2722a7c1343823f4ff5f
[ "MIT" ]
122
2020-01-06T17:31:06.000Z
2020-12-09T19:23:17.000Z
server/anoixo-server/translation_providers/TranslationProvider.py
sheesania/anoixo
29e059ad95ceee07566e2722a7c1343823f4ff5f
[ "MIT" ]
null
null
null
import abc from QueryResult import QueryResult class TranslationProvider(abc.ABC): @abc.abstractmethod def add_translations(self, query_result: QueryResult) -> None: pass
21
66
0.751323
21
189
6.666667
0.714286
0.085714
0
0
0
0
0
0
0
0
0
0
0.179894
189
8
67
23.625
0.903226
0
0
0
0
0
0
0
0
0
0
0
0
1
0.166667
false
0.166667
0.333333
0
0.666667
0
1
0
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
0
1
1
0
1
0
0
5
0c8b34706857e70a6e633435a553a513434db2d7
251
py
Python
otp/avatar/DistributedAvatarUD.py
TheFamiliarScoot/open-toontown
678313033174ea7d08e5c2823bd7b473701ff547
[ "BSD-3-Clause" ]
99
2019-11-02T22:25:00.000Z
2022-02-03T03:48:00.000Z
otp/avatar/DistributedAvatarUD.py
TheFamiliarScoot/open-toontown
678313033174ea7d08e5c2823bd7b473701ff547
[ "BSD-3-Clause" ]
42
2019-11-03T05:31:08.000Z
2022-03-16T22:50:32.000Z
otp/avatar/DistributedAvatarUD.py
TheFamiliarScoot/open-toontown
678313033174ea7d08e5c2823bd7b473701ff547
[ "BSD-3-Clause" ]
57
2019-11-03T07:47:37.000Z
2022-03-22T00:41:49.000Z
from direct.directnotify import DirectNotifyGlobal from direct.distributed.DistributedObjectUD import DistributedObjectUD class DistributedAvatarUD(DistributedObjectUD): notify = DirectNotifyGlobal.directNotify.newCategory('DistributedAvatarUD')
41.833333
79
0.876494
19
251
11.578947
0.578947
0.090909
0
0
0
0
0
0
0
0
0
0
0.071713
251
5
80
50.2
0.944206
0
0
0
0
0
0.075697
0
0
0
0
0
0
1
0
false
0
0.5
0
1
0
1
0
1
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
0
0
1
0
1
0
0
5
0cfd5f6e91b7359f53218fa59e93780a16c2c313
539
py
Python
h/accounts/events.py
julien-cheng/h
36c8ec044725720cf36f0986cdf025395aca8929
[ "BSD-2-Clause" ]
2
2019-08-04T07:22:11.000Z
2020-07-17T05:01:41.000Z
h/accounts/events.py
fuelpress/i.fuel.press
af7b25895d813af0fef656dcf483afe852a99d76
[ "BSD-2-Clause" ]
null
null
null
h/accounts/events.py
fuelpress/i.fuel.press
af7b25895d813af0fef656dcf483afe852a99d76
[ "BSD-2-Clause" ]
null
null
null
# -*- coding: utf-8 -*- from __future__ import unicode_literals class ActivationEvent(object): def __init__(self, request, user): self.request = request self.user = user class LoginEvent(object): def __init__(self, request, user): self.request = request self.user = user class LogoutEvent(object): def __init__(self, request): self.request = request class PasswordResetEvent(object): def __init__(self, request, user): self.request = request self.user = user
20.730769
39
0.653061
60
539
5.516667
0.316667
0.265861
0.1571
0.205438
0.628399
0.555891
0.555891
0.555891
0.555891
0.555891
0
0.002463
0.246753
539
25
40
21.56
0.812808
0.038961
0
0.625
0
0
0
0
0
0
0
0
0
1
0.25
false
0.0625
0.0625
0
0.5625
0
0
0
0
null
1
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
1
0
1
0
0
1
0
0
5
0b42aa14f34d9d6502f03426e3636115611ac61d
97
py
Python
python/testData/resolve/DefaultInClass.py
jnthn/intellij-community
8fa7c8a3ace62400c838e0d5926a7be106aa8557
[ "Apache-2.0" ]
2
2018-12-29T09:53:39.000Z
2018-12-29T09:53:42.000Z
python/testData/resolve/DefaultInClass.py
Cyril-lamirand/intellij-community
60ab6c61b82fc761dd68363eca7d9d69663cfa39
[ "Apache-2.0" ]
173
2018-07-05T13:59:39.000Z
2018-08-09T01:12:03.000Z
python/testData/resolve/DefaultInClass.py
Cyril-lamirand/intellij-community
60ab6c61b82fc761dd68363eca7d9d69663cfa39
[ "Apache-2.0" ]
2
2020-03-15T08:57:37.000Z
2020-04-07T04:48:14.000Z
# default value from class context class A: FOO = 1 def foo(self, param=F<ref>OO): pass
13.857143
34
0.649485
17
97
3.705882
0.882353
0
0
0
0
0
0
0
0
0
0
0.013699
0.247423
97
6
35
16.166667
0.849315
0.329897
0
0
0
0
0
0
0
0
0
0
0
1
0.25
false
0.25
0
0
0.75
0
1
0
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
1
0
1
0
0
1
0
0
5
0b6d5e86c081cec9ac2be15f3b7fd318c78c43c3
2,269
py
Python
25-tables/python/tables.py
tourdedave/selenium-tips
adef3ce6a2aaadf5fc029f37a593ed2f756b2c3e
[ "MIT" ]
251
2015-01-28T05:06:00.000Z
2020-06-26T16:16:12.000Z
25-tables/python/tables.py
tourdedave/selenium-tips
adef3ce6a2aaadf5fc029f37a593ed2f756b2c3e
[ "MIT" ]
23
2015-03-04T07:32:52.000Z
2019-06-28T10:16:44.000Z
25-tables/python/tables.py
tourdedave/selenium-tips
adef3ce6a2aaadf5fc029f37a593ed2f756b2c3e
[ "MIT" ]
157
2015-01-20T19:38:13.000Z
2020-06-17T13:16:19.000Z
# -*- coding: utf-8 -*- """ Implementation of http://elementalselenium.com/tips/25-tables """ import unittest from selenium import webdriver class Tables(unittest.TestCase): def setUp(self): self.driver = webdriver.Firefox() def tearDown(self): self.driver.quit() def test_sort_number_column_in_ascending_order_with_limited_locators(self): driver = self.driver driver.get('http://the-internet.herokuapp.com/tables') driver.find_element_by_css_selector('#table1 thead tr th:nth-of-type(4)').click() due_column = driver.find_elements_by_css_selector('#table1 tbody tr td:nth-of-type(4)') dues = [float(due.text.replace('$','')) for due in due_column] assert dues == sorted(dues) def test_sort_number_column_in_descending_order_with_limited_locators(self): driver = self.driver driver.get('http://the-internet.herokuapp.com/tables') driver.find_element_by_css_selector('#table1 thead tr th:nth-of-type(4)').click() driver.find_element_by_css_selector('#table1 thead tr th:nth-of-type(4)').click() due_column = driver.find_elements_by_css_selector('#table1 tbody tr td:nth-of-type(4)') dues = [float(due.text.replace('$','')) for due in due_column] assert dues == sorted(dues, reverse=True) def test_sort_text_column_in_ascending_order_with_limited_locators(self): driver = self.driver driver.get('http://the-internet.herokuapp.com/tables') driver.find_element_by_css_selector('#table1 thead tr th:nth-of-type(3)').click() email_column = driver.find_elements_by_css_selector('#table1 tbody tr td:nth-of-type(3)') emails = [email.text for email in email_column] assert emails == sorted(emails) def test_sort_number_column_in_ascending_order_with_helpful_locators(self): driver = self.driver driver.get('http://the-internet.herokuapp.com/tables') driver.find_element_by_css_selector('#table2 thead .dues').click() due_column = driver.find_elements_by_css_selector('#table2 tbody .dues') dues = [float(due.text.replace('$','')) for due in due_column] assert dues == sorted(dues) if __name__ == "__main__": unittest.main()
42.811321
97
0.695901
316
2,269
4.718354
0.234177
0.067069
0.078471
0.089202
0.755869
0.755869
0.739101
0.739101
0.739101
0.668679
0
0.010144
0.174526
2,269
52
98
43.634615
0.785905
0.037021
0
0.473684
0
0
0.205328
0
0
0
0
0
0.105263
1
0.157895
false
0
0.052632
0
0.236842
0
0
0
0
null
0
0
0
0
1
1
1
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
5
0b708b93e02731181576650f28345f24df387506
9,038
py
Python
model-optimizer/mo/ops/tile_test.py
zhoub/dldt
e42c01cf6e1d3aefa55e2c5df91f1054daddc575
[ "Apache-2.0" ]
3
2020-02-09T23:25:37.000Z
2021-01-19T09:44:12.000Z
model-optimizer/mo/ops/tile_test.py
zhoub/dldt
e42c01cf6e1d3aefa55e2c5df91f1054daddc575
[ "Apache-2.0" ]
null
null
null
model-optimizer/mo/ops/tile_test.py
zhoub/dldt
e42c01cf6e1d3aefa55e2c5df91f1054daddc575
[ "Apache-2.0" ]
2
2020-04-18T16:24:39.000Z
2021-01-19T09:42:19.000Z
""" Copyright (c) 2018-2019 Intel Corporation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. """ import unittest import numpy as np from mo.graph.graph import Node from mo.ops.tile import Tile from mo.utils.unittest.graph import build_graph nodes_attributes = {'data': {'value': None, 'shape': np.array([10, 20, 30, 40]), 'kind': 'data'}, 'tile_values': {'value': None, 'shape': np.array([4]), 'kind': 'data'}, 'tile': {'type': 'Tile', 'kind': 'op'}, 'tile_out': {'value': None, 'shape': None, 'kind': 'data'}, } class TestTileInfer(unittest.TestCase): def test_tile_infer_correct(self): graph = build_graph(nodes_attributes, [('data', 'tile'), ('tile_values', 'tile'), ('tile', 'tile_out')], {'tile_values': {'value': np.array([7, 1, 1, 1])}}) tile_node = Node(graph, 'tile') Tile.infer(tile_node) self.assertTrue(np.all(np.array([70, 20, 30, 40]) == graph.node['tile_out']['shape'])) self.assertEqual(tile_node.axis, 0) self.assertEqual(tile_node.tiles, 7) def test_tile_infer_correct_2(self): graph = build_graph(nodes_attributes, [('data', 'tile'), ('tile_values', 'tile'), ('tile', 'tile_out')], {'tile_values': {'value': np.array([1, 7, 1, 1])}}) tile_node = Node(graph, 'tile') Tile.infer(tile_node) self.assertTrue(np.all(np.array([10, 140, 30, 40]) == graph.node['tile_out']['shape'])) self.assertEqual(tile_node.axis, 1) self.assertEqual(tile_node.tiles, 7) def test_tile_infer_correct_2d_tensor(self): graph = build_graph(nodes_attributes, [('data', 'tile'), ('tile_values', 'tile'), ('tile', 'tile_out')], {'data': {'shape': np.array([3, 7])}, 'tile_values': {'value': np.array([5, 1])}}) tile_node = Node(graph, 'tile') Tile.infer(tile_node) self.assertTrue(np.all(np.array([15, 7]) == graph.node['tile_out']['shape'])) self.assertEqual(tile_node.axis, 0) self.assertEqual(tile_node.tiles, 5) def test_tile_infer_all_ones(self): graph = build_graph(nodes_attributes, [('data', 'tile'), ('tile_values', 'tile'), ('tile', 'tile_out')], {'tile_values': {'value': np.array([1, 1, 1, 1])}}) tile_node = Node(graph, 'tile') Tile.infer(tile_node) self.assertTrue(np.all(np.array([10, 20, 30, 40]) == graph.node['tile_out']['shape'])) self.assertEqual(tile_node.axis, 0) self.assertEqual(tile_node.tiles, 1) def test_tile_infer_two_non_one(self): graph = build_graph(nodes_attributes, [('data', 'tile'), ('tile_values', 'tile'), ('tile', 'tile_out')], {'tile_values': {'value': np.array([2, 1, 1, 2])}}) tile_node = Node(graph, 'tile') Tile.infer(tile_node) self.assertIsNone(graph.node['tile']['type']) self.assertTrue(np.all(np.array([20, 20, 30, 80]) == graph.node['tile_out']['shape'])) self.assertFalse(tile_node.has_and_set('axis')) self.assertFalse(tile_node.has_and_set('tiles')) def test_tile_infer_three_non_one(self): graph = build_graph(nodes_attributes, [('data', 'tile'), ('tile_values', 'tile'), ('tile', 'tile_out')], {'tile_values': {'value': np.array([2, 1, 5, 2])}}) tile_node = Node(graph, 'tile') Tile.infer(tile_node) self.assertIsNone(graph.node['tile']['type']) self.assertTrue(np.all(np.array([20, 20, 150, 80]) == graph.node['tile_out']['shape'])) def test_tile_infer_none_input_shape(self): graph = build_graph(nodes_attributes, [('data', 'tile'), ('tile_values', 'tile'), ('tile', 'tile_out')], {'data': {'shape': None}, 'tile_values': {'value': np.array([1, 7, 1, 1])}}) tile_node = Node(graph, 'tile') Tile.infer(tile_node) self.assertIsNone(graph.node['tile_out']['shape']) def test_tile_infer_values_test(self): input_data = np.arange(-30, 60, 0.25).reshape([2, 4, 3, -1]) tile_values = np.array([3, 1, 1, 1]) graph = build_graph(nodes_attributes, [('data', 'tile'), ('tile_values', 'tile'), ('tile', 'tile_out')], {'data': {'shape': input_data.shape, 'value': input_data}, 'tile_values': {'value': tile_values}}) tile_node = Node(graph, 'tile') Tile.infer(tile_node) self.assertTrue(np.all(np.tile(input_data, tile_values) == graph.node['tile_out']['value'])) self.assertEqual(tile_node.axis, 0) self.assertEqual(tile_node.tiles, 3) def test_tile_infer_values_const_propagation(self): """ Test for constant propagation even if tile with multiple tile indices is not supported """ input_data = np.arange(-30, 60, 0.25).reshape([2, 4, 3, -1]) tile_values = np.array([4, 3, 2, 5]) graph = build_graph(nodes_attributes, [('data', 'tile'), ('tile_values', 'tile'), ('tile', 'tile_out')], {'data': {'shape': input_data.shape, 'value': input_data}, 'tile_values': {'value': tile_values}}) tile_node = Node(graph, 'tile') Tile.infer(tile_node) self.assertTrue(np.all(np.tile(input_data, tile_values) == graph.node['tile_out']['value'])) self.assertIsNone(tile_node.type) def test_tile_infer_undefined_tile_values(self): graph = build_graph(nodes_attributes, [('data', 'tile'), ('tile_values', 'tile'), ('tile', 'tile_out')], {'tile_values': {'value': None}}) tile_node = Node(graph, 'tile') Tile.infer(tile_node) self.assertIsNone(graph.node['tile_out']['shape']) def test_tile_infer_shapes_mismatch(self): graph = build_graph(nodes_attributes, [('data', 'tile'), ('tile_values', 'tile'), ('tile', 'tile_out')], {'tile_values': {'value': np.array([1, 2, 1]), 'shape': np.array([3])}}) tile_node = Node(graph, 'tile') Tile.infer(tile_node) self.assertIsNone(graph.node['tile_out']['shape']) def test_tile_infer_one_input_correct(self): graph = build_graph(nodes_attributes, [('data', 'tile'), ('tile', 'tile_out')], {'tile': {'axis': 1, 'tiles': 7}}) tile_node = Node(graph, 'tile') Tile.infer(tile_node) self.assertTrue(np.all(np.array([10, 140, 30, 40]) == graph.node['tile_out']['shape'])) self.assertEqual(tile_node.axis, 1) self.assertEqual(tile_node.tiles, 7) def test_tile_infer_one_input_correct_missing_axis(self): graph = build_graph(nodes_attributes, [('data', 'tile'), ('tile', 'tile_out')], {'tile': {'tiles': 7}}) tile_node = Node(graph, 'tile') Tile.infer(tile_node) self.assertIsNone(graph.node['tile_out']['shape']) def test_tile_infer_one_input_correct_missing_tiles(self): graph = build_graph(nodes_attributes, [('data', 'tile'), ('tile', 'tile_out')], {'tile': {'axis': 1}}) tile_node = Node(graph, 'tile') Tile.infer(tile_node) self.assertIsNone(graph.node['tile_out']['shape'])
45.878173
100
0.512724
1,020
9,038
4.336275
0.140196
0.095863
0.047027
0.084784
0.772779
0.743387
0.734343
0.719873
0.713317
0.704951
0
0.025684
0.332264
9,038
196
101
46.112245
0.707208
0.072361
0
0.672956
0
0
0.127053
0
0
0
0
0
0.194969
1
0.08805
false
0
0.031447
0
0.125786
0
0
0
0
null
0
0
0
0
1
1
1
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
5
0b72161d7459248d856dbae9a4df0ec4ca1e36ab
1,340
py
Python
Conditions if, then, else/16ChessBoard.py
palakbaphna/pyprac
992770d5aed73c632a69b4bb22f471f35d083ee5
[ "Apache-2.0" ]
null
null
null
Conditions if, then, else/16ChessBoard.py
palakbaphna/pyprac
992770d5aed73c632a69b4bb22f471f35d083ee5
[ "Apache-2.0" ]
null
null
null
Conditions if, then, else/16ChessBoard.py
palakbaphna/pyprac
992770d5aed73c632a69b4bb22f471f35d083ee5
[ "Apache-2.0" ]
null
null
null
#Given two cells of a chessboard. If they are painted in one color, print the word YES, and if in a different color - NO. r = int(input("Row number of the first cell on Chessboard, r = ?")) if ((r > 8) or (r < 1)): print("Invalid row number for a Chessboard!") exit() c = int(input("The column number for the first cell on Chessboard, c = ?")) if((c > 8) or (c <1)): print("Invalid column number for a Chessboard!") exit() R = int(input("THe row number for the second cell on Chessboard, R = ?")) if ((R > 8) or (R < 1)): print("Invalid row number for a Chessboard!") exit() C = int(input("The column for the second cell on Chessboard, C = ?")) if ((C > 8) or (C <1 )): print("Invalid column number for a Chessboard!") exit() if ( ( r % 2 == 0) and ( (c % 2 == 0)) )or ( (r % 2 != 0) and (c % 2 != 0)): if ( ((R %2 == 0)and(C% 2 ==0)) or (( R % 2 != 0)and(C %2 != 0)) ): print("YES, The two given cells has the SAME color.") else: print("NO, The two given cells are NOT the same color") elif ( ((r % 2 == 0) and(c %2 != 0)) or ((r % 2 != 0) and (c% 2 ==0)) ): if ( ((R %2 == 0)and(C% 2 !=0)) or (( R % 2 != 0)and(C %2 == 0)) ): print("YES, The two given cells has the SAME color.") else: print("NO, The two given cells are NOT the same color") exit()
37.222222
121
0.552985
239
1,340
3.100418
0.1841
0.043185
0.032389
0.064777
0.79892
0.777328
0.744939
0.744939
0.744939
0.744939
0
0.040609
0.264925
1,340
35
122
38.285714
0.711675
0.089552
0
0.555556
0
0
0.444992
0
0
0
0
0
0
1
0
false
0
0
0
0
0.296296
0
0
0
null
0
0
0
0
1
1
1
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
5
0b733f451b2b7197667ec92345d9310864e3d7cc
74
py
Python
pycalc/my_module.py
kopelek/pycalc
9955b3bfa48896da135e379a40d0ca3946e8ca24
[ "MIT" ]
2
2019-07-25T20:05:54.000Z
2019-08-07T14:24:29.000Z
pycalc/my_module.py
kopelek/pycalc
9955b3bfa48896da135e379a40d0ca3946e8ca24
[ "MIT" ]
null
null
null
pycalc/my_module.py
kopelek/pycalc
9955b3bfa48896da135e379a40d0ca3946e8ca24
[ "MIT" ]
1
2019-02-24T22:51:15.000Z
2019-02-24T22:51:15.000Z
#!/usr/bin/python3 def sin(x): """ sin(x) """ return 42
8.222222
18
0.432432
10
74
3.2
0.8
0.25
0
0
0
0
0
0
0
0
0
0.0625
0.351351
74
8
19
9.25
0.604167
0.324324
0
0
0
0
0
0
0
0
0
0
0
1
0.5
false
0
0
0
1
0
1
0
0
null
1
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
1
0
0
0
0
1
0
0
5
0b8fd953b0bfbf2680f69b091618bad97bc46bb8
31
py
Python
src/nima_keras/utils/__init__.py
souserge/neural-image-assessment
322d007f9f4e22da60d1b27364d80645972cfa25
[ "MIT" ]
null
null
null
src/nima_keras/utils/__init__.py
souserge/neural-image-assessment
322d007f9f4e22da60d1b27364d80645972cfa25
[ "MIT" ]
null
null
null
src/nima_keras/utils/__init__.py
souserge/neural-image-assessment
322d007f9f4e22da60d1b27364d80645972cfa25
[ "MIT" ]
null
null
null
from . import score_utils, cli
15.5
30
0.774194
5
31
4.6
1
0
0
0
0
0
0
0
0
0
0
0
0.16129
31
1
31
31
0.884615
0
0
0
0
0
0
0
0
0
0
0
0
1
0
true
0
1
0
1
0
1
1
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
1
0
1
0
0
0
0
5
e7ec9a3ddf568e172244e5c491ba7cf66cfe0b3b
105
py
Python
trellab/__init__.py
Edinburgh-Genome-Foundry/trellab
9f06e8184cf98a3796c79d16fed2c6b7f4fc9b62
[ "MIT" ]
2
2020-12-06T15:10:40.000Z
2021-07-20T10:26:10.000Z
trellab/__init__.py
Edinburgh-Genome-Foundry/trellab
9f06e8184cf98a3796c79d16fed2c6b7f4fc9b62
[ "MIT" ]
null
null
null
trellab/__init__.py
Edinburgh-Genome-Foundry/trellab
9f06e8184cf98a3796c79d16fed2c6b7f4fc9b62
[ "MIT" ]
null
null
null
""" dna_sequencing_viewer/__init__.py """ # __all__ = [] from .trellab import TrellabOrganizationClient
21
46
0.761905
10
105
7
1
0
0
0
0
0
0
0
0
0
0
0
0.114286
105
5
46
21
0.752688
0.457143
0
0
0
0
0
0
0
0
0
0
0
1
0
true
0
1
0
1
0
1
0
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
1
0
1
0
1
0
0
5
f01c6eed4b7d6412b67d4ca42bb777d893f587a5
131
py
Python
ffprobes3/__init__.py
Shub77/ffprobes3
decc48be50dbb35b09b6fee3f2644325f5dceb32
[ "MIT" ]
2
2019-10-10T04:27:38.000Z
2022-03-03T08:39:50.000Z
ffprobes3/__init__.py
Shub77/ffprobes3
decc48be50dbb35b09b6fee3f2644325f5dceb32
[ "MIT" ]
null
null
null
ffprobes3/__init__.py
Shub77/ffprobes3
decc48be50dbb35b09b6fee3f2644325f5dceb32
[ "MIT" ]
null
null
null
""" Python3 wrapper for ffprobe command line tool. ffprobe must exist in the path. """ from .ffprobes3 import FFProbes3, FFStream
21.833333
78
0.763359
18
131
5.555556
0.888889
0
0
0
0
0
0
0
0
0
0
0.027273
0.160305
131
5
79
26.2
0.881818
0.59542
0
0
0
0
0
0
0
0
0
0
0
1
0
true
0
1
0
1
0
1
0
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
1
0
1
0
1
0
0
5
f02712765632cb04718371315ab6941a46c2d138
70
py
Python
config.py
Arshiapersian/Persiana-Security-
0925d9bd16fe9a5f8f0e68cf00de1abbd1f25a50
[ "BSL-1.0" ]
null
null
null
config.py
Arshiapersian/Persiana-Security-
0925d9bd16fe9a5f8f0e68cf00de1abbd1f25a50
[ "BSL-1.0" ]
null
null
null
config.py
Arshiapersian/Persiana-Security-
0925d9bd16fe9a5f8f0e68cf00de1abbd1f25a50
[ "BSL-1.0" ]
null
null
null
TOKEN = "ODU1MDQ2MDU4NzQwOTQwODEw.YMsxsg.tI0PD9F1iuOH3myK_vrYRPK2ao4"
35
69
0.885714
5
70
12.2
1
0
0
0
0
0
0
0
0
0
0
0.134328
0.042857
70
1
70
70
0.776119
0
0
0
0
0
0.842857
0.842857
0
0
0
0
0
1
0
false
0
0
0
0
0
1
0
1
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
1
1
null
0
0
0
0
0
0
0
0
0
0
0
0
0
5
f030c26644d92d020688af505474f2262845d10d
80
py
Python
python/testData/inspections/GoogleDocStringRemoveParam_after.py
truthiswill/intellij-community
fff88cfb0dc168eea18ecb745d3e5b93f57b0b95
[ "Apache-2.0" ]
2
2019-04-28T07:48:50.000Z
2020-12-11T14:18:08.000Z
python/testData/inspections/GoogleDocStringRemoveParam_after.py
truthiswill/intellij-community
fff88cfb0dc168eea18ecb745d3e5b93f57b0b95
[ "Apache-2.0" ]
173
2018-07-05T13:59:39.000Z
2018-08-09T01:12:03.000Z
python/testData/inspections/GoogleDocStringRemoveParam_after.py
truthiswill/intellij-community
fff88cfb0dc168eea18ecb745d3e5b93f57b0b95
[ "Apache-2.0" ]
2
2020-03-15T08:57:37.000Z
2020-04-07T04:48:14.000Z
def foo(): """ Parameters: a: foo Returns: None """
10
15
0.3875
7
80
4.428571
0.857143
0
0
0
0
0
0
0
0
0
0
0
0.4625
80
8
16
10
0.72093
0.4625
0
0
0
0
0
0
0
0
0
0
0
1
1
true
0
0
0
1
0
1
0
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
1
1
0
0
0
1
0
0
5
f03abfcf3b180d9ef358f09198ecfc27bb580b96
157
py
Python
producer/tests/__init__.py
nicolalamacchia/kwebmon
13d8720314e9faff99b34dd5cb6c10d1cf45d786
[ "MIT" ]
null
null
null
producer/tests/__init__.py
nicolalamacchia/kwebmon
13d8720314e9faff99b34dd5cb6c10d1cf45d786
[ "MIT" ]
4
2021-04-28T03:19:37.000Z
2021-04-28T13:10:27.000Z
producer/tests/__init__.py
nicolalamacchia/kwebmon
13d8720314e9faff99b34dd5cb6c10d1cf45d786
[ "MIT" ]
null
null
null
import os def fixture_path(fixture_file): return os.path.join( os.path.join(os.path.dirname(__file__), "fixtures"), fixture_file )
17.444444
60
0.649682
21
157
4.52381
0.47619
0.189474
0.210526
0.252632
0.273684
0
0
0
0
0
0
0
0.229299
157
8
61
19.625
0.785124
0
0
0
0
0
0.050955
0
0
0
0
0
0
1
0.166667
false
0
0.166667
0.166667
0.5
0
1
0
0
null
0
1
1
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
0
0
0
1
0
0
0
5
f04a87905898daec4cc87a517b2f679f6bcd3138
22
py
Python
PycharmProjects/untitled/ex002/ex002.py
zmixtv1/cev-Python
edce04f86d943d9af070bf3c5e89575ff796ec9e
[ "MIT" ]
null
null
null
PycharmProjects/untitled/ex002/ex002.py
zmixtv1/cev-Python
edce04f86d943d9af070bf3c5e89575ff796ec9e
[ "MIT" ]
null
null
null
PycharmProjects/untitled/ex002/ex002.py
zmixtv1/cev-Python
edce04f86d943d9af070bf3c5e89575ff796ec9e
[ "MIT" ]
null
null
null
print('olá professor')
22
22
0.772727
3
22
5.666667
1
0
0
0
0
0
0
0
0
0
0
0
0.045455
22
1
22
22
0.809524
0
0
0
0
0
0.565217
0
0
0
0
0
0
1
0
true
0
0
0
0
1
1
1
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
1
0
0
0
0
1
0
5
652b3e8465ddf5ab033a8df6d1a95ca1ee8f9ead
73
py
Python
auth/admin.py
AntHoneyLam/open-pos
a0d625549ae82852836e45c621abe4e52419761c
[ "MIT" ]
null
null
null
auth/admin.py
AntHoneyLam/open-pos
a0d625549ae82852836e45c621abe4e52419761c
[ "MIT" ]
null
null
null
auth/admin.py
AntHoneyLam/open-pos
a0d625549ae82852836e45c621abe4e52419761c
[ "MIT" ]
null
null
null
class admin(): def __init__(self): pass def get_id(self): pass
7.3
20
0.630137
11
73
3.727273
0.727273
0.390244
0
0
0
0
0
0
0
0
0
0
0.246575
73
10
21
7.3
0.745455
0
0
0.4
0
0
0
0
0
0
0
0
0
1
0.4
false
0.4
0
0
0.6
0
1
0
0
null
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
1
0
1
0
0
1
0
0
5
6538e0287968e91c5e468aa6f929436935df648c
105
py
Python
solutions/session-00/hello.py
infelane/python-for-java-devs
56f313f89ad8603598f879f31e0d9a35795e50e3
[ "Apache-2.0" ]
1
2019-10-20T16:05:30.000Z
2019-10-20T16:05:30.000Z
solutions/session-00/hello.py
infelane/python-for-java-devs
56f313f89ad8603598f879f31e0d9a35795e50e3
[ "Apache-2.0" ]
1
2020-07-10T09:09:58.000Z
2020-07-10T09:09:58.000Z
solutions/session-00/hello.py
infelane/python-for-java-devs
56f313f89ad8603598f879f31e0d9a35795e50e3
[ "Apache-2.0" ]
3
2020-07-10T07:46:51.000Z
2022-02-21T08:58:45.000Z
def get_hello(): return 'Hello' class HelloSayer(): def say_hello(self): print('Hello')
15
24
0.609524
13
105
4.769231
0.692308
0
0
0
0
0
0
0
0
0
0
0
0.247619
105
7
25
15
0.78481
0
0
0
0
0
0.09434
0
0
0
0
0
0
1
0.4
false
0
0
0.2
0.8
0.2
1
0
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
1
0
0
0
1
1
0
0
5
e8e74d198413f2a0e094d04d1c022bc5bb620a64
5,400
py
Python
python-client/cloudera/director/d6_2/models/__init__.py
daanknoope/director-sdk
a099fedd5afe365aedbb50daa75de048ef6f7ab4
[ "Apache-2.0" ]
24
2015-03-04T01:39:36.000Z
2020-06-30T13:34:27.000Z
python-client/cloudera/director/d6_2/models/__init__.py
daanknoope/director-sdk
a099fedd5afe365aedbb50daa75de048ef6f7ab4
[ "Apache-2.0" ]
5
2015-11-04T08:18:47.000Z
2019-01-05T11:12:19.000Z
python-client/cloudera/director/d6_2/models/__init__.py
daanknoope/director-sdk
a099fedd5afe365aedbb50daa75de048ef6f7ab4
[ "Apache-2.0" ]
26
2015-02-24T21:13:53.000Z
2020-12-15T06:01:46.000Z
# coding: utf-8 # flake8: noqa """ Licensed to Cloudera, Inc. under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. Cloudera, Inc. licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. """ from __future__ import absolute_import # import models into model package from cloudera.director.d6_2.models.capabilities import Capabilities from cloudera.director.d6_2.models.cloud_provider_metadata import CloudProviderMetadata from cloudera.director.d6_2.models.cluster import Cluster from cloudera.director.d6_2.models.cluster_administration_settings import ClusterAdministrationSettings from cloudera.director.d6_2.models.cluster_template import ClusterTemplate from cloudera.director.d6_2.models.cluster_update_event_summary import ClusterUpdateEventSummary from cloudera.director.d6_2.models.configuration_property import ConfigurationProperty from cloudera.director.d6_2.models.configuration_property_value import ConfigurationPropertyValue from cloudera.director.d6_2.models.deployment import Deployment from cloudera.director.d6_2.models.deployment_template import DeploymentTemplate from cloudera.director.d6_2.models.diagnostic_data_summary import DiagnosticDataSummary from cloudera.director.d6_2.models.display_property import DisplayProperty from cloudera.director.d6_2.models.environment import Environment from cloudera.director.d6_2.models.error_info import ErrorInfo from cloudera.director.d6_2.models.eula import Eula from cloudera.director.d6_2.models.external_account import ExternalAccount from cloudera.director.d6_2.models.external_database import ExternalDatabase from cloudera.director.d6_2.models.external_database_server import ExternalDatabaseServer from cloudera.director.d6_2.models.external_database_server_template import ExternalDatabaseServerTemplate from cloudera.director.d6_2.models.external_database_server_usage import ExternalDatabaseServerUsage from cloudera.director.d6_2.models.external_database_template import ExternalDatabaseTemplate from cloudera.director.d6_2.models.health import Health from cloudera.director.d6_2.models.health_check import HealthCheck from cloudera.director.d6_2.models.import_result import ImportResult from cloudera.director.d6_2.models.import_status import ImportStatus from cloudera.director.d6_2.models.instance import Instance from cloudera.director.d6_2.models.instance_provider_config import InstanceProviderConfig from cloudera.director.d6_2.models.instance_state import InstanceState from cloudera.director.d6_2.models.instance_template import InstanceTemplate from cloudera.director.d6_2.models.login import Login from cloudera.director.d6_2.models.marketplace_image import MarketplaceImage from cloudera.director.d6_2.models.metering_setting import MeteringSetting from cloudera.director.d6_2.models.metrics import Metrics from cloudera.director.d6_2.models.migrating_group import MigratingGroup from cloudera.director.d6_2.models.migration import Migration from cloudera.director.d6_2.models.normalization_configuration import NormalizationConfiguration from cloudera.director.d6_2.models.notification import Notification from cloudera.director.d6_2.models.password_change import PasswordChange from cloudera.director.d6_2.models.resource_provider_metadata import ResourceProviderMetadata from cloudera.director.d6_2.models.script import Script from cloudera.director.d6_2.models.service import Service from cloudera.director.d6_2.models.ssh_credentials import SshCredentials from cloudera.director.d6_2.models.status import Status from cloudera.director.d6_2.models.time_series import TimeSeries from cloudera.director.d6_2.models.time_series_aggregate_statistics import TimeSeriesAggregateStatistics from cloudera.director.d6_2.models.time_series_cross_entity_metadata import TimeSeriesCrossEntityMetadata from cloudera.director.d6_2.models.time_series_data import TimeSeriesData from cloudera.director.d6_2.models.time_series_metadata import TimeSeriesMetadata from cloudera.director.d6_2.models.time_series_response import TimeSeriesResponse from cloudera.director.d6_2.models.time_series_response_list import TimeSeriesResponseList from cloudera.director.d6_2.models.time_series_row import TimeSeriesRow from cloudera.director.d6_2.models.user import User from cloudera.director.d6_2.models.user_management_status import UserManagementStatus from cloudera.director.d6_2.models.validation_exception_condition import ValidationExceptionCondition from cloudera.director.d6_2.models.validation_result import ValidationResult from cloudera.director.d6_2.models.validation_results import ValidationResults from cloudera.director.d6_2.models.virtual_instance import VirtualInstance from cloudera.director.d6_2.models.virtual_instance_group import VirtualInstanceGroup from cloudera.director.d6_2.models.warning_info import WarningInfo
63.529412
106
0.878889
735
5,400
6.272109
0.272109
0.153579
0.255965
0.281562
0.461388
0.461388
0.322993
0.164642
0.053579
0
0
0.024682
0.06963
5,400
84
107
64.285714
0.892914
0.148333
0
0
0
0
0
0
0
0
0
0
0
1
0
true
0.016667
1
0
1
0
0
0
0
null
0
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
1
0
1
0
1
0
0
5
e8f73d77003ad96b3f32b153c709ada2eb58a2a5
68
py
Python
data_processing.py
VJ0216/fraud_detection
92a2f8bc6062c4d5f92ba8ddd785b45f5b22d3eb
[ "Unlicense" ]
null
null
null
data_processing.py
VJ0216/fraud_detection
92a2f8bc6062c4d5f92ba8ddd785b45f5b22d3eb
[ "Unlicense" ]
null
null
null
data_processing.py
VJ0216/fraud_detection
92a2f8bc6062c4d5f92ba8ddd785b45f5b22d3eb
[ "Unlicense" ]
null
null
null
print("adding all the data processing code related fraud detection")
68
68
0.823529
10
68
5.6
1
0
0
0
0
0
0
0
0
0
0
0
0.117647
68
1
68
68
0.933333
0
0
0
0
0
0.855072
0
0
0
0
0
0
1
0
true
0
0
0
0
1
1
0
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
1
0
null
0
0
0
0
0
0
1
0
0
0
0
1
0
5
334375d85e9635ba7c65cef0426c4ce0ccd3f245
116
py
Python
lambdata_nwilliams030/simple_test.py
nwilliams030/lambdata
4c6bb55fedeff680c894b92b0ff1db3a815f3841
[ "MIT" ]
null
null
null
lambdata_nwilliams030/simple_test.py
nwilliams030/lambdata
4c6bb55fedeff680c894b92b0ff1db3a815f3841
[ "MIT" ]
3
2020-03-24T18:05:13.000Z
2021-06-02T00:45:54.000Z
lambdata_nwilliams030/simple_test.py
nwilliams030/lambdata
4c6bb55fedeff680c894b92b0ff1db3a815f3841
[ "MIT" ]
null
null
null
""" Unit Tests for df_utils """ import unittest from simple import __ class UtilsTests(unittest.TestCase): ""
11.6
36
0.715517
14
116
5.714286
0.857143
0
0
0
0
0
0
0
0
0
0
0
0.181034
116
9
37
12.888889
0.842105
0.198276
0
0
0
0
0
0
0
0
0
0
0
1
0
true
0
0.5
0
0.75
0
1
0
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
1
0
1
0
1
0
0
5
334f2f798302c045206b933cfa97cb86e3ffc7af
196
py
Python
log_generator/exit_program.py
DobyLov/loggenerator
d1889f38b2e8fc84a1f047d65f00db003d9ab0cd
[ "MIT" ]
null
null
null
log_generator/exit_program.py
DobyLov/loggenerator
d1889f38b2e8fc84a1f047d65f00db003d9ab0cd
[ "MIT" ]
2
2020-05-01T19:51:20.000Z
2020-05-01T20:59:38.000Z
log_generator/exit_program.py
DobyLov/loggenerator
d1889f38b2e8fc84a1f047d65f00db003d9ab0cd
[ "MIT" ]
null
null
null
""" Exit program """ from log_generator.dateTime_handler import get_dateNow import sys # sortir du programme def exitProgram(): print("Sortie du programme : " + get_dateNow()) sys.exit()
21.777778
54
0.719388
25
196
5.48
0.72
0.145985
0
0
0
0
0
0
0
0
0
0
0.168367
196
9
55
21.777778
0.840491
0.173469
0
0
0
0
0.141026
0
0
0
0
0
0
1
0.2
true
0
0.4
0
0.6
0.2
1
0
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
1
0
1
0
1
0
0
5
334fb9c3091166661e98b8f002164498215e5a91
2,308
py
Python
tests/test_title.py
TrAyZeN/ArchiveBox
88cc75a0457859a63b06854e353b053c730b3752
[ "MIT" ]
1
2021-09-24T23:10:42.000Z
2021-09-24T23:10:42.000Z
tests/test_title.py
TrAyZeN/ArchiveBox
88cc75a0457859a63b06854e353b053c730b3752
[ "MIT" ]
5
2021-03-30T14:20:11.000Z
2021-09-22T19:39:29.000Z
tests/test_title.py
TrAyZeN/ArchiveBox
88cc75a0457859a63b06854e353b053c730b3752
[ "MIT" ]
null
null
null
import os import sqlite3 from .fixtures import * def test_title_is_htmlencoded_in_index_html(tmp_path, process, disable_extractors_dict): """ https://github.com/pirate/ArchiveBox/issues/330 Unencoded content should not be rendered as it facilitates xss injections and breaks the layout. """ subprocess.run(['archivebox', 'add', 'http://127.0.0.1:8080/static/title_with_html.com.html'], capture_output=True, env=disable_extractors_dict) list_process = subprocess.run(["archivebox", "list", "--html"], capture_output=True) assert "<textarea>" not in list_process.stdout.decode("utf-8") def test_title_in_meta_title(tmp_path, process, disable_extractors_dict): add_process = subprocess.run(["archivebox", "add", "http://127.0.0.1:8080/static/title_with_html.com.html"], capture_output=True, env=disable_extractors_dict) os.chdir(tmp_path) conn = sqlite3.connect("index.sqlite3") conn.row_factory = sqlite3.Row c = conn.cursor() c.execute("SELECT title from core_snapshot") snapshot = c.fetchone() conn.close() assert snapshot[0] == "It All Starts with a Humble <textarea> ◆ 24 ways" def test_title_in_meta_og(tmp_path, process, disable_extractors_dict): add_process = subprocess.run(["archivebox", "add", "http://127.0.0.1:8080/static/title_og_with_html.com.html"], capture_output=True, env=disable_extractors_dict) os.chdir(tmp_path) conn = sqlite3.connect("index.sqlite3") conn.row_factory = sqlite3.Row c = conn.cursor() c.execute("SELECT title from core_snapshot") snapshot = c.fetchone() conn.close() assert snapshot[0] == "It All Starts with a Humble <textarea>" def test_title_malformed(tmp_path, process, disable_extractors_dict): add_process = subprocess.run(["archivebox", "add", "http://127.0.0.1:8080/static/malformed.html"], capture_output=True, env=disable_extractors_dict) os.chdir(tmp_path) conn = sqlite3.connect("index.sqlite3") conn.row_factory = sqlite3.Row c = conn.cursor() c.execute("SELECT title from core_snapshot") snapshot = c.fetchone() conn.close() assert snapshot[0] == "malformed document"
39.118644
115
0.678943
308
2,308
4.88961
0.279221
0.090305
0.111554
0.069721
0.758964
0.73506
0.711819
0.711819
0.711819
0.711819
0
0.031772
0.195407
2,308
58
116
39.793103
0.778675
0.062392
0
0.609756
0
0
0.246729
0
0
0
0
0
0.097561
1
0.097561
false
0
0.073171
0
0.170732
0
0
0
0
null
0
0
0
0
1
1
1
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
5
6834755879e080bc7813bfc2da891b65efee75b9
54
py
Python
depr/0.1.3/dtools/analyze/__init__.py
rosspalmer/DataTools
7857e68af56e243598dd6b0e95aa1cc592df4b6b
[ "MIT" ]
1
2015-09-09T01:46:19.000Z
2015-09-09T01:46:19.000Z
depr/0.1.3/dtools/analyze/__init__.py
rosspalmer/DataTools
7857e68af56e243598dd6b0e95aa1cc592df4b6b
[ "MIT" ]
null
null
null
depr/0.1.3/dtools/analyze/__init__.py
rosspalmer/DataTools
7857e68af56e243598dd6b0e95aa1cc592df4b6b
[ "MIT" ]
null
null
null
from predict import linear, logistic, kmeans, knearest
54
54
0.833333
7
54
6.428571
1
0
0
0
0
0
0
0
0
0
0
0
0.111111
54
1
54
54
0.9375
0
0
0
0
0
0
0
0
0
0
0
0
1
0
true
0
1
0
1
0
1
0
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
1
0
1
0
1
0
0
5
68488ea3ce7ac2aae30d18e022a50b3a3400b361
158
py
Python
mne/stats/__init__.py
neurodebian/mne-python
44a5ef5241a748b2f77c62fdcda6334220c6af45
[ "BSD-3-Clause" ]
1
2017-01-28T21:49:11.000Z
2017-01-28T21:49:11.000Z
mne/stats/__init__.py
neurodebian/mne-python
44a5ef5241a748b2f77c62fdcda6334220c6af45
[ "BSD-3-Clause" ]
null
null
null
mne/stats/__init__.py
neurodebian/mne-python
44a5ef5241a748b2f77c62fdcda6334220c6af45
[ "BSD-3-Clause" ]
null
null
null
from .permutations import permutation_t_test from .cluster_level import permutation_cluster_test, \ permutation_cluster_1samp_test
39.5
57
0.740506
17
158
6.411765
0.529412
0.311927
0
0
0
0
0
0
0
0
0
0.008264
0.234177
158
3
58
52.666667
0.892562
0
0
0
0
0
0
0
0
0
0
0
0
1
0
true
0
0.666667
0
0.666667
0
1
0
0
null
1
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
1
0
1
0
0
0
0
5
685019e7ed9a998b6055e9b6c7e2c1f7015fcbb8
44
py
Python
pmp/utils/ilp/__init__.py
Koozco/pmp
3ad96b01afb2ce6644eb1917ae88ee6d72adc8cf
[ "MIT" ]
1
2020-03-30T18:56:02.000Z
2020-03-30T18:56:02.000Z
pmp/utils/ilp/__init__.py
Koozco/pmp
3ad96b01afb2ce6644eb1917ae88ee6d72adc8cf
[ "MIT" ]
9
2018-11-19T00:04:52.000Z
2022-03-11T23:51:18.000Z
pmp/utils/ilp/__init__.py
Koozco/pmp
3ad96b01afb2ce6644eb1917ae88ee6d72adc8cf
[ "MIT" ]
2
2018-12-02T10:43:34.000Z
2020-03-30T10:15:50.000Z
from .model import Model from .ilp import *
14.666667
24
0.75
7
44
4.714286
0.571429
0
0
0
0
0
0
0
0
0
0
0
0.181818
44
2
25
22
0.916667
0
0
0
0
0
0
0
0
0
0
0
0
1
0
true
0
1
0
1
0
1
1
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
1
0
1
0
0
0
0
5
6874df642e5fdc4a4ebe358bb0b028ac50bf5634
261
py
Python
crpytarch.py
GuiltedRose/CryptArc
69b5b3ed73acfa61727a45ad30df75059814b76e
[ "MIT" ]
null
null
null
crpytarch.py
GuiltedRose/CryptArc
69b5b3ed73acfa61727a45ad30df75059814b76e
[ "MIT" ]
null
null
null
crpytarch.py
GuiltedRose/CryptArc
69b5b3ed73acfa61727a45ad30df75059814b76e
[ "MIT" ]
null
null
null
# This will the base file for our encription method import string import os import pypi # algorithms to know: RSA should be good enough if we decide to make it a web app or something. # Why RSA? Because it's used for SSH, HTTPS, Bitcoin, and PGP/GPG encryption.
43.5
95
0.770115
48
261
4.1875
0.875
0
0
0
0
0
0
0
0
0
0
0
0.183908
261
6
96
43.5
0.943662
0.83908
0
0
0
0
0
0
0
0
0
0
0
1
0
true
0
1
0
1
0
0
0
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
1
0
0
0
0
0
0
null
0
0
0
0
0
0
1
0
1
0
1
0
0
5
6875af1503a09d5ea46d6b7928facac2ea0f6bcb
140
py
Python
alloy/algo/__init__.py
CMU-TBD/alloy
cf66738e044613fb274bd1b159864a7600e15cb5
[ "MIT" ]
null
null
null
alloy/algo/__init__.py
CMU-TBD/alloy
cf66738e044613fb274bd1b159864a7600e15cb5
[ "MIT" ]
null
null
null
alloy/algo/__init__.py
CMU-TBD/alloy
cf66738e044613fb274bd1b159864a7600e15cb5
[ "MIT" ]
null
null
null
# Copyright - Transporation, Bots, and Disability Lab - Carnegie Mellon University # Released under MIT License from .graph_search import *
35
82
0.792857
17
140
6.470588
1
0
0
0
0
0
0
0
0
0
0
0
0.15
140
4
83
35
0.92437
0.764286
0
0
0
0
0
0
0
0
0
0
0
1
0
true
0
1
0
1
0
1
0
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
1
0
1
0
1
0
0
5
6880954eccc6c55b1134fec6ddc916fe1f1ce559
11
py
Python
part4/myproj/dir1/value.py
MADTeacher/python_basics
06ae43d8063c1c8426a4fbb53443b6d1ee727951
[ "MIT" ]
null
null
null
part4/myproj/dir1/value.py
MADTeacher/python_basics
06ae43d8063c1c8426a4fbb53443b6d1ee727951
[ "MIT" ]
null
null
null
part4/myproj/dir1/value.py
MADTeacher/python_basics
06ae43d8063c1c8426a4fbb53443b6d1ee727951
[ "MIT" ]
4
2020-10-04T12:24:14.000Z
2022-01-16T17:01:59.000Z
val = 3.99
5.5
10
0.545455
3
11
2
1
0
0
0
0
0
0
0
0
0
0
0.375
0.272727
11
1
11
11
0.375
0
0
0
0
0
0
0
0
0
0
0
0
1
0
false
0
0
0
0
0
1
1
0
null
0
0
0
0
0
0
0
0
0
0
1
0
0
1
0
0
1
0
0
0
0
0
0
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
5
688ab91d21eb57fd6a3fa20c41ee654a72e7158b
225
py
Python
tributary/__init__.py
Ferev/tributary
df38e489f2c93415e889006475464e254b4433a1
[ "Apache-2.0" ]
357
2018-09-13T19:58:46.000Z
2022-03-31T17:22:20.000Z
tributary/__init__.py
Ferev/tributary
df38e489f2c93415e889006475464e254b4433a1
[ "Apache-2.0" ]
109
2018-09-13T18:37:00.000Z
2022-03-27T00:59:49.000Z
tributary/__init__.py
Ferev/tributary
df38e489f2c93415e889006475464e254b4433a1
[ "Apache-2.0" ]
36
2018-09-17T21:01:05.000Z
2022-03-26T02:41:37.000Z
from ._version import __version__ # noqa: F401, E402 from .lazy import LazyGraph, LazyNode, node # noqa: F401, E402 from .streaming import * # noqa: F401, F403, E402 from .utils import LazyToStreaming # noqa: F401, E402
37.5
63
0.733333
30
225
5.333333
0.466667
0.2
0.225
0.2
0
0
0
0
0
0
0
0.145946
0.177778
225
5
64
45
0.718919
0.324444
0
0
0
0
0
0
0
0
0
0
0
1
0
true
0
1
0
1
0
0
0
0
null
0
1
1
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
1
0
1
0
0
0
0
5
d7a113899ce7c3ad8818cc1892fce3c01416c064
22
py
Python
hyqWork1.py
1804fengya/1442
76cc3d63914c493a2a0d341cd12be8a896c593cf
[ "Apache-2.0" ]
null
null
null
hyqWork1.py
1804fengya/1442
76cc3d63914c493a2a0d341cd12be8a896c593cf
[ "Apache-2.0" ]
null
null
null
hyqWork1.py
1804fengya/1442
76cc3d63914c493a2a0d341cd12be8a896c593cf
[ "Apache-2.0" ]
null
null
null
print("kkkkkkkkkkkkk")
22
22
0.818182
2
22
9
1
0
0
0
0
0
0
0
0
0
0
0
0
22
1
22
22
0.818182
0
0
0
0
0
0.565217
0
0
0
0
0
0
1
0
true
0
0
0
0
1
1
1
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
1
0
0
0
0
1
0
5
d7ddcf266435db3f1517c3fc265e401cb9c7020c
1,914
py
Python
test.py
jwnicholas99/rpi-moodlights
3f53c2a328086146ca808512ea0e4b3627f6b3fd
[ "MIT" ]
2
2022-02-22T03:56:58.000Z
2022-02-22T19:29:16.000Z
test.py
jwnicholas99/rpi-moodlights
3f53c2a328086146ca808512ea0e4b3627f6b3fd
[ "MIT" ]
2
2020-08-20T14:55:29.000Z
2020-08-20T14:58:08.000Z
test.py
jwnicholas99/rpi-moodlights
3f53c2a328086146ca808512ea0e4b3627f6b3fd
[ "MIT" ]
null
null
null
from utils.gui import convert_input def check_none(ret): if ret is not None: raise Exception def test_convert_input(): # Test bool ret = convert_input("1", "bool", "param", "bool") check_none(ret) ret = convert_input("3.67", "bool", "param", "bool") check_none(ret) ret = convert_input("-1000", "bool", "param", "bool") check_none(ret) # Test int ret = convert_input("1.0", "int", "param", " positive int") check_none(ret) ret = convert_input("-1", "int", "param", " positive int") check_none(ret) ret = convert_input("-1.0", "int", "param", " positive int") check_none(ret) ret = convert_input("True", "int", "param", " positive int") check_none(ret) ret = convert_input("[hello, moshi]", "int", "param", " positive int") check_none(ret) # Test float ret = convert_input("-1", "float", "param", " positive float") check_none(ret) ret = convert_input("-1.0", "float", "param", " positive float") check_none(ret) ret = convert_input("True", "float", "param", " positive float") check_none(ret) ret = convert_input("[hello, moshi]", "float", "param", " positive float") check_none(ret) # Test intensity ret = convert_input("25.01", "intensity", "param", "positive and between 0 and 255") check_none(ret) ret = convert_input("-1", "intensity", "param", "positive and between 0 and 255") check_none(ret) ret = convert_input("-1.0", "intensity", "param", "positive and between 0 and 255") check_none(ret) ret = convert_input("True", "intensity", "param", "positive and between 0 and 255") check_none(ret) ret = convert_input("[hello, moshi]", "intensity", "param", "positive and between 0 and 255") check_none(ret) # Test color ret = convert_input([], "color", "param", "non-empty") check_none(ret) test_convert_input()
28.567164
97
0.619645
257
1,914
4.451362
0.14786
0.22028
0.199301
0.170455
0.77535
0.77535
0.753497
0.685315
0.656469
0.586538
0
0.028439
0.210031
1,914
67
98
28.567164
0.728175
0.028736
0
0.428571
0
0
0.309061
0
0
0
0
0
0
1
0.047619
false
0
0.02381
0
0.071429
0
0
0
0
null
1
1
1
0
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
5
d7ef4b674ba89eaa3d3d2d45f63d24e0ea1aacde
34
py
Python
vecLib/setting.py
chenjl0710/arcpyTools
4f31e79f402cc2a0827450ab3aaba8f8d9a5f502
[ "MIT" ]
1
2019-07-07T17:46:55.000Z
2019-07-07T17:46:55.000Z
vecLib/setting.py
chenjl0710/arcpyTools
4f31e79f402cc2a0827450ab3aaba8f8d9a5f502
[ "MIT" ]
7
2021-03-31T18:45:40.000Z
2022-03-11T23:25:36.000Z
vecLib/setting.py
chenjl0710/arcpyTools
4f31e79f402cc2a0827450ab3aaba8f8d9a5f502
[ "MIT" ]
1
2020-07-21T00:13:07.000Z
2020-07-21T00:13:07.000Z
env = [r"D:\pyCodes\codes\vecLib"]
34
34
0.676471
6
34
3.833333
1
0
0
0
0
0
0
0
0
0
0
0
0.058824
34
1
34
34
0.71875
0
0
0
0
0
0.657143
0.657143
0
0
0
0
0
1
0
false
0
0
0
0
0
1
1
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
1
1
null
0
0
0
0
0
0
0
0
0
0
0
0
0
5
d7f6631eb69bab2cb19b25872aee2354f38a8bd5
116
py
Python
code/game/classes/lines/__init__.py
Maaack/SixX
ed92ddd3bc7d0d9612bdff36df6a208ae9a24fdd
[ "Apache-2.0" ]
1
2017-10-08T06:38:32.000Z
2017-10-08T06:38:32.000Z
code/game/classes/lines/__init__.py
Maaack/SixX
ed92ddd3bc7d0d9612bdff36df6a208ae9a24fdd
[ "Apache-2.0" ]
null
null
null
code/game/classes/lines/__init__.py
Maaack/SixX
ed92ddd3bc7d0d9612bdff36df6a208ae9a24fdd
[ "Apache-2.0" ]
null
null
null
from FadeInLine import FadeInLine from OutwardPulseLine import OutwardPulseLine from ChargeLines import ChargeLines
29
45
0.896552
12
116
8.666667
0.416667
0
0
0
0
0
0
0
0
0
0
0
0.103448
116
3
46
38.666667
1
0
0
0
0
0
0
0
0
0
0
0
0
1
0
true
0
1
0
1
0
1
0
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
1
0
1
0
1
0
0
5
cc1fd85732d076c5a79f1c23f21254cb19cd621f
72
py
Python
project/src/core/entities/email.py
CesarLinhares/list_contact
f939d0d601a0f71600dad9eb4bf9fa08029b313a
[ "MIT" ]
null
null
null
project/src/core/entities/email.py
CesarLinhares/list_contact
f939d0d601a0f71600dad9eb4bf9fa08029b313a
[ "MIT" ]
null
null
null
project/src/core/entities/email.py
CesarLinhares/list_contact
f939d0d601a0f71600dad9eb4bf9fa08029b313a
[ "MIT" ]
null
null
null
from pydantic import BaseModel class Email(BaseModel): email: str
12
30
0.75
9
72
6
0.777778
0
0
0
0
0
0
0
0
0
0
0
0.194444
72
5
31
14.4
0.931034
0
0
0
0
0
0
0
0
0
0
0
0
1
0
true
0
0.333333
0
1
0
1
0
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
1
0
1
0
1
0
0
5
cc205d604555853a66e275091be0921a4347d40c
145
py
Python
molecool/test.py
FeiQuantumSoftware/molecool
9a5b81484d6f6c66139bfc8c5e9e16cb10505662
[ "BSD-3-Clause" ]
null
null
null
molecool/test.py
FeiQuantumSoftware/molecool
9a5b81484d6f6c66139bfc8c5e9e16cb10505662
[ "BSD-3-Clause" ]
1
2022-02-03T16:25:22.000Z
2022-02-03T16:25:22.000Z
molecool/test.py
FeiQuantumSoftware/molecool
9a5b81484d6f6c66139bfc8c5e9e16cb10505662
[ "BSD-3-Clause" ]
null
null
null
import os from molecool import open_pdb pdb_file = os.path.join('molecool','data','pdb','water.pdb') symbols, coords = open_pdb(pdb_file) symbols
29
60
0.765517
24
145
4.458333
0.541667
0.130841
0.186916
0.261682
0
0
0
0
0
0
0
0
0.089655
145
5
61
29
0.810606
0
0
0
0
0
0.164384
0
0
0
0
0
0
1
0
false
0
0.4
0
0.4
0
1
0
0
null
0
1
1
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
0
0
1
0
0
0
0
5
cc2755571e57d81916ba728e0e537ca0ac934a59
164
py
Python
tests/02_single_trivial_function/one_liner_to_return_output.py
sadielbartholomew/debugulator
c7870b44e2f1b8a1cf35560b4b10f409ae0351d1
[ "MIT" ]
null
null
null
tests/02_single_trivial_function/one_liner_to_return_output.py
sadielbartholomew/debugulator
c7870b44e2f1b8a1cf35560b4b10f409ae0351d1
[ "MIT" ]
null
null
null
tests/02_single_trivial_function/one_liner_to_return_output.py
sadielbartholomew/debugulator
c7870b44e2f1b8a1cf35560b4b10f409ae0351d1
[ "MIT" ]
null
null
null
# <<<DBGL8R>>> def add_floats(float_1, float_2): """ Add two floating point numbers together. """ return float_1 + float_2 print('Hello world') # <<<DBGL8R
27.333333
52
0.658537
23
164
4.478261
0.695652
0.116505
0.213592
0.23301
0
0
0
0
0
0
0
0.044444
0.176829
164
5
53
32.8
0.718519
0.396341
0
0
0
0
0.120879
0
0
0
0
0
0
1
0.333333
false
0
0
0
0.666667
0.333333
1
0
0
null
0
1
1
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
1
0
0
0
0
0
0
0
5
0bcdcd0e47b8ca11bee15ed7c16c6884128f2fd7
61
py
Python
python_cowbull_game/__init__.py
dsandersAzure/python_cowbull_game
82a0d8ee127869123d4fad51a8cd1707879e368f
[ "Apache-2.0" ]
1
2017-05-01T20:13:40.000Z
2017-05-01T20:13:40.000Z
python_cowbull_game/__init__.py
dsandersAzure/python_cowbull_game
82a0d8ee127869123d4fad51a8cd1707879e368f
[ "Apache-2.0" ]
null
null
null
python_cowbull_game/__init__.py
dsandersAzure/python_cowbull_game
82a0d8ee127869123d4fad51a8cd1707879e368f
[ "Apache-2.0" ]
null
null
null
from python_cowbull_game.GameController import GameController
61
61
0.934426
7
61
7.857143
0.857143
0
0
0
0
0
0
0
0
0
0
0
0.04918
61
1
61
61
0.948276
0
0
0
0
0
0
0
0
0
0
0
0
1
0
true
0
1
0
1
0
1
0
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
1
0
1
0
1
0
0
5
0bff8caf9e29af2f16fc081375533102a19f5376
4,079
py
Python
tests/nuget_version_util_test.py
doneholmes/nuget-package-scanner
bd9669342bab680a9965648d0115e0aaedf984ca
[ "MIT" ]
2
2020-05-04T15:08:32.000Z
2020-10-26T15:11:16.000Z
tests/nuget_version_util_test.py
doneholmes/nuget-package-scanner
bd9669342bab680a9965648d0115e0aaedf984ca
[ "MIT" ]
87
2020-06-01T16:40:43.000Z
2022-03-24T16:31:33.000Z
tests/nuget_version_util_test.py
doneholmes/nuget-package-scanner
bd9669342bab680a9965648d0115e0aaedf984ca
[ "MIT" ]
2
2020-05-05T18:39:46.000Z
2021-11-09T19:17:50.000Z
import unittest from nuget_package_scanner.nuget import version_util as nugetversion from nuget_package_scanner.nuget import VersionPart as VersionPart class TestNugetVersion(unittest.TestCase): def test_get_version_part(self): m = nugetversion.pattern.match("1.2.3.4") self.assertEqual(nugetversion.get_version_part(m,VersionPart.MAJOR),1) self.assertEqual(nugetversion.get_version_part(m,VersionPart.MINOR),2) self.assertEqual(nugetversion.get_version_part(m,VersionPart.PATCH),3) self.assertEqual(nugetversion.get_version_part(m,VersionPart.BUILD),4) def test_get_version_part_default(self): m = nugetversion.pattern.match("1.2") self.assertEqual(nugetversion.get_version_part(m,VersionPart.MAJOR),1) self.assertEqual(nugetversion.get_version_part(m,VersionPart.MINOR),2) self.assertEqual(nugetversion.get_version_part(m,VersionPart.PATCH),0) def test_is_full_release_invalid_version(self): with self.assertRaises(AssertionError): nugetversion.is_full_release("not.a.version.nope") def test_is_full_release_false(self): self.assertFalse(nugetversion.is_full_release("1.2.3-beta")) self.assertFalse(nugetversion.is_full_release("1.2.3+build.1-rc")) self.assertFalse(nugetversion.is_full_release("1.2.3-beta+build.1-rc")) def test_is_full_release_true(self): self.assertTrue(nugetversion.is_full_release("1.2.3")) self.assertTrue(nugetversion.is_full_release("999.999.999")) self.assertTrue(nugetversion.is_full_release("1.2.3.4")) self.assertTrue(nugetversion.is_full_release("999.999.999.1")) def test_is_newer_release_invalid_version(self): with self.assertRaises(AssertionError): nugetversion.is_newer_release("not.a.version.nope", "1.2.3") def test_is_newer_release_invalid_compare_version(self): with self.assertRaises(AssertionError): nugetversion.is_newer_release("1.2.3", "not.a.version.nope") def test_is_newer_release_false(self): self.assertFalse(nugetversion.is_newer_release("1.2.40604.0921","1.2.40604.00920")) self.assertFalse(nugetversion.is_newer_release("1.2.3.4","1.2.3.4")) self.assertFalse(nugetversion.is_newer_release("1.2.3","0.7.9")) self.assertFalse(nugetversion.is_newer_release("1.2","1.2.0")) self.assertFalse(nugetversion.is_newer_release("1.2.0","1.2")) self.assertFalse(nugetversion.is_newer_release("3.3.105.24","3.3.4.16")) self.assertFalse(nugetversion.is_newer_release("3.3.105.24","3.3.105.16")) self.assertFalse(nugetversion.is_newer_release("3.3.105.24","3.3.105.24-beta")) def test_is_newer_release_true(self): self.assertTrue(nugetversion.is_newer_release("1.2.40604.0921","01.2.040604.00922")) self.assertTrue(nugetversion.is_newer_release("1.2","1.2.1")) self.assertTrue(nugetversion.is_newer_release("1.2","1.2.0.1")) self.assertTrue(nugetversion.is_newer_release("1.2.3","1.3.1")) self.assertTrue(nugetversion.is_newer_release("1.2.3","1.2.9")) self.assertTrue(nugetversion.is_newer_release("3.3.105.24","3.3.105.999-beta")) self.assertTrue(nugetversion.is_newer_release("3.3.105.24","3.3.105.999")) self.assertTrue(nugetversion.is_newer_release("1.2.3","3.0.0")) def test_get_version_count_behind_basic(self): result = nugetversion.get_version_count_behind("1.2.3","2.0.0") self.assertEqual(list(result.values()), [1,0,0]) result = nugetversion.get_version_count_behind("2.1.1","2.1.1") self.assertEqual(list(result.values()), [0,0,0]) result = nugetversion.get_version_count_behind("1.99.1","1.299.0") self.assertEqual(list(result.values()), [0,200,0]) result = nugetversion.get_version_count_behind("1.1.1","1.1.009") self.assertEqual(list(result.values()), [0,0,8]) if __name__ == '__main__': unittest.main()
52.974026
102
0.696739
590
4,079
4.588136
0.130508
0.021426
0.113779
0.172885
0.895456
0.850757
0.78611
0.683044
0.558182
0.41485
0
0.078216
0.153714
4,079
77
103
52.974026
0.705968
0
0
0.112903
0
0
0.114706
0.005147
0
0
0
0
0.596774
1
0.16129
false
0
0.048387
0
0.225806
0
0
0
0
null
0
0
1
1
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
null
0
0
0
1
0
0
0
0
0
0
0
0
0
5
04009920ad64185c80661d179dfc202f8771aeae
129
py
Python
src/fastapi_quickcrud/__init__.py
aebrahim/FastAPIQuickCRUD
5c4d1bea2203c30eb21557f18bf9016b55fffa60
[ "MIT" ]
123
2021-08-17T01:54:12.000Z
2022-03-29T20:41:56.000Z
src/fastapi_quickcrud/__init__.py
aebrahim/FastAPIQuickCRUD
5c4d1bea2203c30eb21557f18bf9016b55fffa60
[ "MIT" ]
10
2021-12-28T21:34:20.000Z
2022-03-16T13:31:24.000Z
src/fastapi_quickcrud/__init__.py
aebrahim/FastAPIQuickCRUD
5c4d1bea2203c30eb21557f18bf9016b55fffa60
[ "MIT" ]
10
2021-08-17T07:37:36.000Z
2022-03-31T13:16:55.000Z
from .misc.utils import sqlalchemy_to_pydantic from .crud_router import crud_router_builder from .misc.type import CrudMethods
21.5
46
0.852713
19
129
5.526316
0.631579
0.152381
0
0
0
0
0
0
0
0
0
0
0.108527
129
5
47
25.8
0.913043
0
0
0
0
0
0
0
0
0
0
0
0
1
0
true
0
1
0
1
0
1
0
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
1
0
1
0
1
0
0
5
041351eaf35b129bac50d0c1d1f61aa06ebf166a
36
py
Python
Python/Free_Code_Camp/Set_Up_and_Helloworld/main.py
Josh-Luedke/Vision-Notes
544e9ef53dbf34e19af5144012b90bfa19012c16
[ "MIT" ]
null
null
null
Python/Free_Code_Camp/Set_Up_and_Helloworld/main.py
Josh-Luedke/Vision-Notes
544e9ef53dbf34e19af5144012b90bfa19012c16
[ "MIT" ]
null
null
null
Python/Free_Code_Camp/Set_Up_and_Helloworld/main.py
Josh-Luedke/Vision-Notes
544e9ef53dbf34e19af5144012b90bfa19012c16
[ "MIT" ]
null
null
null
# Basic Code print ("Helloworld")
12
21
0.666667
4
36
6
1
0
0
0
0
0
0
0
0
0
0
0
0.194444
36
2
22
18
0.827586
0.277778
0
0
0
0
0.434783
0
0
0
0
0
0
1
0
true
0
0
0
0
1
1
1
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
1
0
0
0
0
1
0
5
041390c848643ff84f4ff189a5d9acbacb202d1e
22
py
Python
alig/kr/__init__.py
moeraza/ali-g
342e24e139fc1e75f4bf576d0784ed886f305cf8
[ "MIT" ]
null
null
null
alig/kr/__init__.py
moeraza/ali-g
342e24e139fc1e75f4bf576d0784ed886f305cf8
[ "MIT" ]
null
null
null
alig/kr/__init__.py
moeraza/ali-g
342e24e139fc1e75f4bf576d0784ed886f305cf8
[ "MIT" ]
null
null
null
from .alig import AliG
22
22
0.818182
4
22
4.5
0.75
0
0
0
0
0
0
0
0
0
0
0
0.136364
22
1
22
22
0.947368
0
0
0
0
0
0
0
0
0
0
0
0
1
0
true
0
1
0
1
0
1
1
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
1
0
1
0
0
0
0
5
0423fe784d327970b05a2deae123b8508d6f6985
20,291
py
Python
osm_alkis_tool/views.py
omniscale/osm-alkis-tool
f4a52648f3c104bcdea053260237c070360b6757
[ "Apache-2.0" ]
1
2020-07-20T18:10:11.000Z
2020-07-20T18:10:11.000Z
osm_alkis_tool/views.py
omniscale/osm-alkis-tool
f4a52648f3c104bcdea053260237c070360b6757
[ "Apache-2.0" ]
null
null
null
osm_alkis_tool/views.py
omniscale/osm-alkis-tool
f4a52648f3c104bcdea053260237c070360b6757
[ "Apache-2.0" ]
null
null
null
# -*- coding: utf-8 -*- # pylint: disable=unused-argument from __future__ import absolute_import import argparse import csv import itertools import re from io import open import yaml VIEW_TEMPLATE = """DROP VIEW IF EXISTS %(view_schema)s.%(view_name)s; CREATE VIEW %(view_schema)s.%(view_name)s AS SELECT \n%(columns)s \n\tFROM %(source)s;\n""" REDIRECT_VIEW_TEMPLATE = """DROP VIEW IF EXISTS %(view_schema)s.%(view_name)s; CREATE VIEW %(view_schema)s.%(view_name)s AS SELECT * FROM %(osm_schema)s.%(osm_table)s;\n""" def source_table_exist(cursor, schema, table): query = """SELECT EXISTS ( SELECT 1 FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace WHERE n.nspname = %(schema)s AND c.relname = %(table)s );""" cursor.execute(query, {'schema': schema, 'table': table}) return cursor.fetchone()[0] def osm_tables_from_db(cursor, schema): query = """SELECT table_name FROM information_schema.tables WHERE table_schema=%(schema)s AND table_type='BASE TABLE';""" cursor.execute(query, {'schema': schema}) return [r[0] for r in cursor.fetchall()] def read_type_mapping(type_mapping_file): mapping = {} with open(type_mapping_file, 'r', encoding='utf-8') as csv_file: reader = csv.DictReader(csv_file, delimiter=';') for row in reader: source_table = row['objektart'] short_source = row['short_source'] source_attribute = row['attribut'] source_value = row['wert'] target_table = row['osm_tabelle'] target_value = row['styled_osm_type'] # list of additional columns with their target name and source SQL extra_columns = dict(zip( [c for c in row.get('extra_columns', '').split(',') if c], [c for c in row.get('extra_columns_sql', '').split(',') if c], )) if target_value == '': continue if target_table not in mapping: mapping[target_table] = { 'sources': {} } if source_table not in mapping[target_table]['sources']: mapping[target_table]['sources'][source_table] = { 'short_source': short_source, 'type_mapping': {}, 'extra_columns': extra_columns, } if source_attribute == '': mapping[target_table]['sources'][source_table] = { 'short_source': short_source, 'type': target_value, 'type_mapping': {}, 'extra_columns': {}, } continue mapping[target_table]['sources'][source_table]['type_mapping'].setdefault(source_attribute, []).append((source_value, target_value)) mapping[target_table]['sources'][source_table]['extra_columns'].update(extra_columns) return mapping def fnk_read_type_mapping(type_mapping_file): mapping = {} with open(type_mapping_file, 'r', encoding='utf-8') as csv_file: reader = csv.DictReader(csv_file, delimiter=';') for row in reader: source_table = 'fnk' source_attribute = row['attribut'] source_value = row['wert'] target_table = row['osm_tabelle'] target_value = row['styled_osm_type'] # list of additional columns with their target name and source SQL extra_columns = dict(zip( [c for c in row.get('extra_columns', '').split(',') if c], [c for c in row.get('extra_columns_sql', '').split(',') if c], )) if target_value == '': continue if target_table not in mapping: mapping[target_table] = { 'sources': {} } if source_table not in mapping[target_table]['sources']: mapping[target_table]['sources'][source_table] = { 'type_mapping': {}, 'extra_columns': extra_columns, } if source_attribute == '': mapping[target_table]['sources'][source_table] = { 'type': target_value, 'type_mapping': {}, 'extra_columns': {}, } continue mapping[target_table]['sources'][source_table]['type_mapping'].setdefault(source_attribute, []).append((source_value, target_value)) mapping[target_table]['sources'][source_table]['extra_columns'].update(extra_columns) return mapping def atkis_read_type_mapping(type_mapping_file): mapping = {} with open(type_mapping_file, 'r', encoding='utf-8') as csv_file: reader = csv.DictReader(csv_file, delimiter=';') for row in reader: source_table = row['tabelle'] source_attribute = row['attribut'] source_value = row['wert'] target_table = row['osm_tabelle'] target_value = row['styled_osm_type'] # list of additional columns with their target name and source SQL extra_columns = dict(zip( [c for c in row.get('extra_columns', '').split(',') if c], [c for c in row.get('extra_columns_sql', '').split(',') if c], )) if target_value == '': continue if target_table not in mapping: mapping[target_table] = { 'sources': {} } if source_table not in mapping[target_table]['sources']: mapping[target_table]['sources'][source_table] = { 'type_mapping': {}, 'extra_columns': extra_columns, } if source_attribute == '': mapping[target_table]['sources'][source_table] = { 'type': target_value, 'type_mapping': {}, 'extra_columns': {}, } continue mapping[target_table]['sources'][source_table]['type_mapping'].setdefault(source_attribute, []).append((source_value, target_value)) mapping[target_table]['sources'][source_table]['extra_columns'].update(extra_columns) return mapping def indent_lines(lines, tabs=1): return ['\t'*tabs + l for l in lines] def create_views(type_mapping, mappings, alkis_schema, view_schema, alkis_srid=25832): views = [] typed_views = mappings.define_typed_views() single_table_views = mappings.define_single_table_views() for view in single_table_views: views.append(view) for name, view in typed_views.items(): views.append(typed_view( name=name, view=view, mapping=type_mapping[name], alkis_schema='{{alkis_schema}}', view_schema='{{view_schema}}', )) return ''.join(views) def create_fnk_views(type_mapping, mappings, fnk_schema, view_schema, fnk_srid=25832): views = [] typed_views = mappings.define_typed_views() for name, view in typed_views.items(): views.append(fnk_typed_view( name=name, view=view, mapping=type_mapping[name], fnk_schema='{{fnk_schema}}', view_schema='{{view_schema}}', )) return ''.join(views) def create_atkis_views(type_mapping, mappings, atkis_schema, view_schema, atkis_srid=25832): views = [] typed_views = mappings.define_typed_views() for name, view in typed_views.items(): views.append(atkis_typed_view( name=name, view=view, mapping=type_mapping[name], atkis_schema='{{atkis_schema}}', view_schema='{{view_schema}}', )) return ''.join(views) def create_osm_views(osm_schema, view_schema, osm_tables=None): views = [] for table in osm_tables or []: views.append(REDIRECT_VIEW_TEMPLATE % { 'view_schema': view_schema, 'view_name': table, 'osm_schema': osm_schema, 'osm_table': table }) return ''.join(views) def typed_view(name, view, mapping, alkis_schema, view_schema): column_defs = ['\ttype::VARCHAR AS "type"'] columns = {} for column, value in view['columns'].items(): column_defs.append('''\t%(value)s::%(type)s AS "%(column)s"''' % { 'value': value[1], 'type': value[0], 'column': column }) if value[1] not in ('NULL', '0'): columns[value[1]] = value[0] # remove 'special' columns to get all additional columns additional_columns = dict(columns) for c in [ 'short_source', 'type', 'code', 'gml_id', 'wkb_geometry', ]: additional_columns.pop(c, None) # also remove columns that contain wkb_geometry, for columns like # `ST_Area(wkb_geometry)` for c in list(additional_columns.keys()): if re.match(r'.*\bwkb_geometry\b', c): additional_columns.pop(c, None) queries = [] for source_table, mapping_data in mapping['sources'].items(): source_columns = [] code_column = None if 'type' in mapping_data: source_columns.append("'%s' AS type" % mapping_data['type']) else: type_mapping = [] for source_column in mapping_data['type_mapping']: code_column = source_column for values in mapping_data['type_mapping'][source_column]: source_value, target_value = values type_mapping.append((source_column, source_value, target_value)) source_columns.append(type_case_mapping(type_mapping, default='NULL', name='type')) if 'short_source' in mapping_data: source_columns.append("'%s' AS short_source" % mapping_data['short_source']) else: source_columns.append("NULL::VARCHAR AS short_source") if code_column: source_columns.append("%s.%s AS code" % (source_table, code_column)) else: source_columns.append("NULL::INT AS code") for col, typ in additional_columns.items(): if col in mapping_data['extra_columns']: sql = mapping_data['extra_columns'][col] source_columns.append('%s::%s AS %s' % (sql, typ, col)) else: source_columns.append('NULL AS ' + col) source_columns.append('gml_id') source_columns.append('wkb_geometry') filters = [geom_type_filter(view)] if 'filter' in view: for exclude_table, f in view['filter']: if exclude_table == source_table: filters.append(f) source_columns = indent_lines(source_columns, 2) query = "\tSELECT\n %s \n\tFROM %s.%s\n" % (',\n'.join(source_columns), alkis_schema, source_table) if len(filters) > 0: query += "\tWHERE %s\n" % '\n\tAND '.join(filters) queries.append(query) return VIEW_TEMPLATE % { 'view_schema': view_schema, 'view_name': name, 'columns': ',\n'.join(column_defs), 'source': '( %s ) as data WHERE type IS NOT NULL' % '\tUNION ALL\n'.join(queries) } def fnk_typed_view(name, view, mapping, fnk_schema, view_schema): column_defs = ['\ttype::VARCHAR AS "type"'] columns = {} for column, value in view['columns'].items(): column_defs.append('''\t%(value)s::%(type)s AS "%(column)s"''' % { 'value': value[1], 'type': value[0], 'column': column }) if value[1] not in ('NULL', '0'): columns[value[1]] = value[0] # remove 'special' columns to get all additional columns additional_columns = dict(columns) for c in [ 'short_source', 'type', 'code', 'wkb_geometry', 'objectid', ]: additional_columns.pop(c, None) # also remove columns that contain wkb_geometry, for columns like # `ST_Area(wkb_geometry)` for c in list(additional_columns.keys()): if re.match(r'.*\bwkb_geometry\b', c): additional_columns.pop(c, None) queries = [] for source_table, mapping_data in mapping['sources'].items(): source_columns = [] code_column = None if 'type' in mapping_data: source_columns.append("'%s' AS type" % mapping_data['type']) else: type_mapping = [] for source_column in mapping_data['type_mapping']: code_column = source_column for values in mapping_data['type_mapping'][source_column]: source_value, target_value = values type_mapping.append((source_column, source_value, target_value)) source_columns.append(type_case_mapping(type_mapping, default='NULL', name='type')) source_columns.append("NULL::VARCHAR AS short_source") if code_column: source_columns.append("%s.%s AS code" % (source_table, code_column)) else: source_columns.append("NULL::INT AS code") for col, typ in additional_columns.items(): if col in mapping_data['extra_columns']: sql = mapping_data['extra_columns'][col] source_columns.append('%s::%s AS %s' % (sql, typ, col)) else: source_columns.append('NULL AS ' + col) source_columns.append('objectid') source_columns.append('wkb_geometry') filters = [geom_type_filter(view)] if 'filter' in view: for exclude_table, f in view['filter']: if exclude_table == source_table: filters.append(f) source_columns = indent_lines(source_columns, 2) query = "\tSELECT\n %s \n\tFROM %s.%s\n" % (',\n'.join(source_columns), fnk_schema, source_table) if len(filters) > 0: query += "\tWHERE %s\n" % '\n\tAND '.join(filters) queries.append(query) return VIEW_TEMPLATE % { 'view_schema': view_schema, 'view_name': name, 'columns': ',\n'.join(column_defs), 'source': '( %s ) as data WHERE type IS NOT NULL' % '\tUNION ALL\n'.join(queries) } def atkis_typed_view(name, view, mapping, atkis_schema, view_schema): column_defs = ['\ttype::VARCHAR AS "type"'] columns = {} for column, value in view['columns'].items(): column_defs.append('''\t%(value)s::%(type)s AS "%(column)s"''' % { 'value': value[1], 'type': value[0], 'column': column }) if value[1] not in ('NULL', '0'): columns[value[1]] = value[0] # remove 'special' columns to get all additional columns additional_columns = dict(columns) for c in [ 'short_source', 'nam', 'code', 'wkb_geometry', 'type', 'objid', ]: additional_columns.pop(c, None) # also remove columns that contain wkb_geometry, for columns like # `ST_Area(wkb_geometry)` for c in list(additional_columns.keys()): if re.match(r'.*\bwkb_geometry\b', c): additional_columns.pop(c, None) queries = [] for source_table, mapping_data in mapping['sources'].items(): source_columns = [] code_column = None if 'type' in mapping_data: source_columns.append("'%s' AS type" % mapping_data['type']) else: type_mapping = [] for source_column in mapping_data['type_mapping']: code_column = source_column for values in mapping_data['type_mapping'][source_column]: source_value, target_value = values type_mapping.append((source_column, source_value, target_value)) source_columns.append(type_case_mapping(type_mapping, default='NULL', name='type')) source_columns.append("NULL::VARCHAR AS short_source") if code_column: source_columns.append("%s.%s AS code" % (source_table, code_column)) else: source_columns.append("NULL::INT AS code") for col, typ in additional_columns.items(): if col in mapping_data['extra_columns']: sql = mapping_data['extra_columns'][col] source_columns.append('%s::%s AS %s' % (sql, typ, col)) else: source_columns.append('NULL AS ' + col) source_columns.append('nam') source_columns.append('objid') source_columns.append('wkb_geometry') filters = [geom_type_filter(view)] if 'filter' in view: for exclude_table, f in view['filter']: if exclude_table == source_table: filters.append(f) source_columns = indent_lines(source_columns, 2) query = "\tSELECT\n %s \n\tFROM %s.%s\n" % (',\n'.join(source_columns), atkis_schema, source_table) if len(filters) > 0: query += "\tWHERE %s\n" % '\n\tAND '.join(filters) queries.append(query) return VIEW_TEMPLATE % { 'view_schema': view_schema, 'view_name': name, 'columns': ',\n'.join(column_defs), 'source': '( %s ) as data WHERE type IS NOT NULL' % '\tUNION ALL\n'.join(queries) } def type_case_mapping(checks, default=None, name=None): """ >>> type_case_mapping([('foo', 1, 'bar')]) "CASE\\n\\t\\t\\tWHEN foo = 1 THEN 'bar'\\n\\t\\tEND" >>> type_case_mapping([('foo', 1, 'bar'), ('foo', 4, 'bar')], 'baz', 'type') "CASE\\n\\t\\t\\tWHEN foo IN (1, 4) THEN 'bar'\\n\\t\\t\\tELSE baz\\n\\t\\tEND AS type" """ whens = [] checks.sort(key=lambda x: (x[0], x[2])) for group, it in itertools.groupby(checks, lambda x: (x[0], x[2])): check = list(it) if len(check) == 1: whens.append("WHEN %s = %s THEN '%s'" % check[0]) else: ins = ', '.join(str(c[1]) for c in check) whens.append("WHEN %s IN (%s) THEN '%s'" % (group[0], ins, group[1])) whens = indent_lines(whens, 3) result = 'CASE\n' + '\n'.join(whens) if default: result += '\n\t\t\tELSE %s' % default result += '\n\t\tEND' if name: result += ' AS %s' % name return result def geom_type_filter(view): geom_type = view.get('geometry_type') if geom_type == 'Point': filter_types = "'ST_Point'" elif geom_type == 'Line': filter_types = "'ST_LineString', 'ST_MultiLineString'" elif geom_type in ('Polygon', None): filter_types = "'ST_Polygon','ST_MultiPolygon'" else: raise ValueError("unsupported geometry_type %s" % geom_type) return "ST_GeometryType(wkb_geometry) IN (%s)" % filter_types def prepare_options(argv=None): parser = argparse.ArgumentParser(description='Create views for combining OSM with ALKIS data') parser.add_argument('--alkis-srid', help='SRID of alkis tables', default='25832', ) parser.add_argument('--alkis-schema', help='Schema alkis tables are in', default='alkis', ) parser.add_argument('--osm-schema', help='Schema osm tables are in', default='osm', ) parser.add_argument('--view-schema', help='Target schema for created views', default='public', ) parser.add_argument('--type-mapping', dest='type_mapping_file', help='CSV file mapping alkis values to osm values', default='type_mapping.csv', ) parser.add_argument('--osm-mapping', help='Imposm3 mapping JSON', ) options = parser.parse_args(argv) return options def osm_tables_from_imposm_mapping(imposm_mapping): with open(imposm_mapping) as f: osm_mapping = yaml.safe_load(f) osm_tables = osm_mapping['tables'].keys() + osm_mapping['generalized_tables'].keys() osm_tables = ['osm_' + t for t in osm_tables] # use default prefix return osm_tables
34.68547
144
0.5739
2,410
20,291
4.609959
0.093776
0.044554
0.049595
0.040504
0.757066
0.744824
0.736184
0.736184
0.729433
0.721602
0
0.004817
0.294121
20,291
584
145
34.744863
0.770858
0.046375
0
0.682119
0
0.004415
0.183576
0.01773
0.002208
0
0
0
0
1
0.037528
false
0
0.015453
0.002208
0.090508
0
0
0
0
null
0
0
0
0
1
1
1
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
5
043bb66745bb32d1aa4fe3ca5a89d239e3813d52
181
py
Python
fetching/__init__.py
xyla-io/almacen
7b7f235dc7939777f971f1b5eadd5621e980c15e
[ "MIT" ]
2
2020-10-15T22:12:17.000Z
2020-10-26T07:17:17.000Z
fetching/__init__.py
xyla-io/almacen
7b7f235dc7939777f971f1b5eadd5621e980c15e
[ "MIT" ]
null
null
null
fetching/__init__.py
xyla-io/almacen
7b7f235dc7939777f971f1b5eadd5621e980c15e
[ "MIT" ]
null
null
null
from .base import ReportFetcher from .fetch_date_base import ReportDateFetcher from .fetch_date_factory import report_date_fetcher from .fetch_report_factory import report_fetcher
30.166667
51
0.883978
25
181
6.04
0.4
0.178808
0.172185
0
0
0
0
0
0
0
0
0
0.093923
181
5
52
36.2
0.920732
0
0
0
0
0
0
0
0
0
0
0
0
1
0
true
0
1
0
1
0
1
0
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
1
0
1
0
1
0
0
5
f0acc13ec0b4b3e31021cb82ada90158db8c057f
350
py
Python
acquisition/shopping_api.py
lene/style-scout
e100c718bf6ea5a30f3260eb196dd554afccbba3
[ "BSD-3-Clause" ]
null
null
null
acquisition/shopping_api.py
lene/style-scout
e100c718bf6ea5a30f3260eb196dd554afccbba3
[ "BSD-3-Clause" ]
27
2017-04-08T12:44:34.000Z
2018-04-24T11:01:04.000Z
acquisition/shopping_api.py
lene/style-scout
e100c718bf6ea5a30f3260eb196dd554afccbba3
[ "BSD-3-Clause" ]
null
null
null
from typing import Any, Dict, List class ShoppingApi: def categories(self, root_id: int) -> List[Any]: raise NotImplementedError() def get_category_items(self, category: Any, limit: int=100, page: int=1) -> Any: raise NotImplementedError() def get_item(self, item_id: int) -> Dict: raise NotImplementedError()
26.923077
84
0.674286
44
350
5.25
0.545455
0.311688
0.233766
0.25974
0.285714
0
0
0
0
0
0
0.014599
0.217143
350
12
85
29.166667
0.828467
0
0
0.375
0
0
0
0
0
0
0
0
0
1
0.375
false
0
0.125
0
0.625
0
0
0
0
null
1
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
1
0
0
0
0
1
0
0
5
f0d28d97d86d87a86280b5d3ca750d51c7bc38f0
60
py
Python
tests.py
scottbarnes/smart-team-maker
3663965df312af6894eacfd760d81d1b654c5cf7
[ "MIT" ]
null
null
null
tests.py
scottbarnes/smart-team-maker
3663965df312af6894eacfd760d81d1b654c5cf7
[ "MIT" ]
null
null
null
tests.py
scottbarnes/smart-team-maker
3663965df312af6894eacfd760d81d1b654c5cf7
[ "MIT" ]
null
null
null
import unittest from main import \ team_creator \
10
22
0.666667
7
60
5.571429
0.857143
0
0
0
0
0
0
0
0
0
0
0
0.3
60
5
23
12
0.928571
0
0
0
0
0
0
0
0
0
0
0
0
1
0
true
0
0.666667
0
0.666667
0
1
0
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
1
0
1
0
1
0
0
5
f0d740d44a26228ad910d57cd6258bea1d40d4ba
101
py
Python
signalanalysis/__init__.py
p-j-smith/signalanalysis
cea41a8f806a9121380c90e19caea009ee1492b5
[ "Apache-2.0" ]
1
2021-11-02T13:52:21.000Z
2021-11-02T13:52:21.000Z
signalanalysis/__init__.py
p-j-smith/signalanalysis
cea41a8f806a9121380c90e19caea009ee1492b5
[ "Apache-2.0" ]
4
2022-01-14T17:09:09.000Z
2022-01-25T09:57:55.000Z
signalanalysis/__init__.py
p-j-smith/signalanalysis
cea41a8f806a9121380c90e19caea009ee1492b5
[ "Apache-2.0" ]
1
2022-01-11T10:11:21.000Z
2022-01-11T10:11:21.000Z
__all__ = ['signalanalysis', 'signalplot', 'tools'] from . import signalanalysis, signalplot, tools
25.25
51
0.742574
9
101
7.888889
0.666667
0.676056
0.816901
0
0
0
0
0
0
0
0
0
0.118812
101
3
52
33.666667
0.797753
0
0
0
0
0
0.287129
0
0
0
0
0
0
1
0
false
0
0.5
0
0.5
0
1
0
0
null
1
1
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
0
0
1
0
0
0
0
5
0b1cee68ecde62a93181c8154b20554ecf96ade2
132
py
Python
python/fate_arch/federation/pulsar/__init__.py
hubert-he/FATE
6758e150bd7ca7d6f788f9a7a8c8aea7e6500363
[ "Apache-2.0" ]
3,787
2019-08-30T04:55:10.000Z
2022-03-31T23:30:07.000Z
python/fate_arch/federation/pulsar/__init__.py
JavaGreenHands/FATE
ea1e94b6be50c70c354d1861093187e523af32f2
[ "Apache-2.0" ]
1,439
2019-08-29T16:35:52.000Z
2022-03-31T11:55:31.000Z
python/fate_arch/federation/pulsar/__init__.py
JavaGreenHands/FATE
ea1e94b6be50c70c354d1861093187e523af32f2
[ "Apache-2.0" ]
1,179
2019-08-29T16:18:32.000Z
2022-03-31T12:55:38.000Z
from fate_arch.federation.pulsar._federation import Federation, MQ, PulsarManager __all__ = ['Federation', 'MQ', 'PulsarManager']
26.4
81
0.780303
14
132
6.928571
0.642857
0.247423
0.515464
0
0
0
0
0
0
0
0
0
0.098485
132
4
82
33
0.815126
0
0
0
0
0
0.19084
0
0
0
0
0
0
1
0
false
0
0.5
0
0.5
0
1
0
0
null
1
1
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
0
0
1
0
0
0
0
5
0b1da42c13ca57fafa3abc86b7596bce8bc48620
44
py
Python
bitl/__init__.py
tritas/bitl
f394e633e38f983fed10c3e672af7be2883cbdbb
[ "BSD-3-Clause" ]
1
2017-06-30T08:50:49.000Z
2017-06-30T08:50:49.000Z
bitl/__init__.py
tritas/bitl
f394e633e38f983fed10c3e672af7be2883cbdbb
[ "BSD-3-Clause" ]
null
null
null
bitl/__init__.py
tritas/bitl
f394e633e38f983fed10c3e672af7be2883cbdbb
[ "BSD-3-Clause" ]
null
null
null
# coding=utf-8 # Copyright 2019 Aris Tritas
14.666667
28
0.75
7
44
4.714286
1
0
0
0
0
0
0
0
0
0
0
0.135135
0.159091
44
2
29
22
0.756757
0.886364
0
null
0
null
0
0
null
0
0
0
null
1
null
true
0
0
null
null
null
1
1
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
1
0
0
0
0
0
0
null
0
0
0
0
0
0
1
0
0
0
0
0
0
5
9be2264b665ebd00eb5ec04f80e094fe8a8bfdb9
39
py
Python
hello-python/hello-world.py
florianbussmann/hello-world
f36cade4b04c7cc9e10e81e6a1b1b5c34816895a
[ "MIT" ]
2
2015-03-15T03:13:01.000Z
2021-05-31T11:55:35.000Z
hello-python/hello-world.py
florianbussmann/hello-world
f36cade4b04c7cc9e10e81e6a1b1b5c34816895a
[ "MIT" ]
1
2015-01-28T19:47:01.000Z
2015-01-28T19:47:01.000Z
hello-python/hello-world.py
florianbussmann/hello-world
f36cade4b04c7cc9e10e81e6a1b1b5c34816895a
[ "MIT" ]
3
2015-01-25T00:20:49.000Z
2015-04-13T03:39:05.000Z
#!/usr/bin/python print "Hello, World."
19.5
21
0.692308
6
39
4.5
1
0
0
0
0
0
0
0
0
0
0
0
0.076923
39
2
21
19.5
0.75
0.410256
0
0
0
0
0.565217
0
0
0
0
0
0
0
null
null
0
0
null
null
1
1
1
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
1
0
0
0
0
0
0
1
0
5
50428e09c9822b5e043ef4102ea1311ed181dd9a
41
py
Python
tests/__init__.py
aitaro/gcf_dev_gen
d3d13f559d0cfe8bb23c03d5efce1da99534e02f
[ "MIT" ]
null
null
null
tests/__init__.py
aitaro/gcf_dev_gen
d3d13f559d0cfe8bb23c03d5efce1da99534e02f
[ "MIT" ]
null
null
null
tests/__init__.py
aitaro/gcf_dev_gen
d3d13f559d0cfe8bb23c03d5efce1da99534e02f
[ "MIT" ]
null
null
null
"""Unit test package for gcf_dev_gen."""
20.5
40
0.707317
7
41
3.857143
1
0
0
0
0
0
0
0
0
0
0
0
0.121951
41
1
41
41
0.75
0.829268
0
null
0
null
0
0
null
0
0
0
null
1
null
true
0
0
null
null
null
1
1
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
1
0
0
0
0
0
0
null
0
0
0
0
0
0
1
0
0
0
0
0
0
5
5044217e5c3bc41f3b6c29058798f4b1f89b7989
39
py
Python
tests/__init__.py
burtonrj/platemate
5f243906dd36df831eade91758eb0392a572f52d
[ "MIT" ]
null
null
null
tests/__init__.py
burtonrj/platemate
5f243906dd36df831eade91758eb0392a572f52d
[ "MIT" ]
null
null
null
tests/__init__.py
burtonrj/platemate
5f243906dd36df831eade91758eb0392a572f52d
[ "MIT" ]
null
null
null
"""Unit test package for platemate."""
19.5
38
0.692308
5
39
5.4
1
0
0
0
0
0
0
0
0
0
0
0
0.128205
39
1
39
39
0.794118
0.820513
0
null
0
null
0
0
null
0
0
0
null
1
null
true
0
0
null
null
null
1
1
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
1
0
0
0
0
0
0
null
0
0
0
0
0
0
1
0
0
0
0
0
0
5
ac9ee35aa3a0cc5dceffbe63e66c550500f30e07
62
py
Python
source/controllers/__init__.py
omerk2511/TakiServer
f162d80e1b48f739c77c31a942416bd60b3f5af6
[ "MIT" ]
4
2020-10-07T16:50:07.000Z
2020-10-30T11:27:53.000Z
source/controllers/__init__.py
omerk2511/TakiServer
f162d80e1b48f739c77c31a942416bd60b3f5af6
[ "MIT" ]
2
2020-10-14T16:43:48.000Z
2020-10-25T12:41:51.000Z
source/controllers/__init__.py
omerk2511/TakiServer
f162d80e1b48f739c77c31a942416bd60b3f5af6
[ "MIT" ]
1
2020-10-10T14:29:51.000Z
2020-10-10T14:29:51.000Z
from controller import get_controller_func from game import *
20.666667
42
0.854839
9
62
5.666667
0.666667
0
0
0
0
0
0
0
0
0
0
0
0.129032
62
2
43
31
0.944444
0
0
0
0
0
0
0
0
0
0
0
0
1
0
true
0
1
0
1
0
1
0
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
1
0
1
0
1
0
0
5
acfc20f2e06045c213664f4eb8afac1d810f584a
6,579
py
Python
test/test_index.py
Scartography/mapchete
f7d1a74acb4021adfd3053501416d2b974c40af9
[ "MIT" ]
161
2016-02-20T15:18:13.000Z
2022-03-28T11:55:32.000Z
test/test_index.py
Scartography/mapchete
f7d1a74acb4021adfd3053501416d2b974c40af9
[ "MIT" ]
387
2015-08-12T07:16:56.000Z
2022-03-30T14:27:12.000Z
test/test_index.py
Scartography/mapchete
f7d1a74acb4021adfd3053501416d2b974c40af9
[ "MIT" ]
20
2016-02-22T12:51:54.000Z
2022-01-30T22:54:08.000Z
import fiona import numpy as np import os import pytest import rasterio import mapchete from mapchete.index import zoom_index_gen from mapchete.io import get_boto3_bucket @pytest.mark.remote def test_remote_indexes(mp_s3_tmpdir, gtiff_s3): zoom = 7 gtiff_s3.dict.update(zoom_levels=zoom) def gen_indexes_and_check(): # generate indexes list( zoom_index_gen( mp=mp, zoom=zoom, out_dir=mp.config.output.path, geojson=True, txt=True, vrt=True, ) ) # assert GeoJSON exists with fiona.open( os.path.join(mp.config.output.path, "%s.geojson" % zoom) ) as src: assert len(src) == 2 # assert TXT exists txt_index = os.path.join(mp.config.output.path, "%s.txt" % zoom) bucket = get_boto3_bucket(txt_index.split("/")[2]) key = "/".join(txt_index.split("/")[3:]) for obj in bucket.objects.filter(Prefix=key): if obj.key == key: content = obj.get()["Body"].read().decode() assert len([l + "\n" for l in content.split("\n") if l]) == 2 # assert VRT exists with rasterio.open(os.path.join(mp.config.output.path, "%s.vrt" % zoom)) as src: assert src.read().any() with mapchete.open(gtiff_s3.dict) as mp: # write output data mp.batch_process(zoom=zoom) # generate indexes and check gen_indexes_and_check() # generate indexes again and assert nothing has changes gen_indexes_and_check() def test_vrt(mp_tmpdir, cleantopo_br): zoom = 8 with mapchete.open( dict(cleantopo_br.dict, zoom_levels=dict(min=0, max=zoom)) ) as mp: # generate output mp.batch_process(zoom=zoom) # generate index list( zoom_index_gen( mp=mp, zoom=zoom, out_dir=mp.config.output.path, vrt=True, ) ) output_tiles = list( mp.config.output_pyramid.tiles_from_bounds( mp.config.bounds_at_zoom(zoom=zoom), zoom=zoom ) ) bounds = ( min([t.left for t in output_tiles]), min([t.bottom for t in output_tiles]), max([t.right for t in output_tiles]), max([t.top for t in output_tiles]), ) # bounds = mp.config.effective_bounds vrt_index = os.path.join(mp.config.output.path, "%s.vrt" % zoom) with rasterio.open(vrt_index) as vrt: assert vrt.driver == "VRT" assert vrt.dtypes[0] == "uint16" assert vrt.meta["dtype"] == "uint16" assert vrt.count == 1 assert vrt.nodata == 0 assert vrt.bounds == bounds vrt_data = vrt.read() assert vrt_data.any() # generate a VRT using GDAL and compare out_dir = os.path.join(mp_tmpdir, "cleantopo_br") temp_vrt = os.path.join(out_dir, str(zoom) + "_gdal.vrt") gdalbuildvrt = "gdalbuildvrt %s %s/%s/*/*.tif > /dev/null" % ( temp_vrt, out_dir, zoom, ) os.system(gdalbuildvrt) with rasterio.open(temp_vrt, "r") as gdal_vrt: assert gdal_vrt.dtypes[0] == "uint16" assert gdal_vrt.meta["dtype"] == "uint16" assert gdal_vrt.count == 1 assert gdal_vrt.nodata == 0 assert gdal_vrt.bounds == bounds gdal_vrt_data = gdal_vrt.read() assert np.array_equal(vrt_data, gdal_vrt_data) # make sure handling an existing VRT works with mapchete.open( dict(cleantopo_br.dict, zoom_levels=dict(min=0, max=zoom)) ) as mp: # generate output mp.batch_process(zoom=zoom) # generate index list( zoom_index_gen( mp=mp, zoom=zoom, out_dir=mp.config.output.path, vrt=True, ) ) def test_vrt_mercator(mp_tmpdir, cleantopo_br_mercator): zoom = 8 with mapchete.open( dict(cleantopo_br_mercator.dict, zoom_levels=dict(min=0, max=zoom)) ) as mp: # generate output mp.batch_process(zoom=zoom) # generate index list( zoom_index_gen( mp=mp, zoom=zoom, out_dir=mp.config.output.path, vrt=True, ) ) output_tiles = list( mp.config.output_pyramid.tiles_from_bounds( mp.config.bounds_at_zoom(zoom=zoom), zoom=zoom ) ) bounds = ( min([t.left for t in output_tiles]), min([t.bottom for t in output_tiles]), max([t.right for t in output_tiles]), max([t.top for t in output_tiles]), ) # bounds = mp.config.effective_bounds vrt_index = os.path.join(mp.config.output.path, "%s.vrt" % zoom) with rasterio.open(vrt_index) as vrt: assert vrt.driver == "VRT" assert vrt.dtypes[0] == "uint16" assert vrt.meta["dtype"] == "uint16" assert vrt.count == 1 assert vrt.nodata == 0 for vrt_b, b in zip(vrt.bounds, bounds): assert round(vrt_b, 6) == round(b, 6) vrt_data = vrt.read() assert vrt_data.any() # generate a VRT using GDAL and compare out_dir = os.path.join(mp_tmpdir, "cleantopo_br_mercator") temp_vrt = os.path.join(out_dir, str(zoom) + "_gdal.vrt") gdalbuildvrt = "gdalbuildvrt %s %s/%s/*/*.tif > /dev/null" % ( temp_vrt, out_dir, zoom, ) os.system(gdalbuildvrt) with rasterio.open(temp_vrt, "r") as gdal_vrt: assert gdal_vrt.dtypes[0] == "uint16" assert gdal_vrt.meta["dtype"] == "uint16" assert gdal_vrt.count == 1 assert gdal_vrt.nodata == 0 for vrt_b, b in zip(vrt.bounds, bounds): assert round(vrt_b, 6) == round(b, 6) gdal_vrt_data = gdal_vrt.read() assert np.array_equal(vrt_data, gdal_vrt_data) assert gdal_vrt_data.any() # make sure handling an existing VRT works with mapchete.open( dict(cleantopo_br_mercator.dict, zoom_levels=dict(min=0, max=zoom)) ) as mp: # generate output mp.batch_process(zoom=zoom) # generate index list( zoom_index_gen( mp=mp, zoom=zoom, out_dir=mp.config.output.path, vrt=True, ) )
30.178899
88
0.556316
855
6,579
4.112281
0.147368
0.039818
0.047782
0.051195
0.779295
0.76934
0.742036
0.742036
0.739192
0.718999
0
0.011159
0.332573
6,579
217
89
30.317972
0.78957
0.080103
0
0.680473
0
0
0.042123
0.003483
0
0
0
0
0.177515
1
0.023669
false
0
0.047337
0
0.071006
0
0
0
0
null
0
0
0
0
1
1
1
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
5
4a26895a31ec0e1182be3cd2b895cfbcb5d30aec
230
py
Python
cli/commands/cmd_stopall.py
Pythonian/catwatch
25730faa9d8ec6564b075de78bbbf4ff125ada97
[ "MIT" ]
null
null
null
cli/commands/cmd_stopall.py
Pythonian/catwatch
25730faa9d8ec6564b075de78bbbf4ff125ada97
[ "MIT" ]
null
null
null
cli/commands/cmd_stopall.py
Pythonian/catwatch
25730faa9d8ec6564b075de78bbbf4ff125ada97
[ "MIT" ]
2
2018-08-04T16:46:55.000Z
2019-07-02T19:30:24.000Z
import subprocess import click @click.command() def cli(): """ Stop all services. :return: Subprocess call result """ cmd = 'pkill honcho && docker-compose stop' return subprocess.call(cmd, shell=True)
15.333333
47
0.647826
27
230
5.518519
0.703704
0.214765
0.268456
0
0
0
0
0
0
0
0
0
0.234783
230
14
48
16.428571
0.846591
0.221739
0
0
0
0
0.220126
0
0
0
0
0
0
1
0.166667
false
0
0.333333
0
0.666667
0
1
0
0
null
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
0
0
1
0
1
0
0
5
c586406b080e269715b578337289a21558a3b44c
1,412
py
Python
spec/python/test_default_endian_expr_inherited.py
DarkShadow44/kaitai_struct_tests
4bb13cef82965cca66dda2eb2b77cd64e9f70a12
[ "MIT" ]
11
2018-04-01T03:58:15.000Z
2021-08-14T09:04:55.000Z
spec/python/test_default_endian_expr_inherited.py
DarkShadow44/kaitai_struct_tests
4bb13cef82965cca66dda2eb2b77cd64e9f70a12
[ "MIT" ]
73
2016-07-20T10:27:15.000Z
2020-12-17T18:56:46.000Z
spec/python/test_default_endian_expr_inherited.py
DarkShadow44/kaitai_struct_tests
4bb13cef82965cca66dda2eb2b77cd64e9f70a12
[ "MIT" ]
37
2016-08-15T08:25:56.000Z
2021-08-28T14:48:46.000Z
# Autogenerated from KST: please remove this line if doing any edits by hand! import unittest from default_endian_expr_inherited import DefaultEndianExprInherited class TestDefaultEndianExprInherited(unittest.TestCase): def test_default_endian_expr_inherited(self): with DefaultEndianExprInherited.from_file('src/endian_expr.bin') as r: self.assertEqual(r.docs[0].indicator, b"\x49\x49") self.assertEqual(r.docs[0].main.insides.some_int, 66) self.assertEqual(r.docs[0].main.insides.more.some_int1, 16896) self.assertEqual(r.docs[0].main.insides.more.some_int2, 66) self.assertEqual(r.docs[0].main.insides.more.some_inst, 66) self.assertEqual(r.docs[1].indicator, b"\x4D\x4D") self.assertEqual(r.docs[1].main.insides.some_int, 66) self.assertEqual(r.docs[1].main.insides.more.some_int1, 66) self.assertEqual(r.docs[1].main.insides.more.some_int2, 16896) self.assertEqual(r.docs[1].main.insides.more.some_inst, 1107296256) self.assertEqual(r.docs[2].indicator, b"\x58\x58") self.assertEqual(r.docs[2].main.insides.some_int, 66) self.assertEqual(r.docs[2].main.insides.more.some_int1, 66) self.assertEqual(r.docs[2].main.insides.more.some_int2, 16896) self.assertEqual(r.docs[2].main.insides.more.some_inst, 1107296256)
56.48
79
0.691218
199
1,412
4.798995
0.266332
0.235602
0.251309
0.314136
0.65445
0.59267
0.539267
0.473298
0.473298
0.332984
0
0.069025
0.179178
1,412
24
80
58.833333
0.754961
0.053116
0
0
1
0
0.03221
0
0
0
0
0
0.75
1
0.05
false
0
0.1
0
0.2
0
0
0
0
null
1
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
null
0
0
0
1
0
0
0
0
0
0
0
0
0
5
c587c9e03d1a49ad0241aaae4c1d441224ff0458
12
py
Python
toolateforcoffee.py
foxfluff/too-late-for-coffee
9a2b569f7de9f41ce402c7ac17ca01e750151c48
[ "MIT" ]
null
null
null
toolateforcoffee.py
foxfluff/too-late-for-coffee
9a2b569f7de9f41ce402c7ac17ca01e750151c48
[ "MIT" ]
null
null
null
toolateforcoffee.py
foxfluff/too-late-for-coffee
9a2b569f7de9f41ce402c7ac17ca01e750151c48
[ "MIT" ]
null
null
null
print "No."
6
11
0.583333
2
12
3.5
1
0
0
0
0
0
0
0
0
0
0
0
0.166667
12
1
12
12
0.7
0
0
0
0
0
0.25
0
0
0
0
0
0
0
null
null
0
0
null
null
1
1
1
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
1
0
0
0
0
0
0
1
0
5
c588f0c11b0eb3e147a44ea4bfac8275fa9242ae
128
py
Python
Documentation/GuidesFromPlosCompBioPaper/ExampleCaseC/AdditionalInputFiles/PRSCondition/LAD2coronaryRpController.py
carthurs/CRIMSONGUI
1464df9c4d04cf3ba131ca90b91988a06845c68e
[ "BSD-3-Clause" ]
10
2020-09-17T18:55:31.000Z
2022-02-23T02:52:38.000Z
Documentation/GuidesFromPlosCompBioPaper/ExampleCaseC/AdditionalInputFiles/PRSCondition/LAD2coronaryRpController.py
carthurs/CRIMSONGUI
1464df9c4d04cf3ba131ca90b91988a06845c68e
[ "BSD-3-Clause" ]
null
null
null
Documentation/GuidesFromPlosCompBioPaper/ExampleCaseC/AdditionalInputFiles/PRSCondition/LAD2coronaryRpController.py
carthurs/CRIMSONGUI
1464df9c4d04cf3ba131ca90b91988a06845c68e
[ "BSD-3-Clause" ]
3
2021-05-19T09:02:21.000Z
2021-07-26T17:39:57.000Z
version https://git-lfs.github.com/spec/v1 oid sha256:1eaa715583d925005051963b4060c72e79f474a068a74ee5a9831c55e6dff8ac size 713
32
75
0.882813
13
128
8.692308
1
0
0
0
0
0
0
0
0
0
0
0.418033
0.046875
128
3
76
42.666667
0.508197
0
0
0
0
0
0
0
0
1
0
0
0
0
null
null
0
0
null
null
0
1
0
0
null
0
0
0
0
0
0
0
0
0
0
1
0
0
1
0
0
0
0
0
0
0
0
0
0
null
1
0
0
0
1
0
0
0
0
0
0
0
0
5
c589abd4d4f08da93ca208a5e85f8faa2cf4d9a4
7,545
py
Python
site-packages/mlab/disco/discovery_test.py
m-lab/collectd-mlab
e7d5adb2492794712ae8af023f9c7cdcba392ac1
[ "Apache-2.0" ]
3
2017-01-11T09:11:57.000Z
2019-04-13T09:10:19.000Z
site-packages/mlab/disco/discovery_test.py
m-lab/collectd-mlab
e7d5adb2492794712ae8af023f9c7cdcba392ac1
[ "Apache-2.0" ]
63
2015-01-19T22:03:59.000Z
2019-11-06T18:19:07.000Z
site-packages/mlab/disco/discovery_test.py
m-lab/collectd-mlab
e7d5adb2492794712ae8af023f9c7cdcba392ac1
[ "Apache-2.0" ]
5
2015-10-26T17:57:50.000Z
2018-09-21T19:59:25.000Z
"""Tests for discovery.""" import unittest # Third-party modules. import mock from mlab.disco import simple_session from mlab.disco import models from mlab.disco import network # Module under test. import discovery _JUNIPER_QFX_SYS_DESCR = ('Juniper Networks, Inc. qfx5100-48s-6q Ethernet ' 'Switch, kernel JUNOS 13.2X51-D38') _CISCO_SYS_DESCR = ('Cisco IOS Software, C2960S Software ' '(C2960S-UNIVERSALK9-M), Version 12.2(55)SE7') class DiscoverySessionTest(unittest.TestCase): def setUp(self): self.fake_session = simple_session.FakeSession() self.model_qfx = models.Model(name='qfx', pattern='qfx', qbridge=True) self.model_cisco = models.Model(name='cisco', pattern='Cisco', vlan=True) self.switch_config = models.Config( models=(self.model_qfx, self.model_cisco), default_oids={}) self.session = discovery.DiscoverySession(self.fake_session, self.switch_config) def test_get_model(self): # Identify the switch. self.fake_session.prepare('sysDescr.0', 'sysDescr.0', _JUNIPER_QFX_SYS_DESCR) actual = self.session.get_model() self.assertEqual(self.model_qfx.name, actual.name) self.assertEqual(self.model_qfx.pattern, actual.pattern) self.assertEqual(self.model_qfx.qbridge, actual.qbridge) self.assertEqual(self.model_qfx.vlan, actual.vlan) @mock.patch.object(network, 'get_local_mac') @mock.patch.object(network, 'get_uplink_mac') def test_auto_discover_ifindex(self, mock_get_uplink_mac, mock_get_local_mac): mock_get_uplink_mac.return_value = '00:01:02:03:04:05' mock_get_local_mac.return_value = '00:01:02:03:04:06' # Identify the switch. self.fake_session.prepare('sysDescr.0', 'sysDescr.0', _JUNIPER_QFX_SYS_DESCR), # Setup uplink MAC. self.fake_session.prepare( discovery._OIDS['Q-BRIDGE-MIB::dot1qTpFdbPort'], discovery._mac_to_oid('00:01:02:03:04:05'), '10') self.fake_session.prepare( discovery._OIDS['BRIDGE-MIB::dot1dBasePortIfIndex'] + '.10', 'any_oid_prefix', '12') # Setup local MAC. self.fake_session.prepare( discovery._OIDS['Q-BRIDGE-MIB::dot1qTpFdbPort'], discovery._mac_to_oid('00:01:02:03:04:06'), '20') self.fake_session.prepare( discovery._OIDS['BRIDGE-MIB::dot1dBasePortIfIndex'] + '.20', 'any_oid_prefix', '22') found_ports = self.session.auto_discover_ifindex() self.assertItemsEqual([('uplink', '12'), ('local', '22')], found_ports) @mock.patch.object(network, 'get_local_mac') @mock.patch.object(network, 'get_uplink_mac') def test_auto_discover_ifindex_raises_PortLookupFailed( self, mock_get_uplink_mac, mock_get_local_mac): mock_get_uplink_mac.return_value = '00:01:02:03:04:05' mock_get_local_mac.return_value = '00:01:02:03:04:06' # Identify the switch. self.fake_session.prepare('sysDescr.0', 'sysDescr.0', _JUNIPER_QFX_SYS_DESCR) # Setup uplink MAC. self.fake_session.prepare( discovery._OIDS['Q-BRIDGE-MIB::dot1qTpFdbPort'], discovery._mac_to_oid('00:01:02:03:04:05'), '10') # Exclude the uplink BRIDGE-MIB::dot1dBasePortIfIndex so lookup fails. with self.assertRaises(discovery.PortLookupFailed): self.session.auto_discover_ifindex() @mock.patch.object(network, 'get_local_mac') @mock.patch.object(network, 'get_uplink_mac') def test_auto_discover_ifindex_invalid_value_raises_PortLookupFailed( self, mock_get_uplink_mac, mock_get_local_mac): mock_get_uplink_mac.return_value = '00:01:02:03:04:05' mock_get_local_mac.return_value = '00:01:02:03:04:06' # Identify the switch. self.fake_session.prepare('sysDescr.0', 'sysDescr.0', _JUNIPER_QFX_SYS_DESCR) # Setup uplink MAC self.fake_session.prepare( discovery._OIDS['Q-BRIDGE-MIB::dot1qTpFdbPort'], discovery._mac_to_oid('00:01:02:03:04:05'), '10') # Return an (invalid) empty ifIndex value. self.fake_session.prepare( discovery._OIDS['BRIDGE-MIB::dot1dBasePortIfIndex'] + '.10', 'any_oid_prefix', '') with self.assertRaises(discovery.PortLookupFailed): self.session.auto_discover_ifindex() @mock.patch.object(network, 'get_local_mac') @mock.patch.object(network, 'get_uplink_mac') def test_auto_discover_ifindex_without_qbridge(self, mock_get_uplink_mac, mock_get_local_mac): mock_get_uplink_mac.return_value = '00:01:02:03:04:05' mock_get_local_mac.return_value = '00:01:02:03:04:06' # Identify the switch. self.fake_session.prepare('sysDescr.0', 'sysDescr.0', _CISCO_SYS_DESCR) # Setup uplink MAC. self.fake_session.prepare(discovery._OIDS['BRIDGE-MIB::dot1dTpFdbPort'], discovery._mac_to_oid('00:01:02:03:04:05'), '10') self.fake_session.prepare( discovery._OIDS['BRIDGE-MIB::dot1dBasePortIfIndex'] + '.10', 'any_oid_prefix', '12') # Setup local MAC. self.fake_session.prepare(discovery._OIDS['BRIDGE-MIB::dot1dTpFdbPort'], discovery._mac_to_oid('00:01:02:03:04:06'), '20') self.fake_session.prepare( discovery._OIDS['BRIDGE-MIB::dot1dBasePortIfIndex'] + '.20', 'any_oid_prefix', '22') found_ports = self.session.auto_discover_ifindex() self.assertItemsEqual([('uplink', '12'), ('local', '22')], found_ports) def test_auto_discover_vlan(self): # Identify the switch. self.fake_session.prepare('sysDescr.0', 'sysDescr.0', _CISCO_SYS_DESCR) # Setup VLAN IDs to return. self.fake_session.prepare( discovery._OIDS['CISCO-VTP-MIB::vtpVlanIfIndex'], 'any-tag-does-not-matter', '10') found_vlans = self.session.auto_discover_vlan() self.assertItemsEqual(['10'], found_vlans) def test_auto_discover_vlan_returns_vlan_1(self): # Identify the switch. self.fake_session.prepare('sysDescr.0', 'sysDescr.0', _CISCO_SYS_DESCR) # Setup VLAN IDs with vlan 1 and another vlan. self.fake_session.prepare( discovery._OIDS['CISCO-VTP-MIB::vtpVlanIfIndex'], 'any-tag-does-not-matter', '1') self.fake_session.prepare( discovery._OIDS['CISCO-VTP-MIB::vtpVlanIfIndex'], 'any-tag-does-not-matter', '20') found_vlans = self.session.auto_discover_vlan() self.assertItemsEqual(['1', '20'], found_vlans) def test_auto_discover_vlan_returns_empty_list(self): # Identify the switch. self.fake_session.prepare('sysDescr.0', 'sysDescr.0', _JUNIPER_QFX_SYS_DESCR) found_vlans = self.session.auto_discover_vlan() self.assertItemsEqual([], found_vlans) if __name__ == '__main__': unittest.main()
42.150838
80
0.620013
901
7,545
4.90677
0.146504
0.043429
0.08143
0.109477
0.779462
0.74983
0.74983
0.74983
0.731735
0.693056
0
0.049274
0.260305
7,545
178
81
42.38764
0.742878
0.068257
0
0.603175
0
0
0.187438
0.071806
0
0
0
0
0.087302
1
0.071429
false
0
0.047619
0
0.126984
0
0
0
0
null
0
0
0
0
1
1
1
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
5
c5c2b9b7697b461f12c60b4f0f7cfd29381a105a
70
py
Python
login.py
flyrobot27/cgi-lab
c49a2a725cb938a83acde81f28c1359b05750ad0
[ "Apache-2.0" ]
null
null
null
login.py
flyrobot27/cgi-lab
c49a2a725cb938a83acde81f28c1359b05750ad0
[ "Apache-2.0" ]
null
null
null
login.py
flyrobot27/cgi-lab
c49a2a725cb938a83acde81f28c1359b05750ad0
[ "Apache-2.0" ]
null
null
null
#!/usr/bin/env python3 import templates print(templates.login_page())
17.5
29
0.785714
10
70
5.4
0.9
0
0
0
0
0
0
0
0
0
0
0.015385
0.071429
70
4
29
17.5
0.815385
0.3
0
0
0
0
0
0
0
0
0
0
0
1
0
true
0
0.5
0
0.5
0.5
1
0
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
1
0
1
0
0
1
0
5
680a95b140b22f02bea8cc892f0e4da6558a23fb
1,882
py
Python
tests/test_bond_types.py
pzarabadip/PopOff
4a9db1ff264ab96196014388721a832aea0f7325
[ "MIT" ]
4
2021-06-18T12:22:50.000Z
2021-12-27T16:00:31.000Z
tests/test_bond_types.py
pzarabadip/PopOff
4a9db1ff264ab96196014388721a832aea0f7325
[ "MIT" ]
1
2021-06-27T23:02:23.000Z
2021-08-02T10:07:46.000Z
tests/test_bond_types.py
pzarabadip/PopOff
4a9db1ff264ab96196014388721a832aea0f7325
[ "MIT" ]
2
2021-06-22T10:39:06.000Z
2021-12-27T17:52:16.000Z
#! /usr/bin/env python3 from popoff.bond_types import BondType import pytest @pytest.fixture def bond_type(): return BondType(1, 'Li-O', 65.0) def test_assert_bond_type(bond_type): assert bond_type.bond_type_index == 1 assert bond_type.label == 'Li-O' assert bond_type.spring_coeff_1 == 65.0 assert bond_type.spring_coeff_2 == 0.0 @pytest.mark.parametrize( 'bond_type_index', [('test'), (1.0), (True)]) def test_typeerror_for_bond_type_index_in_bond_type(bond_type_index, bond_type): with pytest.raises(TypeError): BondType(bond_type_index, bond_type.label, bond_type.spring_coeff_1, bond_type.spring_coeff_2) @pytest.mark.parametrize( 'label', [(1), (1.0), (True)]) def test_typeerror_for_label_in_bond_type(label, bond_type): with pytest.raises(TypeError): BondType(bond_type.bond_type_index, label, bond_type.spring_coeff_1, bond_type.spring_coeff_2) @pytest.mark.parametrize( 'spring_coeff_1', [(1), ('test'), (True)]) def test_typeerror_for_spring_coeff_1_in_bond_type(spring_coeff_1, bond_type): with pytest.raises(TypeError): BondType(bond_type.bond_type_index, bond_type.label, spring_coeff_1, bond_type.spring_coeff_2) @pytest.mark.parametrize( 'spring_coeff_2', [(1), ('test'), (True)]) def test_typeerror_for_spring_coeff_2_in_bond_type(spring_coeff_2, bond_type): with pytest.raises(TypeError): BondType(bond_type.bond_type_index, bond_type.label, bond_type.spring_coeff_1, spring_coeff_2) @pytest.mark.parametrize( 'label', [('LiO'), ('Li_O'), ('Li O'), ('something')]) def test_valueerror_for_label_in_bond_type(label, bond_type): with pytest.raises(ValueError): BondType(bond_type.bond_type_index, label, bond_type.spring_coeff_1, bond_type.spring_coeff_2) def test_bond_string_in_bond_type(bond_type): assert bond_type.bond_string() == 'bond_coeff 1 65.00 0.0'
43.767442
102
0.755579
299
1,882
4.341137
0.133779
0.271186
0.12943
0.175655
0.783513
0.710324
0.710324
0.609399
0.557011
0.465331
0
0.025872
0.116897
1,882
42
103
44.809524
0.755114
0.01169
0
0.1875
0
0
0.064013
0
0
0
0
0
0.1875
1
0.25
false
0
0.0625
0.03125
0.34375
0
0
0
0
null
1
0
1
0
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
1
0
0
0
0
0
0
0
5
a83ad5df9740a2b077836934a4f60c23570fbb8d
117
py
Python
Base/Python/vtkAddon.py
TheInterventionCentre/NorMIT-Plan-App
765ed9a5dccc1cc134b65ccabe93fc132baeb2ea
[ "MIT" ]
null
null
null
Base/Python/vtkAddon.py
TheInterventionCentre/NorMIT-Plan-App
765ed9a5dccc1cc134b65ccabe93fc132baeb2ea
[ "MIT" ]
null
null
null
Base/Python/vtkAddon.py
TheInterventionCentre/NorMIT-Plan-App
765ed9a5dccc1cc134b65ccabe93fc132baeb2ea
[ "MIT" ]
null
null
null
""" This module loads all the classes from the vtkAddon library into its namespace.""" from vtkAddonPython import *
23.4
72
0.769231
16
117
5.625
0.875
0
0
0
0
0
0
0
0
0
0
0
0.162393
117
4
73
29.25
0.918367
0.675214
0
0
0
0
0
0
0
0
0
0
0
1
0
true
0
1
0
1
0
1
0
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
1
0
1
0
1
0
0
5
a891d1e32b9f0d6eab9304ac695dbbfed49a5215
17,145
py
Python
laser_width/second_position/pyroot_analyse.py
beckstev/purdue_laser_box
aa4fbf2f3cf6a43fea0a8939d2b22005ffae9bc0
[ "MIT" ]
null
null
null
laser_width/second_position/pyroot_analyse.py
beckstev/purdue_laser_box
aa4fbf2f3cf6a43fea0a8939d2b22005ffae9bc0
[ "MIT" ]
null
null
null
laser_width/second_position/pyroot_analyse.py
beckstev/purdue_laser_box
aa4fbf2f3cf6a43fea0a8939d2b22005ffae9bc0
[ "MIT" ]
null
null
null
import ROOT as root import numpy as np import uncertainties.unumpy as unp from uncertainties import ufloat from uncertainties.unumpy import nominal_values as noms from uncertainties.unumpy import std_devs as stds from array import array import sys ############### Readout command line argument try: name_of_folder = sys.argv[1] try: plot_style = sys.argv[2] except IndexError: plot_style = None except IndexError: print('No Argument given Or other Index out of Range Er') sys.path.insert(0, './' + name_of_folder + '/') ########################## import pyData.py ###################################### from pyData import * ##################################################### Set Cnavas Style ############################# root.gStyle.SetOptTitle(0) root.gStyle.SetOptFit(1) root.gStyle.SetLabelSize(.05, "XY"); root.gStyle.SetTitleSize(.05, "XY"); root.gStyle.SetTitleOffset(1, "XY"); root.gStyle.SetStatFontSize(.08) ########################### Def Gaus function ###################### personal_gaus = root.TF1("personal_gaus", " [0] * exp( -0.5 * ( (x - [1]) / [2] ) * ( (x - [1]) / [2] ) ) ") name_params = [ "amplitude/[MeanVcal]", "mean/[Col]", "sigma/[Col]"] personal_gaus.SetParName(0,'Amplitude') personal_gaus.SetParName(2,'Sigma') if plot_style == 'thesis': personal_gaus.SetParName(1,'Mittelwert') else : personal_gaus.SetParName(1,'Mean') ############################### Save Data in list ####################################### mean_value_col_list = [] mean_error_col_list = [] x_value = [] x_error = [] ############################################################################################################################## ################################### Getting the mean hit value of all columns near the laserspot ############################# ############################################################################################################################### ################################## Set sum area, size of sensetive area ############################### xmin = 20 xmax = 26 ymin = 62 ymax = 72 #################################### calculating mean of each coloum ################################ for i in range(xmin,xmax): # going thru all col content = [] error = [] x_value.append(i) x_error.append(0.5) test_error = [] for j in range(ymin,ymax): # going thru all rows if qMap_Ag_C0_V0.GetBinContent(i,j) != 0: content.append( qMap_Ag_C0_V0.GetBinContent(i,j)) # Is this the real error N = qMap_Ag_C0_V0.GetBinEntries( qMap_Ag_C0_V0.GetBin(i,j)) if N == 1: new_error = np.sqrt( ( qMap_Ag_C0_V0.GetBinContent(i,j) - qMap_Ag_C0_V0.GetBinContent(i,j)/N) **2) else: new_error = np.sqrt( 1/(N-1) * ( qMap_Ag_C0_V0.GetBinContent(i,j) - qMap_Ag_C0_V0.GetBinContent(i,j)/N) **2) #error.append( 1/N * np.sqrt(qMap_Ag_C0_V0.GetBinContent(i,j) *N ) ) # Is this the real error error.append( new_error ) # Is this the real error else: pass content_bin = unp.uarray( content, error) mean_content_col = content_bin.sum() # mean value of each bin in the col # Saving values in lists mean_value_col_list.append( noms(mean_content_col)) mean_error_col_list.append( stds(mean_content_col) ) ########################### Create errorbar plot ##################################### errorbar_plot_col = root.TGraphErrors( len(x_value), array( 'f', x_value- np.ones(len(x_value))), array( 'f', mean_value_col_list), array( 'f', x_error), array( 'f', mean_error_col_list) ) x_value -= np.ones(len(x_value)) ############################## Set axis label and range of errobar plot ################################## if plot_style == 'thesis': errorbar_plot_col.GetXaxis().SetTitle("Spalte") errorbar_plot_col.GetYaxis().SetTitle("Summe Hits / Vcal") else: errorbar_plot_col.GetXaxis().SetTitle("Col") errorbar_plot_col.GetYaxis().SetTitle("Mean Hit / Vcal") errorbar_plot_col.SetMinimum(0) errorbar_plot_col.SetMaximum( max( mean_value_col_list) + 0.3 * max(mean_value_col_list) ) ####################### create Canvas and FIT ########################################## c1 = root.TCanvas("c1", "c1", 1980, 1080) c1.SetGrid() if name_of_folder == '7_mm': personal_gaus.SetParLimits(0, max(mean_value_col_list) * .2, max(mean_value_col_list) * 1.5 ) personal_gaus.SetParLimits(1, np.mean(x_value) * .7, np.mean(x_value) * 1.2 ) personal_gaus.SetParLimits(2, np.std(np.array(x_value)) * 0.03, np.std(np.array(x_value)) * 1.4 ) elif name_of_folder == '14_mm': personal_gaus.SetParLimits(0, max(mean_value_col_list) * .4, max(mean_value_col_list) * 1.5 ) personal_gaus.SetParLimits(1, np.mean(x_value) * .8, np.mean(x_value) * 1.1 ) personal_gaus.SetParLimits(2, np.std(np.array(x_value)) * 0.03, np.std(np.array(x_value))*1.1 ) else: personal_gaus.SetParLimits(0, max(mean_value_col_list) * .5, max(mean_value_col_list) * 1.8 ) personal_gaus.SetParLimits(1, np.mean(x_value) * .7, np.mean(x_value) * 1.2 ) personal_gaus.SetParLimits(2, np.std(np.array(x_value)) * 0.03, np.std(np.array(x_value)) * 1.2 ) errorbar_plot_col.Fit(personal_gaus, "", "", min(x_value) -0.5 , max( x_value) +0.5 ) #errorbar_plot_col.Fit("gaus", "", "", min(x_value) -0.5 , max( x_value) +0.5 ) errorbar_plot_col.Draw("ap*") ############################### Create legend #################################### if plot_style == 'thesis': legend = root.TLegend(0.15,0.71,0.37,0.93) legend.SetTextSize(0.055) legend.AddEntry(errorbar_plot_col,"Summe Hits","lep") legend.AddEntry( personal_gaus,"Fit","l") legend.Draw() else: legend = root.TLegend(0.65,0.47,0.98,0.7) legend.SetTextSize(0.04) legend.AddEntry(errorbar_plot_col,"Row sum hit value","lep") legend.AddEntry( personal_gaus,"Gaussian Fit","l") legend.Draw() ######## Transfer Sigma from Bin to mumeter ############################ sigma_mu_meter_col = ufloat(personal_gaus.GetParameter(2), personal_gaus.GetParError(2)) * 150 # 150 is pixel size in y direction ############################################################################# ############################### Save parameter and plot ########################################### with open( f'./fit_params/{name_of_folder}_fit_parameters_col_xaxis.txt', 'w') as file: for i in range(0,3): file.write( name_params[i] + ' ' + str( personal_gaus.GetParameter(i) ) + ' ' + str(personal_gaus.GetParError(i)) + '\n') with open( f'./fit_parameters_col_xaxis.txt', 'a') as file: file.write( name_of_folder + 'Amplitude/Sigma/Mean:' + ' ' + str( personal_gaus.GetParameter(0) ) + ' ' + str(personal_gaus.GetParError(0)) + ' ' + str( personal_gaus.GetParameter(1) ) + ' ' + str(personal_gaus.GetParError(1)) + ' ' + str( personal_gaus.GetParameter(2) ) + ' ' + str(personal_gaus.GetParError(2)) + '\n') with open( f'./sigma_col_xaxis.txt', 'a') as file: file.write( name_params[i] + '_' + name_of_folder + ' ' + str( personal_gaus.GetParameter(2) ) + ' ' + str(personal_gaus.GetParError(2)) + '\n') with open( f'./sigma_col_in_mumeter_xaxis.txt', 'a') as file: file.write( name_params[i] +'_' + name_of_folder + ' ' + str( noms(sigma_mu_meter_col) ) + ' ' + str( stds(sigma_mu_meter_col) ) + '\n') c1.SaveAs(f'./plots/{name_of_folder}_erorbar_plot_col.pdf') ############################################################################################################################## ################################### Getting the mean hit value of all rows near the laserspot ############################# ############################################################################################################################### ############################Reset lists########################################### mean_value_row_list = [] mean_error_row_list = [] x_value = [] x_error = [] row_with_hits = [] #################################### calculating mean of each row ##################################### for i in range(ymin,ymax): # going thru all rows content = [] error = [] x_value.append(i) x_error.append(0.5) for j in range(xmin,xmax): # going thru all col if qMap_Ag_C0_V0.GetBinContent(j,i) != 0: content.append( qMap_Ag_C0_V0.GetBinContent(j,i)) N = qMap_Ag_C0_V0.GetBinEntries( qMap_Ag_C0_V0.GetBin(j,i)) if N == 1: new_error = np.sqrt( ( qMap_Ag_C0_V0.GetBinContent(i,j) - qMap_Ag_C0_V0.GetBinContent(i,j)/N )**2) else: new_error = np.sqrt( 1/(N-1) * ( qMap_Ag_C0_V0.GetBinContent(i,j) - qMap_Ag_C0_V0.GetBinContent(i,j)/N) **2) #error.append( 1/N * np.sqrt(qMap_Ag_C0_V0.GetBinContent(j,i) * N ) ) error.append( new_error) else: pass content_bin = unp.uarray( content, error) mean_content_row = content_bin.sum() # mean value of each bin in the col # Saving values in lists mean_value_row_list.append( noms(mean_content_row)) mean_error_row_list.append( stds(mean_content_row)) ############################# Create new errorbar plot #################################### errorbar_plot_rows = root.TGraphErrors( len(x_value), array( 'f', x_value - np.ones(len(x_value))), array( 'f', mean_value_row_list), array( 'f', x_error), array( 'f', mean_error_row_list) ) x_value -= np.ones(len(x_value)) errorbar_plot_rows.GetXaxis().SetNdivisions(20) ############################### create Canvas ######################################## c2 = root.TCanvas("c2", "c2", 1980, 1080); c2.SetGrid() ############################## Set axis label of errobar plot ################################## if plot_style == 'thesis': errorbar_plot_rows.GetXaxis().SetTitle("Zeile") errorbar_plot_rows.GetYaxis().SetTitle("Summe Hits / Vcal") else: errorbar_plot_rows.GetXaxis().SetTitle("Row") errorbar_plot_rows.GetYaxis().SetTitle("Mean Hit / Vcal") errorbar_plot_rows.SetMinimum(0) if name_of_folder == '10-5_mm': errorbar_plot_rows.SetMaximum( max(mean_value_row_list) + 0.15 * max(mean_value_row_list) ) elif name_of_folder == '11_mm': errorbar_plot_rows.SetMaximum( max(mean_value_row_list) + 0.9 * max(mean_value_row_list) ) elif name_of_folder == '9_mm': errorbar_plot_rows.SetMaximum( max(mean_value_row_list) + 0.4 * max(mean_value_row_list) ) else: errorbar_plot_rows.SetMaximum( max(mean_value_row_list) + 0.3 * max(mean_value_row_list) ) ############################### Plot fucntion and fit ############################################# if name_of_folder == '10-5_mm': print(np.std(np.array(x_value))) personal_gaus.SetParLimits(0, max(mean_value_row_list) * .5, max(mean_value_row_list) * 1.5 ) personal_gaus.SetParLimits(1, np.mean(x_value) * .9, np.mean(x_value) * 1.12) personal_gaus.SetParLimits(2, np.std(np.array(x_value)) * .1, np.std(np.array(x_value))*0.6 ) elif name_of_folder == '11_mm': #personal_gaus.SetParameter(1, 66 ) personal_gaus.SetParLimits(0, max(mean_value_row_list) * .5, max(mean_value_row_list) * 1.8) personal_gaus.SetParLimits(1, np.mean(x_value) * .9, np.mean(x_value) * 1.12 ) personal_gaus.SetParLimits(2, np.std(np.array(x_value)) * .05, np.std(np.array(x_value))*0.8 ) elif name_of_folder == '7_mm': personal_gaus.SetParLimits(0, max(mean_value_row_list) * .2, max(mean_value_row_list)*1.2 ) personal_gaus.SetParLimits(1, np.mean(x_value) * .7, np.mean(x_value) * 1.3) personal_gaus.SetParLimits(2, np.std(np.array(x_value)) * .1, np.std(np.array(x_value)) * 1.05 ) elif name_of_folder == '6_mm': personal_gaus.SetParLimits(0, max(mean_value_row_list) * .2, max(mean_value_row_list) * 1.31 ) personal_gaus.SetParLimits(1, np.mean(x_value) -3, np.mean(x_value)+3 ) personal_gaus.SetParLimits(2, np.std(np.array(x_value)) * .1, np.std(np.array(x_value)) *1.05 ) elif name_of_folder == '9-5_mm': personal_gaus.SetParLimits(0, max(mean_value_row_list) * .4, max(mean_value_row_list) * 1.3 ) personal_gaus.SetParLimits(1, np.mean(x_value) -1/2, np.mean(x_value)+1 ) personal_gaus.SetParLimits(2, np.std(np.array(x_value)) * .2, np.std(np.array(x_value)) ) elif name_of_folder == '9_mm': personal_gaus.SetParLimits(0, max(mean_value_row_list) * .4, max(mean_value_row_list) * 1.3 ) personal_gaus.SetParLimits(1, np.mean(x_value) -1/2, np.mean(x_value)+1 ) personal_gaus.SetParLimits(2, np.std(np.array(x_value)) * .1, np.std(np.array(x_value)) ) elif name_of_folder == '12_mm': personal_gaus.SetParLimits(0, max(mean_value_row_list) * .4, max(mean_value_row_list) * 1.3 ) personal_gaus.SetParLimits(1, np.mean(x_value) -1/2, np.mean(x_value)+1 ) personal_gaus.SetParLimits(2, np.std(np.array(x_value)) * .1, np.std(np.array(x_value)) ) elif name_of_folder == '13_mm': personal_gaus.SetParLimits(0, max(mean_value_row_list) * .4, max(mean_value_row_list) * 1.3 ) personal_gaus.SetParLimits(1, np.mean(x_value) -1/2, np.mean(x_value)+1 ) personal_gaus.SetParLimits(2, np.std(np.array(x_value)) * .1, np.std(np.array(x_value)) ) elif name_of_folder == '14_mm': personal_gaus.SetParLimits(0, max(mean_value_row_list) * .4, max(mean_value_row_list) * 1.3 ) personal_gaus.SetParLimits(1, np.mean(x_value) -1/2, np.mean(x_value)+1 ) personal_gaus.SetParLimits(2, np.std(np.array(x_value)) * .1, np.std(np.array(x_value)) ) elif name_of_folder == '5_mm': personal_gaus.SetParLimits(0, max(mean_value_row_list) * .4, max(mean_value_row_list) * 1.3 ) personal_gaus.SetParLimits(1, np.mean(x_value) -1/2, np.mean(x_value)+1 ) personal_gaus.SetParLimits(2, np.std(np.array(x_value)) * .1, np.std(np.array(x_value)) ) # # elif name_of_folder == '10_mm': personal_gaus.SetParameter(0, max(mean_value_row_list) ) personal_gaus.SetParLimits(0, max(mean_value_row_list) * .4, max(mean_value_row_list) * 1.8) personal_gaus.SetParLimits(1, np.mean(x_value) * .7, np.mean(x_value) * 1.3 ) personal_gaus.SetParLimits(2, np.std(np.array(x_value)) * .1, np.std(np.array(x_value))*1.4 ) # #elif name_of_folder == '15_mm': # #personal_gaus.SetParameter(0, 743 ) # #personal_gaus.SetParameter(1, 66 ) # #personal_gaus.SetParameter(2, 3.05) # # personal_gaus.SetParLimits(0,max(mean_value_row_list) * .4, max(mean_value_row_list) * 1.2 ) # personal_gaus.SetParLimits(1, np.mean(x_value) * .3, np.mean(x_value) * 1.4 ) # personal_gaus.SetParLimits(2,np.std(np.array(x_value)) * .2, np.std(np.array(x_value)) * 1.6 ) # # # else: personal_gaus.SetParLimits(0, max(mean_value_row_list) * .4, max(mean_value_row_list) * 1.5 ) personal_gaus.SetParLimits(1, np.mean(x_value) * .8, np.mean(x_value) * 1.2 ) personal_gaus.SetParLimits(2, np.std(np.array(x_value)) * .2, np.std(np.array(x_value)) * 1.1 ) errorbar_plot_rows.Fit( personal_gaus, "", "", min(x_value) -0.5 , max( x_value) +0.5 ) errorbar_plot_rows.Draw("ap*") ##################################### create legend ################################################ if plot_style == 'thesis': legend = root.TLegend(0.15,0.71,0.37,0.93) legend.SetTextSize(0.055) legend.AddEntry(errorbar_plot_rows,"Summe Hits","lep") legend.AddEntry( personal_gaus,"Fit","l") legend.Draw() else: legend = root.TLegend(0.65,0.47,0.98,0.7) legend.SetTextSize(0.04) legend.AddEntry(errorbar_plot_col,"Row sum hit value","lep") legend.AddEntry( personal_gaus,"Gaussian Fit","l") legend.Draw() ######## Transfer Sigma from Bin to mumeter ############################ sigma_mu_meter_row = ufloat(personal_gaus.GetParameter(2), personal_gaus.GetParError(2)) * 100 # 100 is pixel size in y direction ############################################################################# ########################################### saveplot and fit params ######################################## with open( f'./fit_params/{name_of_folder}_fit_parameters_row_yaxis.txt', 'w') as file: for i in range(0,3): file.write( name_params[i] + ' ' + str( personal_gaus.GetParameter(i) ) + ' ' + str(personal_gaus.GetParError(i)) + '\n') with open( f'./sigma_row_yaxis.txt', 'a') as file: file.write( name_params[i] +'_' + name_of_folder + ' ' + str( personal_gaus.GetParameter(2) ) + ' ' + str(personal_gaus.GetParError(2)) + '\n') with open( f'./sigma_row_in_mumeter_yaxis.txt', 'a') as file: file.write( name_params[i] +'_' + name_of_folder + ' ' + str( noms(sigma_mu_meter_row) ) + ' ' + str( stds(sigma_mu_meter_row) ) + '\n') with open( f'./fit_parameters_row_yaxis.txt', 'a') as file: file.write( name_of_folder + 'Amplitude/Sigma/Mean:' + ' ' + str( personal_gaus.GetParameter(0) ) + ' ' + str(personal_gaus.GetParError(0)) + ' ' + str( personal_gaus.GetParameter(1) ) + ' ' + str(personal_gaus.GetParError(1)) + ' ' + str( personal_gaus.GetParameter(2) ) + ' ' + str(personal_gaus.GetParError(2)) + '\n') c2.SaveAs(f'./plots/{name_of_folder}_erorbar_plot_row.pdf')
42.649254
329
0.596792
2,435
17,145
3.94538
0.096099
0.111169
0.119913
0.063287
0.827001
0.778183
0.74987
0.718018
0.674092
0.633392
0
0.031973
0.140799
17,145
401
330
42.755611
0.620189
0.097579
0
0.46087
0
0.004348
0.07439
0.031267
0
0
0
0
0
1
0
false
0.008696
0.03913
0
0.03913
0.008696
0
0
0
null
0
0
0
1
1
1
1
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
5
a8bbf4ad040a6b253bd400f0a039ffbac93b4026
63
py
Python
RecoBTag/PerformanceDB/python/BTagPerformanceDB1012.py
ckamtsikis/cmssw
ea19fe642bb7537cbf58451dcf73aa5fd1b66250
[ "Apache-2.0" ]
852
2015-01-11T21:03:51.000Z
2022-03-25T21:14:00.000Z
RecoBTag/PerformanceDB/python/BTagPerformanceDB1012.py
ckamtsikis/cmssw
ea19fe642bb7537cbf58451dcf73aa5fd1b66250
[ "Apache-2.0" ]
30,371
2015-01-02T00:14:40.000Z
2022-03-31T23:26:05.000Z
RecoBTag/PerformanceDB/python/BTagPerformanceDB1012.py
ckamtsikis/cmssw
ea19fe642bb7537cbf58451dcf73aa5fd1b66250
[ "Apache-2.0" ]
3,240
2015-01-02T05:53:18.000Z
2022-03-31T17:24:21.000Z
from RecoBTag.PerformanceDB.measure.Btag_mistag101220 import *
31.5
62
0.873016
7
63
7.714286
1
0
0
0
0
0
0
0
0
0
0
0.101695
0.063492
63
1
63
63
0.813559
0
0
0
0
0
0
0
0
0
0
0
0
1
0
true
0
1
0
1
0
1
0
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
1
0
1
0
1
0
0
5
763ce4e8afeab2e7b4b86f6781fbc51141c961c6
122
py
Python
kubemon/collector/__init__.py
hrchlhck/kubemon
d4d73eaa61bef70efce857a416963aeffafa15b5
[ "MIT" ]
4
2021-07-20T07:49:53.000Z
2022-01-17T01:41:45.000Z
kubemon/collector/__init__.py
hrchlhck/kubemon
d4d73eaa61bef70efce857a416963aeffafa15b5
[ "MIT" ]
6
2021-07-03T02:16:09.000Z
2022-01-18T17:35:26.000Z
kubemon/collector/__init__.py
hrchlhck/sys-monitor
29b4c93e3b9333d418748646c76ce47ee3ca7d97
[ "MIT" ]
null
null
null
from .collector import Collector from .collector_client import CollectorClient __all__ = ['Collector', 'CollectorClient']
30.5
45
0.819672
12
122
7.916667
0.5
0.273684
0
0
0
0
0
0
0
0
0
0
0.098361
122
4
46
30.5
0.863636
0
0
0
0
0
0.195122
0
0
0
0
0
0
1
0
false
0
0.666667
0
0.666667
0
1
0
0
null
1
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
0
0
1
0
1
0
0
5
7694bcc9a490bbf2e35274558a8089aa5afb6300
284
py
Python
rec_to_nwb/processing/nwb/components/associated_files/fl_associated_files_builder.py
jihyunbak/rec_to_nwb
6e65f8bf0a4faa4d986483ec2442ba19d70c92a9
[ "Apache-2.0" ]
8
2020-05-29T13:48:35.000Z
2021-11-19T04:24:48.000Z
rec_to_nwb/processing/nwb/components/associated_files/fl_associated_files_builder.py
jihyunbak/rec_to_nwb
6e65f8bf0a4faa4d986483ec2442ba19d70c92a9
[ "Apache-2.0" ]
8
2020-07-13T00:42:35.000Z
2020-11-16T16:17:12.000Z
rec_to_nwb/processing/nwb/components/associated_files/fl_associated_files_builder.py
jihyunbak/rec_to_nwb
6e65f8bf0a4faa4d986483ec2442ba19d70c92a9
[ "Apache-2.0" ]
1
2020-08-28T01:34:35.000Z
2020-08-28T01:34:35.000Z
from rec_to_nwb.processing.nwb.components.associated_files.fl_associated_file import FlAssociatedFile class FlAssociatedFilesBuilder: @staticmethod def build(name, description, content, task_epochs): return FlAssociatedFile(name, description, content, task_epochs)
31.555556
101
0.809859
31
284
7.193548
0.741935
0.134529
0.197309
0.233184
0.286996
0
0
0
0
0
0
0
0.126761
284
8
102
35.5
0.899194
0
0
0
0
0
0
0
0
0
0
0
0
1
0.2
false
0
0.2
0.2
0.8
0
0
0
0
null
0
1
1
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
0
0
0
1
1
0
0
5
76ce59039fe5fa4002693eccff3aff6fdbad1164
90
py
Python
snaketrace/tests/scripts/test-trace.py
dcoles/pytrace
fff95334429943a34d37dc29f260627adbc061fa
[ "MIT" ]
5
2021-01-06T11:57:28.000Z
2021-05-25T16:24:05.000Z
snaketrace/tests/scripts/test-trace.py
dcoles/pytrace
fff95334429943a34d37dc29f260627adbc061fa
[ "MIT" ]
2
2020-01-24T21:54:01.000Z
2020-04-05T06:30:56.000Z
snaketrace/tests/scripts/test-trace.py
dcoles/pytrace
fff95334429943a34d37dc29f260627adbc061fa
[ "MIT" ]
1
2021-02-12T04:08:56.000Z
2021-02-12T04:08:56.000Z
import os # Should generate `open('/dev/null', 'r+', ...) open(os.devnull, 'r+').close()
18
47
0.588889
13
90
4.076923
0.769231
0
0
0
0
0
0
0
0
0
0
0
0.122222
90
4
48
22.5
0.670886
0.5
0
0
1
0
0.046512
0
0
0
0
0
0
1
0
true
0
0.5
0
0.5
0
1
0
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
1
0
0
0
null
0
0
0
0
0
0
1
0
1
0
0
0
0
5
4f36a2dea6caf63f5d1dae211b81e3d85e760ef4
146
py
Python
src/MathResultModel.py
quadzz/fastapi-ci-example
011b41284e853ae676034f5596a9d9716bbf929a
[ "MIT" ]
null
null
null
src/MathResultModel.py
quadzz/fastapi-ci-example
011b41284e853ae676034f5596a9d9716bbf929a
[ "MIT" ]
null
null
null
src/MathResultModel.py
quadzz/fastapi-ci-example
011b41284e853ae676034f5596a9d9716bbf929a
[ "MIT" ]
null
null
null
from pydantic import BaseModel from typing import Optional class MathResultModel(BaseModel): result: Optional[float] = None summary: str
20.857143
34
0.773973
17
146
6.647059
0.764706
0
0
0
0
0
0
0
0
0
0
0
0.171233
146
6
35
24.333333
0.933884
0
0
0
0
0
0
0
0
0
0
0
0
1
0
true
0
0.4
0
1
0
1
0
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
1
0
1
0
1
0
0
5
4f3d70f9945bd647fbde89a457aefc7855d2903d
136
py
Python
highcliff/exampleactions/__init__.py
sermelo/Highcliff-SDK
255dd12b3402361cba8b1ea7a28c506f32a11dae
[ "Apache-2.0" ]
null
null
null
highcliff/exampleactions/__init__.py
sermelo/Highcliff-SDK
255dd12b3402361cba8b1ea7a28c506f32a11dae
[ "Apache-2.0" ]
null
null
null
highcliff/exampleactions/__init__.py
sermelo/Highcliff-SDK
255dd12b3402361cba8b1ea7a28c506f32a11dae
[ "Apache-2.0" ]
null
null
null
from highcliff.exampleactions.exampleactions import MonitorBodyTemperature, ChangeRoomTemperature, \ AuthorizeRoomTemperatureChange
45.333333
100
0.882353
8
136
15
0.875
0
0
0
0
0
0
0
0
0
0
0
0.080882
136
2
101
68
0.96
0
0
0
0
0
0
0
0
0
0
0
0
1
0
true
0
0.5
0
0.5
0
1
0
1
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
1
0
1
0
0
0
0
5
4f7f6e587cb3fa4a32e24f17f2bd50c264b0aea3
88
py
Python
story/admin.py
Arhacai/Storyteller
b3032a3e81c6ffcab315ab803731cf1bcdcdd2dd
[ "BSD-2-Clause" ]
6
2017-01-31T09:17:46.000Z
2020-05-28T09:27:21.000Z
story/admin.py
Arhacai/Storyteller
b3032a3e81c6ffcab315ab803731cf1bcdcdd2dd
[ "BSD-2-Clause" ]
64
2017-01-21T14:04:16.000Z
2019-06-17T12:29:07.000Z
src/story/admin.py
mshrinetra/little-django-app
c4496529643b0bc9157720374bab68db9b96ca3e
[ "MIT" ]
5
2017-01-21T14:18:31.000Z
2018-06-28T16:41:16.000Z
from django.contrib import admin from .models import Story admin.site.register(Story)
14.666667
32
0.806818
13
88
5.461538
0.692308
0
0
0
0
0
0
0
0
0
0
0
0.125
88
5
33
17.6
0.922078
0
0
0
0
0
0
0
0
0
0
0
0
1
0
true
0
0.666667
0
0.666667
0
1
0
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
1
0
1
0
1
0
0
5
4f8e4347c1b604af6054bafe0413c300628b2a6d
172
py
Python
venv/lib/python3.7/site-packages/allauth/socialaccount/providers/angellist/urls.py
vikram0207/django-rest
eafec575999dce6859dc7b99177cff339b2bcbdd
[ "MIT" ]
6,342
2015-01-01T07:40:30.000Z
2022-03-31T04:18:30.000Z
venv/lib/python3.7/site-packages/allauth/socialaccount/providers/angellist/urls.py
vikram0207/django-rest
eafec575999dce6859dc7b99177cff339b2bcbdd
[ "MIT" ]
2,198
2015-01-02T15:17:45.000Z
2022-03-28T10:20:43.000Z
venv/lib/python3.7/site-packages/allauth/socialaccount/providers/angellist/urls.py
vikram0207/django-rest
eafec575999dce6859dc7b99177cff339b2bcbdd
[ "MIT" ]
2,928
2015-01-01T10:44:13.000Z
2022-03-31T03:20:16.000Z
from allauth.socialaccount.providers.oauth2.urls import default_urlpatterns from .provider import AngelListProvider urlpatterns = default_urlpatterns(AngelListProvider)
24.571429
75
0.872093
17
172
8.705882
0.647059
0.243243
0
0
0
0
0
0
0
0
0
0.006329
0.081395
172
6
76
28.666667
0.93038
0
0
0
0
0
0
0
0
0
0
0
0
1
0
false
0
0.666667
0
0.666667
0
1
0
0
null
1
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
0
0
1
0
1
0
0
5
96e8f06cefa469a2f7a27443a0c2ce02683676ef
142
py
Python
utils/time.py
LeLuxNet/GridPy
5f4d02d2b254be1f0682b724a96a99009a415308
[ "MIT" ]
null
null
null
utils/time.py
LeLuxNet/GridPy
5f4d02d2b254be1f0682b724a96a99009a415308
[ "MIT" ]
1
2020-05-09T15:48:41.000Z
2020-05-21T20:14:21.000Z
utils/time.py
LeLuxNet/GridPy
5f4d02d2b254be1f0682b724a96a99009a415308
[ "MIT" ]
null
null
null
from time import sleep def to_ms(time): return time.seconds * 1000 + time.microseconds // 1000 def sleep_ms(ms): sleep(ms / 1000)
14.2
58
0.676056
22
142
4.272727
0.5
0.148936
0
0
0
0
0
0
0
0
0
0.108108
0.21831
142
9
59
15.777778
0.738739
0
0
0
0
0
0
0
0
0
0
0
0
1
0.4
false
0
0.2
0.2
0.8
0
1
0
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
1
0
0
0
1
1
0
0
5
96e9f8daf41e59bcd21653e4968d835342208068
181
py
Python
study/w3resource/exercises/python-basic/001 - 030/python-basic - 004.py
gustavomarquezinho/python
e36779aa5c4bfaf88c587f05db5bd447fd41e4a2
[ "MIT" ]
null
null
null
study/w3resource/exercises/python-basic/001 - 030/python-basic - 004.py
gustavomarquezinho/python
e36779aa5c4bfaf88c587f05db5bd447fd41e4a2
[ "MIT" ]
null
null
null
study/w3resource/exercises/python-basic/001 - 030/python-basic - 004.py
gustavomarquezinho/python
e36779aa5c4bfaf88c587f05db5bd447fd41e4a2
[ "MIT" ]
null
null
null
# 004 - Write a Python program which accepts the radius of a circle from the user and compute the area. print(f'Circle area: {(float(input("Circle radius: ")) ** 2) * 3.1416:.8f}')
60.333333
103
0.696133
31
181
4.064516
0.774194
0
0
0
0
0
0
0
0
0
0
0.066225
0.165746
181
3
104
60.333333
0.768212
0.558011
0
0
0
1
0.835443
0.265823
0
0
0
0
0
1
0
true
0
0
0
0
1
0
0
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
1
1
0
null
0
0
0
0
0
0
1
0
0
0
0
1
0
5
96feef73dc42b1f41c06f8bfa96b63bcd7a80d97
2,819
py
Python
src/tt_web/tt_web/tests/test_unique_priority_queue.py
al-arz/the-tale
542770257eb6ebd56a5ac44ea1ef93ff4ab19eb5
[ "BSD-3-Clause" ]
85
2017-11-21T12:22:02.000Z
2022-03-27T23:07:17.000Z
src/tt_web/tt_web/tests/test_unique_priority_queue.py
al-arz/the-tale
542770257eb6ebd56a5ac44ea1ef93ff4ab19eb5
[ "BSD-3-Clause" ]
545
2017-11-04T14:15:04.000Z
2022-03-27T14:19:27.000Z
src/tt_web/tt_web/tests/test_unique_priority_queue.py
al-arz/the-tale
542770257eb6ebd56a5ac44ea1ef93ff4ab19eb5
[ "BSD-3-Clause" ]
45
2017-11-11T12:36:30.000Z
2022-02-25T06:10:44.000Z
import unittest from ..common import unique_priority_queue class QueueTests(unittest.TestCase): def setUp(self): self.queue = unique_priority_queue.Queue() def test_initialize(self): self.assertEqual(self.queue._heap, []) self.assertEqual(self.queue._set, {}) def test_empty__empty(self): self.assertTrue(self.queue.empty()) def test_empty__not_empty(self): self.queue.push(1, 1) self.assertFalse(self.queue.empty()) def test_push(self): self.queue.push(10, 3) self.queue.push(20, 1) self.queue.push(30, 2) self.assertEqual(self.queue._set, {10: 3, 20: 1, 30: 2}) self.assertEqual([(20, 1), (30, 2), (10, 3)], [item for item in self.queue.items()]) def test_duplicate(self): self.queue.push(10, 3) self.queue.push(20, 1) self.queue.push(10, 2) self.assertEqual(self.queue._set, {10: 2, 20: 1}) self.assertEqual([(20, 1), (10, 2)], [item for item in self.queue.items()]) def test_pop(self): self.queue.push(10, 3) self.queue.push(20, 1) self.queue.push(30, 2) self.assertEqual(self.queue.pop(), (20, 1)) self.assertEqual(self.queue.pop(), (30, 2)) self.assertEqual(self.queue.pop(), (10, 3)) self.assertTrue(self.queue.empty()) def test_pop__empty(self): self.assertEqual(self.queue.pop(), (None, None)) def test_pop__duplicate(self): self.queue.push(10, 3) self.queue.push(20, 1) self.queue.push(10, 2) self.assertEqual(self.queue.pop(), (20, 1)) self.assertEqual(self.queue.pop(), (10, 2)) self.assertTrue(self.queue.empty()) def test_first(self): self.queue.push(10, 3) self.queue.push(20, 1) self.queue.push(30, 2) self.assertEqual(self.queue.first(), (20, 1)) def test_first__empty(self): self.assertEqual(self.queue.first(), (None, None)) def test_first__duplicate(self): self.queue.push(10, 3) self.queue.push(20, 3) self.queue.push(5, 1) self.queue.push(10, 2) self.assertEqual(self.queue.first(), (5, 1)) def test_clean(self): self.queue.push(10, 3) self.queue.push(20, 1) self.queue.push(30, 2) self.queue.clean() self.assertEqual(self.queue._heap, []) self.assertEqual(self.queue._set, {}) self.assertTrue(self.queue.empty()) def test_items__empty(self): self.assertEqual([], [item for item in self.queue.items()]) def test_items__has_items(self): self.queue.push(10, 3) self.queue.push(20, 1) self.queue.push(30, 2) self.assertEqual([(20, 1), (30, 2), (10, 3)], [item for item in self.queue.items()])
27.637255
92
0.593118
400
2,819
4.075
0.1
0.287117
0.207362
0.220859
0.760736
0.740491
0.691411
0.580982
0.580982
0.534969
0
0.06341
0.244768
2,819
101
93
27.910891
0.702208
0
0
0.5
0
0
0
0
0
0
0
0
0.342857
1
0.214286
false
0
0.028571
0
0.257143
0
0
0
0
null
1
1
1
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
1
0
0
0
0
0
0
0
5
4fbf237a8771dbb7158b14a286d7d16e7b0011fb
1,596
py
Python
tests/unit/baskerville_tests/models_tests/test_pipelines.py
equalitie/baskerville
433551d03aee85d5c983ff6b25b388155b54190d
[ "CC-BY-4.0" ]
25
2020-05-19T11:20:47.000Z
2021-09-20T03:15:28.000Z
tests/unit/baskerville_tests/models_tests/test_pipelines.py
mkaranasou/baskerville
433551d03aee85d5c983ff6b25b388155b54190d
[ "CC-BY-4.0" ]
29
2020-05-26T13:21:48.000Z
2021-09-21T06:52:28.000Z
tests/unit/baskerville_tests/models_tests/test_pipelines.py
deflect-ca/baskerville
9659f4b39ab66fcf5329a4eccff15e97245b04f0
[ "CC-BY-4.0" ]
4
2020-06-11T07:00:16.000Z
2021-05-07T09:10:36.000Z
# Copyright (c) 2020, eQualit.ie inc. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. import unittest # from unittest import mock # # from tests.unit.baskerville_tests.helpers.spark_testing_base import \ # SQLTestCaseLatestSpark # from baskerville import src_dir class TestElasticsearchPipelinee(unittest.TestCase): def setUp(self): pass # def test_instance(self): # raise NotImplementedError() # # def test_create_runtime(self): # raise NotImplementedError() # # def test_get_data(self): # raise NotImplementedError() # # def test_save_logs(self): # raise NotImplementedError() # # def test_run(self): # raise NotImplementedError() class TestManualRawLogPipeline(unittest.TestCase): def setUp(self): pass # def test_instance(self): # raise NotImplementedError() # # def test_create_runtime(self): # raise NotImplementedError() # # def test_get_data(self): # raise NotImplementedError() # # def test_run(self): # raise NotImplementedError() class TestKafkaPipeline(unittest.TestCase): def setUp(self): pass # def test_instance(self): # raise NotImplementedError() # # def test_create_runtime(self): # raise NotImplementedError() # # def test_get_data(self): # raise NotImplementedError() # # def test_run(self): # raise NotImplementedError()
23.470588
71
0.655388
163
1,596
6.269939
0.368098
0.089041
0.356164
0.303327
0.639922
0.639922
0.639922
0.639922
0.639922
0.639922
0
0.003359
0.253759
1,596
67
72
23.820896
0.854744
0.677945
0
0.6
0
0
0
0
0
0
0
0
0
1
0.3
false
0.3
0.1
0
0.7
0
0
0
0
null
0
1
1
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
1
0
1
0
0
0
0
0
5
4ff5ac04b9836fbc95e87a6f1079e5e708a5363c
184
py
Python
test_HA1.py
danielhuppmann/homework_no1
e8d58aef443114bae9f83e2d2570a8d475219d7d
[ "Apache-2.0" ]
null
null
null
test_HA1.py
danielhuppmann/homework_no1
e8d58aef443114bae9f83e2d2570a8d475219d7d
[ "Apache-2.0" ]
null
null
null
test_HA1.py
danielhuppmann/homework_no1
e8d58aef443114bae9f83e2d2570a8d475219d7d
[ "Apache-2.0" ]
1
2020-05-22T13:02:06.000Z
2020-05-22T13:02:06.000Z
from HA1 import yamamura from HA1 import roses def test_yamamura(): assert yamamura(theta = 0.11, Y_0 = 0, f = 1.9, b = 0.19) == 0 def test_roses(): assert roses(0, 90) == 1
23
63
0.63587
34
184
3.352941
0.529412
0.122807
0.22807
0
0
0
0
0
0
0
0
0.119718
0.228261
184
8
64
23
0.683099
0
0
0
0
0
0
0
0
0
0
0
0.333333
1
0.333333
true
0
0.333333
0
0.666667
0
0
0
0
null
0
1
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
1
1
0
1
0
0
0
0
5
4ff67d3163b57172afecd271f6bb4b1ec55901bb
41
py
Python
yaas/service.py
dmtucker/yaas
5487312459326cd5b4218122ebe26e20ead80ece
[ "MIT" ]
null
null
null
yaas/service.py
dmtucker/yaas
5487312459326cd5b4218122ebe26e20ead80ece
[ "MIT" ]
28
2015-09-10T07:56:15.000Z
2016-04-25T16:01:03.000Z
yaas/service.py
tucked/yaas
5487312459326cd5b4218122ebe26e20ead80ece
[ "MIT" ]
4
2015-09-09T22:03:35.000Z
2017-02-14T23:59:27.000Z
# coding: utf-8 class Service: pass
8.2
15
0.634146
6
41
4.333333
1
0
0
0
0
0
0
0
0
0
0
0.033333
0.268293
41
4
16
10.25
0.833333
0.317073
0
0
0
0
0
0
0
0
0
0
0
1
0
true
0.5
0
0
0.5
0
1
1
0
null
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
null
0
0
0
0
0
0
1
1
0
0
0
0
0
5
4ffaf91d11f9891e047b57c2ccb9902a53f64678
2,851
py
Python
algebreb/ejercicios/tipos_ejercicios.py
Ivan0123456789/algebreb
c1548df99a7fc960b73239d296db4e2c914926cd
[ "MIT" ]
null
null
null
algebreb/ejercicios/tipos_ejercicios.py
Ivan0123456789/algebreb
c1548df99a7fc960b73239d296db4e2c914926cd
[ "MIT" ]
null
null
null
algebreb/ejercicios/tipos_ejercicios.py
Ivan0123456789/algebreb
c1548df99a7fc960b73239d296db4e2c914926cd
[ "MIT" ]
1
2021-12-13T03:20:08.000Z
2021-12-13T03:20:08.000Z
from sympy import * from algebreb.expresiones.polinomios import Polinomio class UnOperando(): def __init__(self, op1): self.oper = '' self.op1 = op1 self.res = self.operacion() self.respuestas = [] self.pasos = {} self.enunciado = '' def set_op1(self, op1): self.op1 = op1 def get_op1(self): return self.op1 def operacion(self): return def ver_pasos(self): return def as_str(self): dict = { 'operacion': str(self.oper), 'operando1': str(self.op1.as_expr()), 'solucion': str(self.res.as_expr()), 'respuestas': [str(r.as_expr()) for r in self.respuestas] } return dict def as_latex(self): dict = { 'operacion': self.oper, 'operando1': latex(self.op1.as_expr()), 'solucion': latex(self.res.as_expr()), 'enunciado': self.enunciado, 'respuestas': [latex(r.as_expr()) for r in self.respuestas], 'pasos': self.pasos } return dict def as_str_latex(self): diccionario = {} diccionario['string'] = self.as_str() diccionario['latex'] = self.as_latex() return diccionario class DosOperandos(): def __init__(self, op1, op2): self.oper = '' self.op1 = op1 self.op2 = op2 self.res = self.operacion() self.respuestas = [] self.pasos = {} self.enunciado = '' def set_op1(self, op1): self.op1 = op1 def get_op1(self): return self.op1 def set_op2(self, op2): self.op2 = op2 def get_op2(self): return self.op2 def operacion(self): return [r.as_expr() for r in self.respuestas] #if self.respuestas == [] else [] def ver_pasos(self): return def respuestas_str(self): return def as_str(self): dict = { 'operacion': str(self.oper), 'operando1': str(self.op1.as_expr()), 'operando2': str(self.op2.as_expr()), 'solucion': str(self.res.as_expr()), 'respuestas': [str(r.as_expr()) for r in self.respuestas] } return dict def as_latex(self): dict = { 'operacion': self.oper, 'operando1': latex(self.op1.as_expr()), 'operando2': latex(self.op2.as_expr()), 'enunciado': self.enunciado, 'solucion': latex(self.res.as_expr()), 'respuestas': [latex(r.as_expr()) for r in self.respuestas], 'pasos': self.pasos } return dict def as_str_latex(self): diccionario = {} diccionario['string'] = self.as_str() diccionario['latex'] = self.as_latex() return diccionario
24.161017
87
0.530691
325
2,851
4.52
0.123077
0.061266
0.023826
0.034037
0.811436
0.765146
0.678693
0.678693
0.660313
0.660313
0
0.020591
0.335672
2,851
118
88
24.161017
0.755016
0.011224
0
0.808989
0
0
0.075204
0
0
0
0
0
0
1
0.213483
false
0
0.022472
0.089888
0.41573
0
0
0
0
null
0
0
0
1
1
0
0
0
1
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
null
0
0
0
0
0
1
0
0
0
0
0
0
0
5