How to use add_mpath method in avocado

Best Python code snippet using avocado_python

circuit.py

Source:circuit.py Github

copy

Full Screen

...95 "c", -13.7116, 0, -13.65, 24.9998, -27.3597, 24.9998, "m", 27.3597, -24.9998, "h", 21.8846,96 "m", 0, 0, "c", 13.7116, 0, 13.65, -24.9998, 27.3597, -24.9998, "m", -27.3597, 24.9998, "c",97 13.7116, 0, 13.65, 24.9998, 27.3597, 24.9998, "m", -89.5481, -49.9998, "h", 13, "m", 0.0019,98 49.9998, "h", -13.0019, "m", 87.6453, 0, "h", 12.3547, "m", -12.8056, -50, "h", 12.8056]99 canvas.add_mpath(path_data, stroke="black", stroke_width=1)100 canvas.add_text((25*self.get_width(compact), 38),101 content.replace('phi=', 'Φ=').replace('theta=', 'Θ='),102 7, "middle")103 def inverse(self, v=False, h=False):104 if self._phi.is_symbolic():105 if v:106 self._phi = -self._phi.spv107 if h:108 self._phi = self._phi.spv+sp.pi109 else:110 if v:111 self._phi = -float(self._phi)112 if h:113 self._phi = float(self._phi)+np.pi114class PBS(ACircuit):115 _name = "PBS"116 _fcircuit = Circuit117 _supports_polarization = True118 stroke_style = {"stroke": "black", "stroke_width": 1}119 def __init__(self):120 super().__init__(2)121 def _compute_unitary(self, assign=None, use_symbolic=False):122 self.assign(assign)123 return Matrix([[0, 0, 1, 0],124 [0, 1, 0, 0],125 [1, 0, 0, 0],126 [0, 0, 0, 1]], use_symbolic)127 def get_variables(self, map_param_kid=None):128 return {}129 # TODO: make method static130 def describe(self, _=None):131 return "phys.PBS()"132 width = 2133 def get_width(self, compact: bool = False) -> int:134 return self.width/2 if compact else self.width135 def shape(self, content, canvas, compact: bool = False):136 if compact:137 path_data1 = ["M", 0, 25.1, "h", 11.049, "m", -11.049, 50, "h", 10.9375, "m", 27.9029, -50, "h", 11.1596,138 "m", -11.3283, 50, "h", 11.3283, "m", -11.3283, 0, "c", -10.0446, 0, -17.5781, -50, -27.7341,139 -50, "m", 27.9029, 0, "c", -10.7156, 0, -17.7467, 50, -27.7914, 50]140 path_data2 = ["M", 30, 50, "l", -4.7404, -5.2543, "l", -4.7404, 5.2543, "l", 4.7404, 5.2543, "l",141 4.7404, -5.2543, "z", "m", 0.175, 0, "h", -9.6, "z"]142 else:143 path_data1 = ["M", 0, 25.1, "h", 22.0981, "m", -22.0981, 50, "h", 21.8751, "m", 55.8057, -50, "h", 22.3192,144 "m", -22.6566, 50, "h", 22.6566, "m", -22.6566, 0, "c", -20.0892, 0, -35.1561, -50, -55.4683,145 -50, "m", 55.8057, 0, "c", -21.4311, 0, -35.4935, 50, -55.5827, 50]146 path_data2 = ["M", 59, 50, "l", -9.4807, -10.5087, "l", -9.4807, 10.5087, "l", 9.4807, 10.5087, "l", 9.4807,147 -10.5087, "z", "m", 0.35, 0, "h", -19.2, "z"]148 canvas.add_mpath(path_data1, stroke_width=1, stroke="#000")149 canvas.add_mpath(path_data2, stroke_width=1, fill="#fff")150 canvas.add_text((25*self.get_width(compact), 86), text=content, size=7, ta="middle")151 def inverse(self, v=False, h=False):152 if self._phi.is_symbolic():153 if v:154 self._phi = -self._phi.spv155 if h:156 self._phi = self._phi.spv+sp.pi157 else:158 if v:159 self._phi = -float(self._phi)160 if h:161 self._phi = float(self._phi)+np.pi162class DT(ACircuit):163 _name = "DT"164 _fcircuit = Circuit165 delay_circuit = True166 stroke_style = {"stroke": "black", "stroke_width": 2}167 def __init__(self, t):168 super().__init__(1)169 self._dt = self._set_parameter("t", t, 0, sp.oo, False)170 def _compute_unitary(self, assign=None, use_symbolic=False):171 raise RuntimeError("DT circuit cannot be simulated with unitary matrix")172 def get_variables(self, map_param_kid=None):173 parameters = {}174 if map_param_kid is None:175 map_param_kid = self.map_parameters()176 self.variable_def(parameters, "t", "t", None, map_param_kid)177 return parameters178 def describe(self, map_param_kid=None):179 parameters = self.get_variables(map_param_kid)180 params_str = format_parameters(parameters, separator=', ')181 return "phys.DT(%s)" % params_str182 width = 1183 def shape(self, content, canvas, compact: bool = False):184 canvas.add_circle((34, 14), 11, stroke="white", stroke_width=3)185 canvas.add_circle((34, 14), 11, stroke="black", stroke_width=2)186 canvas.add_circle((25, 14), 11, stroke="white", stroke_width=3)187 canvas.add_circle((25, 14), 11, stroke="black", stroke_width=2)188 canvas.add_circle((16, 14), 11, stroke="white", stroke_width=3)189 canvas.add_circle((16, 14), 11, stroke="black", stroke_width=2)190 canvas.add_mline([0, 25, 17, 25], stroke="white", stroke_width=3)191 canvas.add_mline([0, 25, 19, 25], stroke="black", stroke_width=2)192 canvas.add_mline([34, 25, 50, 25], stroke="white", stroke_width=3)193 canvas.add_mline([32, 25, 50, 25], stroke="black", stroke_width=2)194 canvas.add_text((25, 38), text=content.replace("t=", ""), size=7, ta="middle")195class PS(ACircuit):196 _name = "PS"197 _fcircuit = Circuit198 stroke_style = {"stroke": "black", "stroke_width": 1}199 def __init__(self, phi):200 super().__init__(1)201 self._phi = self._set_parameter("phi", phi, 0, 2*sp.pi)202 def _compute_unitary(self, assign=None, use_symbolic=False):203 self.assign(assign)204 if use_symbolic:205 return Matrix([[sp.exp(self._phi.spv*sp.I)]], True)206 else:207 return Matrix([[np.cos(float(self._phi)) + 1j * np.sin(float(self._phi))]], False)208 def get_variables(self, map_param_kid=None):209 parameters = {}210 if map_param_kid is None:211 map_param_kid = self.map_parameters()212 self.variable_def(parameters, "phi", "phi", None, map_param_kid)213 return parameters214 def describe(self, map_param_kid=None):215 parameters = self.get_variables(map_param_kid)216 params_str = format_parameters(parameters, separator=', ')217 return "symb.PS(%s)" % params_str218 width = 1219 def shape(self, content, canvas, compact: bool = False):220 canvas.add_mpath(["M", 0, 25, "h", 20, "m", 10, 0, "h", 20], stroke="black", stroke_width=1)221 canvas.add_mpath(["M", 15, 35, "h", 20, "v", -20, "h", -20, "z"],222 stroke="black", stroke_width=1, fill="lightgray")223 canvas.add_text((25, 44), text=content.replace("phi=", "Φ="), size=7, ta="middle")224 def inverse(self, v=False, h=False):225 if h:226 if self._phi.is_symbolic():227 self._phi = -self._phi.spv228 else:229 self._phi = -float(self._phi)230class Unitary(ACircuit):231 _name = "Unitary"232 _fcircuit = Circuit233 stroke_style = {"stroke": "black", "stroke_width": 1}234 def __init__(self, U: Matrix, name: str = None, use_polarization: bool = False):235 assert U is not None, "A unitary matrix is required"236 assert U.is_unitary(), "U parameter must be a unitary matrix"237 # Even for a symb.Unitary component, a symbolic matrix is not a use case. On top of that, it slows down238 # computations quite a bit!239 assert not U.is_symbolic(), "U parameter must not be symbolic"240 self._u = U241 if name is not None:242 self._name = name243 m = U.shape[0]244 self.width = m245 self._supports_polarization = use_polarization246 if use_polarization:247 assert m % 2 == 0, "Polarization matrix should have an even number of rows/col"248 m //= 2249 super().__init__(m)250 def _compute_unitary(self, assign: dict = None, use_symbolic: bool = False) -> Matrix:251 # Ignore assign and use_symbolic parameters as __init__ checked the unitary matrix is numeric252 return self._u253 def inverse(self, v=False, h=False):254 if v:255 self._u = np.flip(self._u)256 if h:257 self._u = self._u.inv()258 def describe(self, _=None):259 params = [f"Matrix('''{self._u}''')"]260 if self._name != Unitary._name:261 params.append(f"name='{self._name}'")262 if self._supports_polarization:263 params.append("use_polarization=True")264 return f"symb.Unitary({', '.join(params)})"265 def shape(self, _, canvas, compact: bool = False):266 for i in range(self.m):267 canvas.add_mpath(["M", 0, 25 + i*50, "l", 50*self.width, 0], **self.stroke_style)268 radius = 6.25 * self.width # Radius of the rounded corners269 canvas.add_mpath(270 ["M", 0, radius, "c", 0, 0, 0, -radius, radius, -radius, "l", 6 * radius, 0, "c", radius, 0, radius, radius,271 radius, radius, "l", 0, 6 * radius, "c", 0, 0, 0, radius, -radius, radius, "l", -6 * radius, 0, "c",272 -radius, 0, -radius, -radius, -radius, -radius, "l", 0, -6 * radius],273 **self.stroke_style, fill="lightyellow")274 canvas.add_text((25*self.width, 25*self.m), size=10, ta="middle", text=self._name)275class PERM(Unitary):276 _name = "PERM"277 _fcircuit = Circuit278 stroke_style = {"stroke": "black", "stroke_width": 1}279 def __init__(self, perm):280 assert isinstance(perm, list), "permutation Operator needs list parameter"281 assert (min(perm) == 0 and282 max(perm)+1 == len(perm) == len(set(perm)) == len([n for n in perm if isinstance(n, int)])),\283 "%s is not a permutation" % perm284 n = len(perm)285 u = Matrix.zeros((n, n), use_symbolic=False)286 for i, v in enumerate(perm):287 u[v, i] = 1288 super().__init__(U=u)289 self.width = 1290 def get_variables(self, _=None):291 return {'PERM': ''}292 def describe(self, _=None):293 return "symb.PERM(%s)" % str(self._compute_perm_vector())294 def definition(self):295 return self.U296 def _compute_perm_vector(self):297 nz = np.nonzero(self._u)298 m_list = nz[1].tolist()299 return [m_list.index(i) for i in nz[0]]300 def shape(self, content, canvas, compact: bool = False):301 for an_input, an_output in enumerate(self._compute_perm_vector()):302 canvas.add_mpath(["M", 0, 24.8 + an_input * 50,303 "C", 20, 25 + an_input * 50, 30, 25 + an_output * 50, 50, 25 + an_output * 50],304 stroke="white", stroke_width=2)305 canvas.add_mpath(["M", 0, 25 + an_input * 50,306 "C", 20, 25 + an_input * 50, 30, 25 + an_output * 50, 50, 25 + an_output * 50],307 stroke="black", stroke_width=1)308class WP(ACircuit):309 _name = "WP"310 _fcircuit = Circuit311 _supports_polarization = True312 stroke_style = {"stroke": "black", "stroke_width": 1}313 def __init__(self, delta, xsi):314 super().__init__(1)315 self._delta = self._set_parameter("delta", delta, -sp.pi, sp.pi)316 self._xsi = self._set_parameter("xsi", xsi, -sp.pi, sp.pi)317 def _compute_unitary(self, assign=None, use_symbolic=False):318 self.assign(assign)319 if use_symbolic:320 delta = self._delta.spv321 xsi = self._xsi.spv322 return Matrix([[323 sp.cos(delta)+sp.I*sp.sin(delta)*sp.cos(2*xsi),324 sp.I*sp.sin(delta)*sp.sin(2*xsi)325 ], [326 sp.I * sp.sin(delta) * sp.sin(2 * xsi),327 sp.cos(delta) - sp.I * sp.sin(delta) * sp.cos(2 * xsi)328 ]], True)329 else:330 delta = float(self._delta)331 xsi = float(self._xsi)332 return Matrix([[333 np.cos(delta)+1j*np.sin(delta)*np.cos(2*xsi),334 1j*np.sin(delta)*np.sin(2*xsi)335 ], [336 1j * np.sin(delta) * np.sin(2 * xsi),337 np.cos(delta) - 1j * np.sin(delta) * np.cos(2 * xsi)338 ]], False)339 def get_variables(self, map_param_kid=None):340 parameters = {}341 if map_param_kid is None:342 map_param_kid = self.map_parameters()343 self.variable_def(parameters, "xsi", "xsi", None, map_param_kid)344 self.variable_def(parameters, "delta", "delta", None, map_param_kid)345 return parameters346 def describe(self, map_param_kid=None):347 parameters = self.get_variables(map_param_kid)348 params_str = format_parameters(parameters, separator=', ')349 return "phys.WP(%s)" % params_str350 width = 1351 def shape(self, content, canvas, compact: bool = False):352 params = content.replace("xsi=", "ξ=").replace("delta=", "δ=").split("\n")353 canvas.add_mpath(["M", 0, 25, "h", 15, "m", 21, 0, "h", 15], stroke="black", stroke_width=1)354 canvas.add_mpath(["M", 15, 45, "h", 21, "v", -40, "h", -21, "z"], stroke="black", stroke_width=1)355 canvas.add_text((25, 55), text=params[0], size=7, ta="middle")356 canvas.add_text((25, 65), text=params[1], size=7, ta="middle")357class HWP(WP):358 _name = "HWP"359 def __init__(self, xsi):360 super().__init__(sp.pi/2, xsi)361 def shape(self, content, canvas, compact: bool = False):362 params = content.replace("xsi=", "ξ=").replace("delta=", "δ=").split("\n")363 canvas.add_mpath(["M", 0, 25, "v", 0, "h", 0, "h", 50],stroke="black", stroke_width=1)364 canvas.add_mpath(["M", 20, 0, "v", 50], stroke="black", stroke_width=2)365 canvas.add_mpath(["M", 30, 0, "v", 50], stroke="black", stroke_width=2)366 canvas.add_text((25, 60), text=params[0], size=7, ta="middle")367class QWP(WP):368 _name = "QWP"369 def __init__(self, xsi):370 super().__init__(sp.pi/4, xsi)371 def shape(self, content, canvas, compact: bool = False):372 params = content.replace("xsi=", "ξ=").replace("delta=", "δ=").split("\n")373 canvas.add_mpath(["M", 0, 25, "v", 0, "h", 0, "h", 50], stroke="black", stroke_width=1)374 canvas.add_mpath(["M", 25, 0, "v", 50], stroke="black", stroke_width=2)375 canvas.add_text((25, 60), text=params[0], size=7, ta="middle")376class PR(ACircuit):377 """Polarization rotator"""378 _name = "PR"379 _fcircuit = Circuit380 _supports_polarization = True381 stroke_style = {"stroke": "black", "stroke_width": 1}382 def __init__(self, delta):383 super().__init__(1)384 self._delta = self._set_parameter("delta", delta, -sp.pi, sp.pi)385 def _compute_unitary(self, assign=None, use_symbolic=False):386 self.assign(assign)387 if use_symbolic:388 delta = self._delta.spv389 return Matrix([[sp.cos(delta), sp.sin(delta)],390 [-sp.sin(delta), sp.cos(delta)]], True)391 else:392 delta = float(self._delta)393 return Matrix([[np.cos(delta), np.sin(delta)],394 [-np.sin(delta), np.cos(delta)]], False)395 def get_variables(self, map_param_kid=None):396 parameters = {}397 if map_param_kid is None:398 map_param_kid = self.map_parameters()399 self.variable_def(parameters, "delta", "delta", None, map_param_kid)400 return parameters401 def describe(self, map_param_kid=None):402 parameters = self.get_variables(map_param_kid)403 params_str = format_parameters(parameters, separator=', ')404 return "phys.PR(%s)" % params_str405 width = 1406 def shape(self, content, canvas, compact: bool = False):407 canvas.add_mpath(["M", 0, 25, "h", 15, "m", 22, 0, "h", 15], stroke="black", stroke_width=1)408 canvas.add_mpath(["M", 15, 36, "h", 22, "v", -22, "h", -22, "z"], stroke="black", stroke_width=1)409 canvas.add_mpath(["M", 19, 27, "c", 0.107, 0.131, 0.280, 0.131, 0.387, 0,410 "l", 2.305, -2.821, "c", 0.107, -0.131, 0.057, -0.237, -0.112, -0.237,411 "h", -1.22, "c", -0.169, 0, -0.284, -0.135, -0.247, -0.300,412 "c", 0.629, -2.866, 3.187, -5.018, 6.240, -5.018,413 "c", 3.524, 0, 6.39, 2.867, 6.390, 6.3902,414 "c", 0, 3.523, -2.866, 6.39, -6.390, 6.390,415 "c", -0.422, 0, -0.765, 0.342, -0.765, 0.765,416 "s", 0.342, 0.765, 0.765, 0.765,417 "c", 4.367, 0, 7.92, -3.552, 7.920, -7.920,418 "c", 0, -4.367, -3.552, -7.920, -7.920, -7.920,419 "c", -3.898, 0, -7.146, 2.832, -7.799, 6.546,420 "c", -0.029, 0.166, -0.184, 0.302, -0.353, 0.302,421 "H", 17, "c", -0.169, 0, -0.219, 0.106, -0.112, 0.237,422 "z"423 ], fill="black",stroke_width=0.1)...

Full Screen

Full Screen

mplot_renderer.py

Source:mplot_renderer.py Github

copy

Full Screen

...43 stroke_dasharray=None):44 mpath = ["M", points[0], points[1]]45 for n in range(2, len(points), 2):46 mpath += ["L", points[n], points[n+1]]47 self.add_mpath(mpath, stroke=stroke, stroke_width=stroke_width, stroke_linejoin=stroke_linejoin)48 def add_polygon(self, points, stroke="black", stroke_width=1, fill=None, stroke_linejoin="miter",49 stroke_dasharray=None):50 points = super().add_polygon(points, stroke, stroke_width, fill)51 self._patches.append(52 mpatches.Polygon([(points[n], points[n+1]) for n in range(0, len(points), 2)],53 fill=fill is not None, color=fill,54 ec=stroke, linewidth=stroke_width, joinstyle=stroke_linejoin))55 def add_mpath(self, points, stroke="black", stroke_width=1, fill=None, stroke_linejoin="miter",56 stroke_dasharray=None):57 points = super().add_mpath(points, stroke, stroke_width, fill)58 path_data = []59 while points:60 if points[0] == "M":61 path_data.append((mpath.Path.MOVETO, [points[1], points[2]]))62 points = points[3:]63 elif points[0] == "L":64 path_data.append((mpath.Path.LINETO, [points[1], points[2]]))65 points = points[3:]66 elif points[0] == "C":67 path_data.append((mpath.Path.CURVE4, [points[1], points[2]]))68 path_data.append((mpath.Path.CURVE4, [points[3], points[4]]))69 path_data.append((mpath.Path.CURVE4, [points[5], points[6]]))70 points = points[7:]71 elif points[0] == "S":...

Full Screen

Full Screen

shapes.py

Source:shapes.py Github

copy

Full Screen

...23 r = 1024 color = "lightgray"25 if 'color' in opts:26 color = opts['color']27 canvas.add_mpath(["M", 0, 25, "c", 0, 0, 0, -r, r, -r,28 "h", 8, "v", 2*r, "h", -8,29 "c", -r, 0, -r, -r, -r, -r, "z"],30 stroke="black", stroke_width=1, fill=color)31 if 'name' in opts and opts['name']:32 canvas.add_text((8, 44), text='['+opts['name']+']', size=6, ta="middle", fontstyle="italic")33 if 'content' in opts and opts['content']:34 canvas.add_text((10, 28), text=opts['content'], size=7, ta="middle")35def detector_shape(canvas, **opts):36 r = 10 # Radius of the half-circle37 color = "lightgray"38 if 'color' in opts:39 color = opts['color']40 canvas.add_mpath(["M", 20, 35, "h", -8, "v", -2*r, "h", 8,41 "c", 0, 0, r, 0, r, r,42 "c", 0, r, -r, r, -r, r, "z"],43 stroke="black", stroke_width=1, fill=color)44 if 'name' in opts:45 canvas.add_text((18, 44), text='['+opts['name']+']', size=6, ta="middle", fontstyle="italic")46 if 'content' in opts:...

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 avocado 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