repo stringlengths 2 99 | file stringlengths 13 225 | code stringlengths 0 18.3M | file_length int64 0 18.3M | avg_line_length float64 0 1.36M | max_line_length int64 0 4.26M | extension_type stringclasses 1
value |
|---|---|---|---|---|---|---|
qfactor | qfactor-master/tests/gates/gate/test_repr.py | import numpy as np
import unittest as ut
from qfactor.gates import Gate
class TestGateRepr ( ut.TestCase ):
TOFFOLI = np.asarray(
[[1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j],
[0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j],
[0.+0.j, 0... | 1,196 | 35.272727 | 79 | py |
qfactor | qfactor-master/tests/gates/gate/__init__.py | 0 | 0 | 0 | py | |
qfactor | qfactor-master/tests/gates/ry/test_constructor.py | import scipy
import numpy as np
import unittest as ut
from qfactor import get_distance
from qfactor.gates import RyGate
class TestRyGateConstructor ( ut.TestCase ):
def test_rygate_constructor_invalid ( self ):
self.assertRaises( TypeError, RyGate, 1, 0 )
self.assertRaises( TypeError, RyGate, ... | 1,151 | 31.914286 | 64 | py |
qfactor | qfactor-master/tests/gates/ry/test_repr.py | import numpy as np
import unittest as ut
from qfactor.gates import RyGate
class TestRyGateRepr ( ut.TestCase ):
def test_rygate_repr_1 ( self ):
gate = RyGate( 0., 0 )
self.assertEqual( repr( gate ), "(0,): Ry(0.0)" )
def test_rygate_repr_2 ( self ):
gate = RyGate( 2., 1 )
... | 416 | 18.857143 | 57 | py |
qfactor | qfactor-master/tests/gates/ry/test_update.py | import numpy as np
import unittest as ut
from qfactor.gates import RyGate
class TestRyGateUpdate ( ut.TestCase ):
def test_rygate_update_1 ( self ):
env = RyGate( np.pi/3, 0 ).utry
gate = RyGate( 0., 0 )
gate.update( env, 0 )
self.assertTrue( np.allclose( gate.theta, -np.pi/3 ... | 988 | 25.72973 | 64 | py |
qfactor | qfactor-master/tests/gates/ry/__init__.py | 0 | 0 | 0 | py | |
qfactor | qfactor-master/tests/gates/rz/test_constructor.py | import scipy
import numpy as np
import unittest as ut
from qfactor import get_distance
from qfactor.gates import RzGate
class TestRzGateConstructor ( ut.TestCase ):
def test_rzgate_constructor_invalid ( self ):
self.assertRaises( TypeError, RzGate, 1, 0 )
self.assertRaises( TypeError, RzGate, ... | 1,149 | 31.857143 | 64 | py |
qfactor | qfactor-master/tests/gates/rz/test_repr.py | import numpy as np
import unittest as ut
from qfactor.gates import RzGate
class TestRzGateRepr ( ut.TestCase ):
def test_rzgate_repr_1 ( self ):
gate = RzGate( 0., 0 )
self.assertEqual( repr( gate ), "(0,): Rz(0.0)" )
def test_rzgate_repr_2 ( self ):
gate = RzGate( 2., 1 )
... | 416 | 18.857143 | 57 | py |
qfactor | qfactor-master/tests/gates/rz/test_update.py | import numpy as np
import unittest as ut
from qfactor.gates import RzGate
class TestRzGateUpdate ( ut.TestCase ):
def test_rzgate_update_1 ( self ):
env = RzGate( np.pi/3, 0 ).utry
gate = RzGate( 0., 0 )
gate.update( env, 0 )
self.assertTrue( np.allclose( gate.theta, -np.pi/3 ... | 988 | 25.72973 | 64 | py |
qfactor | qfactor-master/tests/gates/rz/__init__.py | 0 | 0 | 0 | py | |
qfactor | qfactor-master/tests/utils/test_is_matrix.py | import numpy as np
import unittest as ut
from scipy.stats import unitary_group
from qfactor.utils import is_matrix
class TestIsMatrix ( ut.TestCase ):
def test_is_matrix1 ( self ):
for i in range( 1, 10 ):
self.assertTrue( is_matrix( unitary_group.rvs( 2 * i ) ) )
def test_is_... | 695 | 25.769231 | 70 | py |
qfactor | qfactor-master/tests/utils/test_is_unitary.py | import numpy as np
import scipy as sp
import unittest as ut
from scipy.stats import unitary_group
from qfactor.utils import is_unitary
class TestIsUnitary ( ut.TestCase ):
def test_is_unitary1 ( self ):
for i in range( 1, 10 ):
U = unitary_group.rvs( 2 * i )
self.assert... | 950 | 28.71875 | 66 | py |
qfactor | qfactor-master/tests/utils/test_is_square_matrix.py | import numpy as np
import unittest as ut
from scipy.stats import unitary_group
from qfactor.utils import is_square_matrix
class TestIsSquareMatrix ( ut.TestCase ):
def test_is_square_matrix1 ( self ):
for i in range( 1, 10 ):
self.assertTrue( is_square_matrix( unitary_group.rvs( 2 * i... | 772 | 28.730769 | 77 | py |
qfactor | qfactor-master/tests/utils/test_is_valid_location.py | import numpy as np
import unittest as ut
from qfactor.utils import is_valid_location
class TestIsValidLocation ( ut.TestCase ):
def test_is_valid_location_invalid1 ( self ):
self.assertFalse( is_valid_location( "a" ) )
self.assertFalse( is_valid_location( 0 ) )
self.assertFalse( i... | 1,606 | 35.522727 | 65 | py |
qfactor | qfactor-master/tests/utils/__init__.py | 0 | 0 | 0 | py | |
qfactor | qfactor-master/tests/utils/test_get_num_qubits.py | import numpy as np
import unittest as ut
from qfactor.utils import get_num_qubits
class TestGetNumQubits ( ut.TestCase ):
def test_num_qubits ( self ):
for i in range( 4 ):
M = np.identity( 2 ** i )
self.assertTrue( get_num_qubits( M ) == i )
def test_num_qubits_i... | 623 | 23 | 58 | py |
pytorch_conv4D | pytorch_conv4D-master/conv4d.py | import numpy as np
import math
import torch
import torch.nn as nn
import torch.nn.functional as F
class Conv4d_broadcast(nn.Module):
def __init__(self, in_channels,
out_channels,
kernel_size,
padding,
stride=1,
padding_mode='circ... | 9,176 | 40.337838 | 116 | py |
pytorch_conv4D | pytorch_conv4D-master/__init__.py | 0 | 0 | 0 | py | |
pytorch_conv4D | pytorch_conv4D-master/test_conv4d.py | import pytest
import timeit
import numpy as np
import scipy.stats as sns
from functools import partial
import torch
import torch.nn as nn
from .conv4d import Conv4d_broadcast, Conv4d_groups
try:
import intel_extension_for_pytorch as ipex
device = torch.device("xpu" if torch.xpu.is_available() else "cpu")
... | 7,179 | 35.262626 | 106 | py |
phocnet | phocnet-master/install.py | import os
import shutil
import logging
import argparse
from subprocess import call
import sys
def main(cudnn_dir, no_caffe, opencv_dir, install_dir, install_caffe_dir):
# init logger
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger('install.py')
# init submodules
call(['git',... | 2,659 | 41.222222 | 174 | py |
phocnet | phocnet-master/tools/predict_phocs.py | #!/usr/bin/env python
'''
Script for predicting PHOCs for a number of images residing in a folder on disk.
'''
import argparse
import logging
import os
import caffe
import numpy as np
import cv2
from phocnet.evaluation.cnn import net_output_for_word_image_list
def main(img_dir, output_dir, pretrained_phocnet, deploy... | 2,673 | 42.836066 | 133 | py |
phocnet | phocnet-master/tools/train_phocnet.py | import argparse
from phocnet.training.phocnet_trainer import PHOCNetTrainer
if __name__ == '__main__':
parser = argparse.ArgumentParser()
# required training parameters
parser.add_argument('--doc_img_dir', action='store', type=str, required=True,
help='The location of the document ima... | 4,914 | 80.916667 | 149 | py |
phocnet | phocnet-master/tools/eval_phocnet.py | '''
This script uses a pretrained PHOCNet to generate the
output for a given test list
'''
import argparse
from phocnet.evaluation.phocnet_evaluator import PHOCNetEvaluation
if __name__ == '__main__':
pne = PHOCNetEvaluation()
parser = argparse.ArgumentParser()
subparser = parser.add_subparsers()
... | 4,794 | 67.5 | 152 | py |
phocnet | phocnet-master/tools/save_deploy_proto.py | #!/usr/bin/env python
import argparse
import os
from phocnet.caffe.model_proto_generator import ModelProtoGenerator
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Save a PHOCNet deploy proto file to disk.')
parser.add_argument('--output_dir', '-od', action='store', type=str, default='... | 1,028 | 59.529412 | 118 | py |
phocnet | phocnet-master/examples/prediction_example.py | import caffe
import numpy as np
def main():
# This example is going to show you how you can use the API to predict
# PHOCs from a trained PHOCNet for your own word images.
# First we need to load the trained PHOCNet. We are going to use the trained
# PHOCNet supplied at
# http://patrec.cs.tu-dort... | 2,767 | 44.377049 | 85 | py |
phocnet | phocnet-master/src/phocnet/__init__.py | 0 | 0 | 0 | py | |
phocnet | phocnet-master/src/phocnet/evaluation/cnn.py | '''
Created on Jul 10, 2016
@author: ssudholt
'''
import logging
import numpy as np
from skimage.transform import resize
from phocnet.evaluation.retrieval import map_from_feature_matrix
def net_output_for_word_image_list(phocnet, word_img_list,
min_img_width_height=-1,input_layer... | 3,594 | 44.506329 | 113 | py |
phocnet | phocnet-master/src/phocnet/evaluation/retrieval.py | '''
Created on Jul 10, 2016
@author: ssudholt
'''
import numpy as np
from scipy.spatial.distance import pdist, squareform, cdist
def map_from_feature_matrix(features, labels, metric, drop_first):
'''
Computes mAP and APs from a given matrix of feature vectors
Each sample is used as a query once and all th... | 6,032 | 38.690789 | 117 | py |
phocnet | phocnet-master/src/phocnet/evaluation/time.py | '''
Created on Jul 10, 2016
@author: ssudholt
'''
def convert_secs2HHMMSS(secs):
'''
Takes as input a float/int representing a timing interval in seconds
and converts it to a string in the format hh:mm:ss
'''
secs = int(secs)
m, s = divmod(secs, 60)
h, m = divmod(m, 60)
return'%dh%02dm%... | 337 | 23.142857 | 72 | py |
phocnet | phocnet-master/src/phocnet/evaluation/__init__.py | 0 | 0 | 0 | py | |
phocnet | phocnet-master/src/phocnet/evaluation/phocnet_evaluator.py | '''
Created on Aug 29, 2016
@author: ssudholt
'''
import logging
import os
import caffe
import numpy as np
from skimage.transform import resize
from phocnet.caffe.model_proto_generator import ModelProtoGenerator
from phocnet.io.xml_io import XMLReader
from phocnet.io.context_manager import Suppressor
from phocnet.a... | 12,724 | 51.80083 | 136 | py |
phocnet | phocnet-master/src/phocnet/io/word_container.py | '''
Created on Aug 29, 2014
This module holds simple container classes for storing
word images for the PHOCNet experiments
@author: ssudholt
'''
import cv2
import numpy as np
class SimpleWordContainer(object):
def __init__(self, transcription, bounding_box, image_path):
self.__transcription = transcript... | 2,747 | 25.423077 | 114 | py |
phocnet | phocnet-master/src/phocnet/io/context_manager.py | '''
Created on Aug 28, 2014
@author: ssudholt
'''
import os
class Suppressor(object):
'''
A context manager for doing a "deep suppression" of stdout and stderr in
Python, i.e. will suppress all print, even if the print originates in a
compiled C/Fortran sub-function.
This will not suppress r... | 1,201 | 31.486486 | 77 | py |
phocnet | phocnet-master/src/phocnet/io/__init__.py | 0 | 0 | 0 | py | |
phocnet | phocnet-master/src/phocnet/io/word_list.py | '''
Created on Jul 8, 2016
@author: ssudholt
'''
import os
from xml.etree import ElementTree
import numpy as np
from phocnet.io.word_container import DocImageWordContainer
def load_word_list_from_READ_xml(xml_file_path, doc_img_dir, dataset_name):
tree = ElementTree.parse(os.path.join(xml_file_path))
root =... | 1,569 | 49.645161 | 118 | py |
phocnet | phocnet-master/src/phocnet/io/files.py | '''
Created on Jul 10, 2016
@author: ssudholt
'''
import os
def save_prototxt(file_path, proto_object, header_comment=None):
with open(file_path, 'w') as output_file:
if header_comment is not None:
output_file.write('#' + header_comment + '\n')
output_file.write(str(proto_object))
def... | 1,013 | 27.166667 | 82 | py |
phocnet | phocnet-master/src/phocnet/io/xml_io.py | '''
Created on Jul 9, 2016
@author: ssudholt
'''
import logging
import os
import xml.etree.ElementTree as ET
import numpy as np
from phocnet.io.word_container import DocImageWordContainer
class XMLReader(object):
'''
Class for reading a training and test set from two READ-style XML files.
'''
def __... | 3,251 | 45.457143 | 122 | py |
phocnet | phocnet-master/src/phocnet/training/phocnet_trainer.py | '''
Created on Aug 29, 2016
@author: ssudholt
'''
import logging
import os
import time
import caffe
import numpy as np
from skimage.transform import resize
from phocnet.attributes.phoc import build_phoc, unigrams_from_word_list,\
get_most_common_n_grams
from phocnet.caffe.model_proto_generator import ModelProtoG... | 24,351 | 53.970655 | 141 | py |
phocnet | phocnet-master/src/phocnet/training/__init__.py | 0 | 0 | 0 | py | |
phocnet | phocnet-master/src/phocnet/numpy/numpy_helper.py | '''
Created on Feb 25, 2015
@author: ssudholt
'''
import numpy as np
class NumpyHelper(object):
@staticmethod
def get_unique_rows(arr, return_indices=False):
'''
Returns the unique rows of the supplied array
this code was originally proposed at stackoverflow
http://sta... | 970 | 31.366667 | 99 | py |
phocnet | phocnet-master/src/phocnet/numpy/__init__.py | 0 | 0 | 0 | py | |
phocnet | phocnet-master/src/phocnet/attributes/__init__.py | 0 | 0 | 0 | py | |
phocnet | phocnet-master/src/phocnet/attributes/phoc.py | '''
Created on Dec 17, 2015
@author: ssudholt
'''
import logging
import numpy as np
def get_most_common_n_grams(words, num_results=50, n=2):
'''
Calculates the 50 (default) most common bigrams (default) from a
list of pages, where each page is a list of WordData objects.
Args:
words (list of... | 5,251 | 41.354839 | 150 | py |
phocnet | phocnet-master/src/phocnet/caffe/augmentation.py | '''
Created on Feb 18, 2016
@author: ssudholt
'''
import numpy as np
import cv2
class AugmentationCreator(object):
'''
classdocs
'''
def __init__(self):
'''
Constructor
'''
pass
@staticmethod
def create_affine_transform_augmentation(img, random_limits=(0.8... | 9,205 | 36.729508 | 124 | py |
phocnet | phocnet-master/src/phocnet/caffe/solver_proto_generator.py | '''
Created on Jul 9, 2016
@author: ssudholt
'''
from caffe.proto import caffe_pb2
from google.protobuf.internal.containers import RepeatedScalarFieldContainer
def generate_solver_proto(**kwargs):
sp = caffe_pb2.SolverParameter()
for k,v in kwargs.iteritems():
if not hasattr(sp, k):
raise ... | 734 | 32.409091 | 95 | py |
phocnet | phocnet-master/src/phocnet/caffe/model_proto_generator.py | # pylint: disable=too-many-arguments
'''
Created on Jul 8, 2016
@author: ssudholt
'''
import logging
from caffe import NetSpec
from caffe import layers as L
from caffe import params as P
from caffe.io import caffe_pb2
import argparse
class ModelProtoGenerator(object):
'''
Class for generating Caffe CNN model... | 9,101 | 49.566667 | 129 | py |
phocnet | phocnet-master/src/phocnet/caffe/lmdb_creator.py | '''
Created on Feb 18, 2016
@author: ssudholt
'''
import os
import shutil
import logging
import numpy as np
import lmdb
import caffe.io
# from patrec.serialization.list_io import LineListIO
class CaffeLMDBCreator(object):
def __init__(self):
'''
LMDB creator can create a single LMDB for single l... | 9,744 | 48.217172 | 139 | py |
phocnet | phocnet-master/src/phocnet/caffe/__init__.py | 0 | 0 | 0 | py | |
pLogicNet | pLogicNet-master/utils.py | import sys
import os
# This function computes the probability of a triplet being true based on the MLN outputs.
def mln_triplet_prob(h, r, t, hrt2p):
# KGE algorithms tend to predict triplets like (e, r, e), which are less likely in practice.
# Therefore, we give a penalty to such triplets, which yields some i... | 4,033 | 29.793893 | 96 | py |
pLogicNet | pLogicNet-master/run.py | import sys
import os
import datetime
from utils import augment_triplet, evaluate
dataset = 'data/FB15k'
path = './record'
iterations = 2
kge_model = 'TransE'
kge_batch = 1024
kge_neg = 256
kge_dim = 100
kge_gamma = 24
kge_alpha = 1
kge_lr = 0.001
kge_iters = 10000
kge_tbatch = 16
kge_reg = 0.0
kge_topk = 100
if kge... | 7,970 | 51.440789 | 284 | py |
pLogicNet | pLogicNet-master/kge/dataloader.py | #!/usr/bin/python3
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import numpy as np
import torch
from torch.utils.data import Dataset
class TrainDataset(Dataset):
def __init__(self, triples, nentity, nrelation, negative_sample_size, mode):
s... | 6,670 | 35.255435 | 107 | py |
pLogicNet | pLogicNet-master/kge/model.py | #!/usr/bin/python3
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import logging
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
from sklearn.metrics import average_precision_score
from torch.utils.data import Data... | 18,193 | 37.222689 | 186 | py |
pLogicNet | pLogicNet-master/kge/run.py | #!/usr/bin/python3
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import argparse
import json
import logging
import os
import random
import numpy as np
import torch
from torch.utils.data import DataLoader
from model import KGEModel
from dataloader impo... | 18,047 | 39.832579 | 113 | py |
Tokenizer | Tokenizer-master/setup.py | #!/usr/bin/env python
"""
Tokenizer for Icelandic text
Copyright (C) 2022 Miðeind ehf.
Original author: Vilhjálmur Þorsteinsson
This software is licensed under the MIT License:
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associate... | 3,938 | 36.160377 | 90 | py |
Tokenizer | Tokenizer-master/src/tokenizer/main.py | #!/usr/bin/env python
"""
Tokenizer for Icelandic text
Copyright (C) 2022 Miðeind ehf.
Original author: Vilhjálmur Þorsteinsson
This software is licensed under the MIT License:
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associate... | 9,652 | 30.545752 | 86 | py |
Tokenizer | Tokenizer-master/src/tokenizer/abbrev.py | """
Abbreviations module for tokenization of Icelandic text
Copyright (C) 2022 Miðeind ehf.
Original author: Vilhjálmur Þorsteinsson
This software is licensed under the MIT License:
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and asso... | 13,144 | 40.466877 | 94 | py |
Tokenizer | Tokenizer-master/src/tokenizer/definitions.py | """
Definitions used for tokenization of Icelandic text
Copyright (C) 2022 Miðeind ehf.
Original author: Vilhjálmur Þorsteinsson
This software is licensed under the MIT License:
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associat... | 27,539 | 20.787975 | 92 | py |
Tokenizer | Tokenizer-master/src/tokenizer/version.py | __version__ = "3.4.2"
| 22 | 10.5 | 21 | py |
Tokenizer | Tokenizer-master/src/tokenizer/tokenizer.py | """
Tokenizer for Icelandic text
Copyright (C) 2022 Miðeind ehf.
Original author: Vilhjálmur Þorsteinsson
This software is licensed under the MIT License:
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
... | 128,327 | 37.618116 | 107 | py |
Tokenizer | Tokenizer-master/src/tokenizer/__init__.py | """
Copyright(C) 2022 Miðeind ehf.
Original author: Vilhjálmur Þorsteinsson
This software is licensed under the MIT License:
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal i... | 2,759 | 25.796117 | 78 | py |
Tokenizer | Tokenizer-master/test/test_tokenizer_tok.py | # type: ignore
"""
Tests for Tokenizer module
Copyright (C) 2022 by Miðeind ehf.
This software is licensed under the MIT License:
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to ... | 18,605 | 30.589134 | 94 | py |
Tokenizer | Tokenizer-master/test/test_detokenize.py | # type: ignore
"""
test_detokenize.py
Tests for Tokenizer module
Copyright (C) 2022 by Miðeind ehf.
Original author: Vilhjálmur Þorsteinsson
This software is licensed under the MIT License:
Permission is hereby granted, free of charge, to any person
obtaining a copy of this sof... | 2,916 | 36.883117 | 87 | py |
Tokenizer | Tokenizer-master/test/test_index_calculation.py | # type: ignore
"""
test_index_calculation.py
Tests for Tokenizer module
Copyright (C) 2022 by Miðeind ehf.
This software is licensed under the MIT License:
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
... | 21,320 | 39.611429 | 141 | py |
Tokenizer | Tokenizer-master/test/test_tokenizer.py | # type: ignore
"""
test_tokenizer.py
Tests for Tokenizer module
Copyright (C) 2022 by Miðeind ehf.
Original author: Vilhjálmur Þorsteinsson
This software is licensed under the MIT License:
Permission is hereby granted, free of charge, to any person
obtaining a copy of this softw... | 102,165 | 38.768782 | 131 | py |
z3 | z3-master/examples/python/visitor.py | # Copyright (c) Microsoft Corporation 2015
from __future__ import print_function
from z3 import *
def visitor(e, seen):
if e in seen:
return
seen[e] = True
yield e
if is_app(e):
for ch in e.children():
for e in visitor(ch, seen):
yield e
return
if... | 2,796 | 30.784091 | 141 | py |
z3 | z3-master/examples/python/example.py | # Copyright (c) Microsoft Corporation 2015, 2016
# The Z3 Python API requires libz3.dll/.so/.dylib in the
# PATH/LD_LIBRARY_PATH/DYLD_LIBRARY_PATH
# environment variable and the PYTHONPATH environment variable
# needs to point to the `python' directory that contains `z3/z3.py'
# (which is at bin/python in our binary ... | 1,036 | 27.027027 | 70 | py |
z3 | z3-master/examples/python/rc2.py | # RC2 algorithm
# basic version with some optimizations
# - process soft constraints in order of highest values first.
# - extract multiple cores, not just one
# - use built-in cardinality constraints, cheap core minimization.
#
# See also https://github.com/pysathq/pysat and papers in CP 2014, JSAT 2015.
from z3 imp... | 4,917 | 29.7375 | 92 | py |
z3 | z3-master/examples/python/union_sort.py | # Copyright Microsoft Corporation 2019
# This example illustrates the use of union types
# from the Python API. It is given as an example
# as response to #2215.
from z3 import *
u = Datatype('IntOrString')
u.declare('IntV', ('int', IntSort()))
u.declare('StringV', ('string', StringSort()))
IntOrString = u.create()
S... | 543 | 24.904762 | 49 | py |
z3 | z3-master/examples/python/all_interval_series.py | # Copyright Microsoft Research 2016
# The following script finds sequences of length n-1 of
# integers 0,..,n-1 such that the difference of the n-1
# adjacent entries fall in the range 0,..,n-1
# This is known as the "The All-Interval Series Problem"
# See http://www.csplib.org/Problems/prob007/
from __future__ import ... | 2,389 | 29.253165 | 108 | py |
z3 | z3-master/examples/python/mini_quip.py | from z3 import *
import heapq
import numpy
import time
import random
verbose = True
# Simplistic (and fragile) converter from
# a class of Horn clauses corresponding to
# a transition system into a transition system
# representation as <init, trans, goal>
# It assumes it is given three Horn clauses
# of the form:
# ... | 25,576 | 31.499365 | 126 | py |
z3 | z3-master/examples/python/efsmt.py | from z3 import *
from z3.z3util import get_vars
'''
Modified from the example in pysmt
https://github.com/pysmt/pysmt/blob/97088bf3b0d64137c3099ef79a4e153b10ccfda7/examples/efsmt.py
'''
def efsmt(ys, phi, maxloops = None):
"""Solving exists xs. forall ys. phi(x, y)"""
xs = [x for x in get_vars(phi) if x not ... | 1,176 | 29.179487 | 94 | py |
z3 | z3-master/examples/python/trafficjam.py | from z3 import *
class Car():
def __init__(self, is_vertical, base_pos, length, start, color):
self.is_vertical = is_vertical
self.base = base_pos
self.length = length
self.start = start
self.color = color
def __eq__(self, other):
return self.color == ... | 3,434 | 25.627907 | 92 | py |
z3 | z3-master/examples/python/simplify_formula.py | from z3 import *
def is_atom(t):
if not is_bool(t):
return False
if not is_app(t):
return False
k = t.decl().kind()
if k == Z3_OP_AND or k == Z3_OP_OR or k == Z3_OP_IMPLIES:
return False
if k == Z3_OP_EQ and t.arg(0).is_bool():
return False
if k == Z3_OP_TRUE or ... | 1,996 | 22.77381 | 79 | py |
z3 | z3-master/examples/python/socrates.py | ############################################
# Copyright (c) Microsoft Corporation. All Rights Reserved.
#
# all humans are mortal
# Socrates is a human
# so Socrates mortal
############################################
from z3 import *
Object = DeclareSort('Object')
Human = Function('Human', Object, BoolSort())
Mor... | 793 | 21.685714 | 64 | py |
z3 | z3-master/examples/python/mini_ic3.py | from z3 import *
import heapq
# Simplistic (and fragile) converter from
# a class of Horn clauses corresponding to
# a transition system into a transition system
# representation as <init, trans, goal>
# It assumes it is given three Horn clauses
# of the form:
# init(x) => Invariant(x)
# Invariant(x) and trans(x,x... | 11,936 | 28.76808 | 101 | py |
z3 | z3-master/examples/python/prooflogs.py | # This script illustrates uses of proof logs over the Python interface.
from z3 import *
example1 = """
(declare-sort T)
(declare-fun subtype (T T) Bool)
;; subtype is reflexive
(assert (forall ((x T)) (subtype x x)))
;; subtype is antisymmetric
(assert (forall ((x T) (y T)) (=> (and (subtype x y)
... | 2,810 | 28.904255 | 71 | py |
z3 | z3-master/examples/python/hs.py | #
# Unweighted hitting set maxsat solver.
# interleaved with local hill-climbing improvements
# and also maxres relaxation steps to reduce number
# of soft constraints.
#
from z3 import *
import random
counter = 0
def add_def(s, fml):
global counter
name = Bool(f"def-{counter}")
counter += 1
s.add(na... | 17,449 | 34.323887 | 152 | py |
z3 | z3-master/examples/python/parallel.py | from z3 import *
from multiprocessing.pool import ThreadPool
from copy import deepcopy
pool = ThreadPool(8)
x = Int('x')
assert x.ctx == main_ctx()
def calculate(x, n, ctx):
""" Do a simple computation with a context"""
assert x.ctx == ctx
assert x.ctx != main_ctx()
# Parallel creation of z3 object... | 849 | 21.972973 | 105 | py |
z3 | z3-master/examples/python/proofreplay.py | # This script illustrates uses of proof replay and proof logs over the Python interface.
from z3 import *
example1 = """
(declare-sort T)
(declare-fun subtype (T T) Bool)
;; subtype is reflexive
(assert (forall ((x T)) (subtype x x)))
;; subtype is antisymmetric
(assert (forall ((x T) (y T)) (=> (and (subtype x y... | 4,308 | 36.798246 | 101 | py |
z3 | z3-master/examples/python/bounded model checking/bubble_sort.py | # File name: bubble_sort.py
#
# BUBBLESORT - Copyright (c) June, 2020 - Matteo Nicoli
from z3 import Solver, Int, Array, IntSort, And, Not, If, Select, Store, sat
def init(i,j) :
return And(i == 0, j == 0)
def invert(A0, A1, tmp, i0, i1) :
return If(Select(A0, i0) > Select(A0, i0 + 1), \
... | 2,473 | 25.319149 | 78 | py |
z3 | z3-master/examples/python/mus/marco.py | ############################################
# Copyright (c) 2016 Microsoft Corporation
#
# Basic core and correction set enumeration.
#
# Author: Nikolaj Bjorner (nbjorner)
############################################
"""
Enumeration of Minimal Unsatisfiable Cores and Maximal Satisfying Subsets
This tutorial illustr... | 6,746 | 35.080214 | 117 | py |
z3 | z3-master/examples/python/mus/mss.py | ############################################
# Copyright (c) 2016 Microsoft Corporation
#
# MSS enumeration based on maximal resolution.
#
# Author: Nikolaj Bjorner (nbjorner)
############################################
"""
The following is a procedure for enumerating maximal satisfying subsets.
It uses maximal res... | 5,260 | 31.079268 | 122 | py |
z3 | z3-master/examples/python/hamiltonian/hamiltonian.py | ############################################
# Copyright (c) Microsoft Corporation. All Rights Reserved.
#
# Check if the given graph has a Hamiltonian cycle.
#
# Author: Ganesh Gopalakrishnan [email protected]
############################################
from z3 import *
def gencon(gr):
"""
Input a graph a... | 2,941 | 32.05618 | 95 | py |
z3 | z3-master/examples/python/complex/complex.py | ############################################
# Copyright (c) 2012 Microsoft Corporation
#
# Complex numbers in Z3
# See http://research.microsoft.com/en-us/um/people/leonardo/blog/2013/01/26/complex.html
#
# Author: Leonardo de Moura (leonardo)
############################################
from __future__ import print... | 3,596 | 27.101563 | 99 | py |
z3 | z3-master/src/api/python/setup.py | import os
import sys
import shutil
import platform
import subprocess
import multiprocessing
import re
import glob
from setuptools import setup
from distutils.util import get_platform
from distutils.errors import LibError
from distutils.command.build import build as _build
from distutils.command.sdist import sdist as _s... | 13,960 | 39.002865 | 406 | py |
z3 | z3-master/src/api/python/z3test.py | ############################################
# Copyright (c) 2012 Microsoft Corporation
#
# Z3 Python interface
#
# Author: Leonardo de Moura (leonardo)
############################################
import z3, doctest, sys
if len(sys.argv) < 2 or sys.argv[1] == 'z3':
r = doctest.testmod(z3.z3)
elif sys.argv[1] == ... | 464 | 21.142857 | 44 | py |
z3 | z3-master/src/api/python/z3/z3rcf.py | ############################################
# Copyright (c) 2013 Microsoft Corporation
#
# Z3 Python interface for Z3 Real Closed Fields
# that may contain
# - computable transcendentals
# - infinitesimals
# - algebraic extensions
#
# Author: Leonardo de Moura (leonardo)
######################################... | 5,039 | 28.822485 | 84 | py |
z3 | z3-master/src/api/python/z3/z3poly.py | ############################################
# Copyright (c) 2012 Microsoft Corporation
#
# Z3 Python interface for Z3 polynomials
#
# Author: Leonardo de Moura (leonardo)
############################################
from .z3 import *
def subresultants(p, q, x):
"""
Return the non-constant subresultants of '... | 1,113 | 28.315789 | 105 | py |
z3 | z3-master/src/api/python/z3/z3types.py | ############################################
# Copyright (c) 2012 Microsoft Corporation
#
# Z3 Python interface
#
# Author: Leonardo de Moura (leonardo)
############################################
import ctypes
class Z3Exception(Exception):
def __init__(self, value):
self.value = value
def __str__(... | 4,883 | 18.152941 | 46 | py |
z3 | z3-master/src/api/python/z3/z3util.py | ############################################
# Copyright (c) 2012 Microsoft Corporation
#
# Z3 Python interface
#
# Authors: Leonardo de Moura (leonardo)
# ThanhVu (Vu) Nguyen <[email protected]>
############################################
"""
Usage:
import common_z3 as CM_Z3
"""
import ctypes
from .z3 impo... | 11,387 | 21.640159 | 97 | py |
z3 | z3-master/src/api/python/z3/z3.py | ############################################
# Copyright (c) 2012 Microsoft Corporation
#
# Z3 Python interface
#
# Author: Leonardo de Moura (leonardo)
############################################
"""Z3 is a high performance theorem prover developed at Microsoft Research.
Z3 is used in many applications such as: sof... | 337,613 | 27.772286 | 151 | py |
z3 | z3-master/src/api/python/z3/z3printer.py | ############################################
# Copyright (c) 2012 Microsoft Corporation
#
# Z3 Python interface
#
# Author: Leonardo de Moura (leonardo)
############################################
import sys
import io
# We want to import submodule z3 here, but there's no way
# to do that that works correctly on both ... | 45,224 | 28.871202 | 116 | py |
z3 | z3-master/src/api/python/z3/z3num.py | ############################################
# Copyright (c) 2012 Microsoft Corporation
#
# Z3 Python interface for Z3 numerals
#
# Author: Leonardo de Moura (leonardo)
############################################
from .z3 import *
from .z3core import *
from .z3printer import *
from fractions import Fraction
from .z3 ... | 16,090 | 26.743103 | 110 | py |
z3 | z3-master/src/api/python/z3/__init__.py | from .z3 import *
from . import z3num
from . import z3poly
from . import z3printer
from . import z3rcf
from . import z3types
from . import z3util
# generated files
from . import z3core
from . import z3consts
| 210 | 15.230769 | 23 | py |
z3 | z3-master/scripts/mk_gparams_register_modules_cpp.py | # -- /usr/bin/env python
"""
Determines the available global parameters from a list of header files and
generates a ``gparams_register_modules.cpp`` file in the destination directory
that defines a function ``void gparams_register_modules()``.
"""
import mk_genfile_common
import argparse
import logging
import os
import... | 1,236 | 29.170732 | 78 | py |
z3 | z3-master/scripts/mk_copyright.py | # Copyright (c) 2015 Microsoft Corporation
import os
import re
cr = re.compile("Copyright")
aut = re.compile("Automatically generated")
cr_notice = """
/*++
Copyright (c) 2015 Microsoft Corporation
--*/
"""
def has_cr(file):
ins = open(file)
lines = 0
line = ins.readline()
while line and lines < 2... | 1,259 | 20.724138 | 95 | py |
z3 | z3-master/scripts/pyg2hpp.py | # - /usr/bin/env python
"""
Reads a pyg file and emits the corresponding
C++ header file into the specified destination
directory.
"""
import mk_genfile_common
import argparse
import logging
import os
import sys
def main(args):
logging.basicConfig(level=logging.INFO)
parser = argparse.ArgumentParser(descripti... | 1,100 | 28.756757 | 88 | py |
z3 | z3-master/scripts/mk_genfile_common.py | # This file contains code that is common to
# both the Python build system and the CMake
# build system.
#
# The code here generally is involved in
# generating files needed by Z3 at build time.
#
# You should **not** import ``mk_util`` here
# to avoid having this code depend on the
# of the Python build system.
import... | 39,190 | 39.654564 | 198 | py |
z3 | z3-master/scripts/mk_exception.py | ############################################
# Copyright (c) 2012 Microsoft Corporation
#
# Author: Leonardo de Moura (leonardo)
############################################
class MKException(Exception):
def __init__(self, value):
self.value = value
def __str__(self):
return repr(self.value)
| 320 | 23.692308 | 44 | py |
z3 | z3-master/scripts/mk_win_dist.py | ############################################
# Copyright (c) 2012 Microsoft Corporation
#
# Scripts for automatically generating
# Window distribution zip files.
#
# Author: Leonardo de Moura (leonardo)
############################################
import os
import glob
import re
import getopt
import sys
import shutil
i... | 12,186 | 33.041899 | 152 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.