How to use invariant_1 method in hypothesis

Best Python code snippet using hypothesis

datalog.py

Source:datalog.py Github

copy

Full Screen

1import logging2from pyDatalog import pyDatalog3from pyDatalog import pyEngine4pyEngine.Logging = True5logging.basicConfig(level=logging.INFO)6 7 8pyDatalog.create_terms('isConnected,hostACL,A,existsRoute,knows,hasAccount,H,K,M,hasUser,N,Q,P,S,listeningOn,U,T,V,X,isRouter,ID6,ID4,ID5,ID2,ID3,ID1,R')9## www_1 ##10# www_system_1 (sdl.nodes.System.Linux),isConnected11+ isConnected(1,'www_1', 'DMZ_subnet_1')12# www_root_1 (sdl.nodes.User.Linux),hasUser13+ hasUser(2,'www_root_1', 'www_1', 'None', 'admin')14# www_ssh_1 (sdl.nodes.Software.Server.SSH.Linux.OpenSSH),listeningOn15+ listeningOn(3,'www_1', 'tcp', '22')16# www_vuln2_1 (sdl.nodes.Vulnerability.Linux.User.RemoteWeakPassword),hasAccount17hasAccount(4,A, 'www_1', 'www_user1_1') <= knows(ID1,A, 'alice') & hasUser(ID2,'www_user1_1', 'www_1', P, R) & listeningOn(ID3,'www_1', 'tcp', '22') & hostACL(ID4,K, 'www_1', 'tcp', '22') & hasAccount(ID5,A, K, V)18# www_vuln1_1 (sdl.nodes.Vulnerability.Linux.EOP.APT),hasAccount19hasAccount(5,A, 'www_1', 'www_root_1') <= hasUser(ID1,'www_root_1', 'www_1', P, R) & hasAccount(ID2,A, 'www_1', 'www_user1_1')20# www_weak1_1 (sdl.nodes.Vulnerability.Linux.User.RemoteEnumerable),knows21knows(6,A, 'alice') <= listeningOn(ID1,'www_1', 'tcp', '80') & hostACL(ID2,K, 'www_1', 'tcp', '80') & hasAccount(ID3,A, K, V)22# www_user1_1 (sdl.nodes.User.Linux),hasUser23+ hasUser(7,'www_user1_1', 'www_1', 'xexexexe', 'user')24# www_http_1 (sdl.nodes.Software.Server.HTTP.Linux.Apache),listeningOn25+ listeningOn(8,'www_1', 'tcp', '80')26# www_cms_1 (sdl.nodes.Software.Server.CMS.Linux.Wordpress),knows227knows(9,A, 'venerus') <= hasUser(ID1,'www_sysuser1_1','www_1',P, R) & hasAccount(ID2,A,'www_1', 'www_sysuser1_1')28# www_cms_1 (sdl.nodes.Software.Server.CMS.Linux.Wordpress),knows129knows(10,A, 'venerus') <= hasUser(ID1,U,'www_1',P,'admin') & hasAccount(ID2,A,'www_1',U)30# www_sysuser1_1 (sdl.nodes.User.Linux),hasUser31+ hasUser(11,'www_sysuser1_1', 'www_1', 'None', 'user')32## Firewall_1 ##33# Firewall_UFW_1 (sdl.nodes.Firewall.UFW),existsRoute34+ existsRoute(12,'Server_subnet_1','Server_subnet_1','Firewall_1')35# Firewall_UFW_1 (sdl.nodes.Firewall.UFW),existsRoute36+ existsRoute(12,'Server_subnet_1','Outside_subnet_1','Firewall_1')37# Firewall_UFW_1 (sdl.nodes.Firewall.UFW),existsRoute38+ existsRoute(12,'Server_subnet_1','DMZ_subnet_1','Firewall_1')39# Firewall_UFW_1 (sdl.nodes.Firewall.UFW),existsRoute40+ existsRoute(12,'Outside_subnet_1','Server_subnet_1','Firewall_1')41# Firewall_UFW_1 (sdl.nodes.Firewall.UFW),existsRoute42+ existsRoute(12,'Outside_subnet_1','Outside_subnet_1','Firewall_1')43# Firewall_UFW_1 (sdl.nodes.Firewall.UFW),existsRoute44+ existsRoute(12,'Outside_subnet_1','DMZ_subnet_1','Firewall_1')45# Firewall_UFW_1 (sdl.nodes.Firewall.UFW),existsRoute46+ existsRoute(12,'DMZ_subnet_1','Server_subnet_1','Firewall_1')47# Firewall_UFW_1 (sdl.nodes.Firewall.UFW),existsRoute48+ existsRoute(12,'DMZ_subnet_1','Outside_subnet_1','Firewall_1')49# Firewall_UFW_1 (sdl.nodes.Firewall.UFW),existsRoute50+ existsRoute(12,'DMZ_subnet_1','DMZ_subnet_1','Firewall_1')51# Firewall_UFW_1 (sdl.nodes.Firewall.UFW),isConnected52+ isConnected(13,'Firewall_1', 'Server_subnet_1')53# Firewall_UFW_1 (sdl.nodes.Firewall.UFW),isConnected54+ isConnected(13,'Firewall_1', 'Outside_subnet_1')55# Firewall_UFW_1 (sdl.nodes.Firewall.UFW),isConnected56+ isConnected(13,'Firewall_1', 'DMZ_subnet_1')57# Firewall_UFW_1 (sdl.nodes.Firewall.UFW),isRouter58+ isRouter(14,'Firewall_1')59# Firewall_DefaultRoute1_1 (sdl.nodes.Configuration.DefaultRoute.Firewall.UFW),existsRoute60existsRoute(15,'Outside_subnet_1', N, 'Firewall_1') <= isConnected(ID1,X, 'Outside_subnet_1') & isRouter(ID2,X) & existsRoute(ID3,'Outside_subnet_1', N, X)61## ns_1 ##62# dns_bind_1 (sdl.nodes.Software.Server.DNS.Linux.Bind),listeningOn63+ listeningOn(16,'ns_1', 'udp', '53')64# dns_system_1 (sdl.nodes.System.Linux),isConnected65+ isConnected(17,'ns_1', 'DMZ_subnet_1')66## db_1 ##67# db_config_1 (sdl.nodes.Configuration.DBMS.Linux.MySQL.RootAllHosts),listeningOn68+ listeningOn(18,'db_1', 'tcp', '3306')69# db_cmsdb_1 (sdl.nodes.Configuration.DB.Linux.MySQL),knows70knows(19,A, 'CMS') <= knows(ID1,A, 'venerus') & hasAccount(ID2,A,H,U) & hostACL(ID3,H, 'db_1', 'tcp', '3306')71# db_system_1 (sdl.nodes.System.Linux),isConnected72+ isConnected(20,'db_1', 'Server_subnet_1')73# db_confidentialdb_1 (sdl.nodes.Configuration.DB.Linux.MySQL),knows74knows(21,A, 'DB_confidential') <= knows(ID1,A, 'venerus') & hasAccount(ID2,A,H,U) & hostACL(ID3,H, 'db_1', 'tcp', '3306')75## root-ns_1 ##76# root-ns_bind_1 (sdl.nodes.Software.Server.DNS.Linux.Bind),listeningOn77+ listeningOn(22,'root-ns_1', 'udp', '53')78# root-ns_system_1 (sdl.nodes.System.Linux),isConnected79+ isConnected(23,'root-ns_1', 'Simint1_subnet_1')80## invariant_1 ##81# invariant_1 (sdl.nodes.Invariant),existsRoute82existsRoute(24,N,M,X) <= isConnected(ID1,X,N) & isConnected(ID2,X,M) & isRouter(ID3,X)83# invariant_1 (sdl.nodes.Invariant),hostACL184hostACL(25,H,K,P,Q) <= listeningOn(ID1,K,P,Q) & isConnected(ID2,K,N) & isConnected(ID3,H,M) & isConnected(ID4,S,M) & isRouter(ID5,S) & existsRoute(ID6,T,N,S)85# invariant_1 (sdl.nodes.Invariant),hostACL286hostACL(26,H,K,P,Q) <= listeningOn(ID1,K,P,Q) & isConnected(ID2,H,N) & isConnected(ID3,K,N)87# invariant_1 (sdl.nodes.Invariant),hasAccount88hasAccount(27,A,H,U) <= hasUser(ID1,U,H,P,R) & knows(ID2,A,U) & knows(ID3,A,P)89## client_1 ##90# eve_1 (sdl.nodes.Principal),hasAccount91+ hasAccount(28,'eve_1', 'client_1','client_user1_1')92# client_user1_1 (sdl.nodes.User.Linux),hasUser93+ hasUser(29,'client_user1_1', 'client_1', 'supersecret', 'admin')94# client_system_1 (sdl.nodes.System.Linux),isConnected95+ isConnected(30,'client_1', 'Simint1_subnet_1')96## Provider_1 ##97# Provider_Route1_1 (sdl.nodes.Configuration.Route.Firewall.VyOS),existsRoute98+ existsRoute(31,'Outside_subnet_1', 'DMZ_subnet_1','Provider_1')99# Provider_Firewall_1 (sdl.nodes.Firewall.VyOS),existsRoute100+ existsRoute(32,'Extnet_subnet_1','Extnet_subnet_1','Provider_1')101# Provider_Firewall_1 (sdl.nodes.Firewall.VyOS),existsRoute102+ existsRoute(32,'Extnet_subnet_1','Outside_subnet_1','Provider_1')103# Provider_Firewall_1 (sdl.nodes.Firewall.VyOS),existsRoute104+ existsRoute(32,'Extnet_subnet_1','Simint1_subnet_1','Provider_1')105# Provider_Firewall_1 (sdl.nodes.Firewall.VyOS),existsRoute106+ existsRoute(32,'Outside_subnet_1','Extnet_subnet_1','Provider_1')107# Provider_Firewall_1 (sdl.nodes.Firewall.VyOS),existsRoute108+ existsRoute(32,'Outside_subnet_1','Outside_subnet_1','Provider_1')109# Provider_Firewall_1 (sdl.nodes.Firewall.VyOS),existsRoute110+ existsRoute(32,'Outside_subnet_1','Simint1_subnet_1','Provider_1')111# Provider_Firewall_1 (sdl.nodes.Firewall.VyOS),existsRoute112+ existsRoute(32,'Simint1_subnet_1','Extnet_subnet_1','Provider_1')113# Provider_Firewall_1 (sdl.nodes.Firewall.VyOS),existsRoute114+ existsRoute(32,'Simint1_subnet_1','Outside_subnet_1','Provider_1')115# Provider_Firewall_1 (sdl.nodes.Firewall.VyOS),existsRoute116+ existsRoute(32,'Simint1_subnet_1','Simint1_subnet_1','Provider_1')117# Provider_Firewall_1 (sdl.nodes.Firewall.VyOS),isConnected118+ isConnected(33,'Provider_1', 'Extnet_subnet_1')119# Provider_Firewall_1 (sdl.nodes.Firewall.VyOS),isConnected120+ isConnected(33,'Provider_1', 'Outside_subnet_1')121# Provider_Firewall_1 (sdl.nodes.Firewall.VyOS),isConnected122+ isConnected(33,'Provider_1', 'Simint1_subnet_1')123# Provider_Firewall_1 (sdl.nodes.Firewall.VyOS),isRouter...

Full Screen

Full Screen

statics2.py

Source:statics2.py Github

copy

Full Screen

1# Created by YongHua | 12 April 2021 23:102# Email: yht1e20@soton.ac.uk3import numpy as np4from math import pi, sin, cos, sqrt5def stress_transformation(exx, eyy, exy, theta):6 """Stress transformation for a 2-D stress tensor matrix.7 Takes four input parameters:8 `exx` >>> the exx stress component.9 `eyy` >>> the eyy stress component.10 `exy` >>> the exy stress component.11 `theta` >>> (in degrees) which is the angle of the stress element to be rotated.12 Returns `exx'`, `eyy'` and `exy'`13 * You can choose to include or omit prefixes e.g. MPa which is 1E6, as always take14 care of units and magnitudes!15 """16 # Convert to radians for the sin and cos functions17 thetar = theta / 180 * pi18 rotation_matrix = np.array([19 [cos(thetar)**2, sin(thetar)**2, sin(2*thetar)],20 [sin(thetar)**2, cos(thetar)**2, -sin(2*thetar)],21 [-cos(thetar)*sin(thetar), cos(thetar)*sin(thetar), cos(2*thetar)]22 ])23 old_stress = np.array([exx, eyy, exy])24 new_stress = np.dot(rotation_matrix, old_stress)25 return new_stress26def find_principle(exx, eyy, exy):27 """Finds the principle values `eI` and `eII` of a 2-D stress element.28 Takes three input parameters: `exx`, `eyy` and `exy`. Returns a list of29 principal stresses"""30 invariant_1 = exx + eyy # trace31 invariant_2 = exx * eyy - exy ** 2 # determinant32 eI = 0.5 * (invariant_1 + sqrt(invariant_1 ** 2 - 4 * invariant_2))33 eII = 0.5 * (invariant_1 - sqrt(invariant_1 ** 2 - 4 * invariant_2))34 return [eI, eII] # returns a list35def find_maxshear(exx, eyy, exy):36 """Find the maximum shear stress `exy` in 2-D stress element subject to37 planar rotational transformation. Numerical implementation of Mohr's circle.38 Takes three input parameters: `exx`, `eyy` and `exy`. Returns a list of39 coordinates of maximum shear stresses, in the form [centre, ±radius]"""40 eI, eII = find_principle(exx, eyy, exy)41 centre = (eI + eII) / 2 # centre of Mohr's circle, 0.5tr(e)42 radius = abs(eI - centre) # radius of Mohr's circle43 assert abs(eI - centre) == abs(eII - centre)44 maxshear = [[centre, radius], [centre, -radius]]45 return maxshear46if __name__ == '__main__':47 # example48 help(stress_transformation)49 print(stress_transformation(40, 860, 375, 30))50 help(find_principle)51 print(find_principle(-25, 75, -56))52 help(find_maxshear)...

Full Screen

Full Screen

test_prec.py

Source:test_prec.py Github

copy

Full Screen

1import torch2import numpy as np3import pickle as pkl4'''5train_mdata_, bb, invariant_1 = pkl.load(open('snapshot.pkl', 'rb'))6invariant = np.where(invariant_1)[0]7tnsr_features_ = train_mdata_._getTensorFeatures().cuda()8basis = bb.getBasisTensor()9bias = bb.getBiasTensor()10sub_basis = basis[:, :, invariant]11sub_bias = bias[:, invariant]12print('num boundaries: ', sub_bias.shape)13'''14invariant_2 = np.zeros(6452, dtype='bool')15dice = np.random.rand(6452)16invariant_2[dice < 0.01] = True17#invariant_2[invariant_1] = True18print(np.sum(invariant_2))19invariant = invariant_220tnsr_features_ = torch.rand(10808, 784).cuda().squeeze()21basis = (torch.rand(1, 784, 6452) - 0.5).cuda().squeeze()22bias = (torch.rand(1, 6452) - 0.5).cuda().squeeze()23sub_basis = basis[:, invariant]24sub_bias = bias[invariant]25print('=============================')26print(tnsr_features_.dtype, tnsr_features_.shape)27print(basis.dtype, basis.shape)28print(bias.dtype, bias.shape)29print(sub_basis.dtype, sub_basis.shape)30print(sub_bias.dtype, sub_bias.shape)31hashval = torch.mm(tnsr_features_, basis)32sub_hashval = hashval[:, invariant]33sub_config = np.zeros(sub_hashval.shape)34sub_config[sub_hashval.cpu().numpy() > 0] = 135sub_basis = basis[:, invariant]36sub_bias = bias[invariant]37new_sub_hashval = torch.mm(tnsr_features_, sub_basis)38new_sub_config = np.zeros(new_sub_hashval.shape)39new_sub_config[new_sub_hashval.cpu().numpy() > 0] = 140diff1 = np.sum(np.abs(sub_hashval.cpu().numpy() - new_sub_hashval.cpu().numpy()))41print('diff1: ', diff1)42diff2 = np.sum(np.abs(sub_config - new_sub_config))43print('diff2: ', diff2)44diff_mat = np.abs(sub_hashval.cpu().numpy() - new_sub_hashval.cpu().numpy())45print(np.amax(diff_mat))46'''47print(np.amin(sub_hashval.numpy()), np.amax(sub_hashval.numpy()))48print(np.amin(new_sub_hashval.numpy()), np.amax(new_sub_hashval.numpy()))...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run hypothesis automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful