How to use set_pa method in fMBT

Best Python code snippet using fMBT_python

blochSphere.py

Source:blochSphere.py Github

copy

Full Screen

...41 if not(-np.pi <= phi <= np.pi):42 phi = phi%(2*np.pi) - 2*np.pi43 self.a = np.cos(theta/2) #já está com a fase zerada44 self.b = np.sin(theta/2)*np.exp(1j*phi)45 def set_pa(self, a, b):46 # assign values to a, b47 aux = np.abs(a)**2 + np.abs(b)**248 self.a = np.sqrt(np.abs(a)**2/aux)49 self.b = np.sqrt(np.abs(b)**2/aux)*(b/np.abs(b))*(np.abs(a)/a)50 def set_wf(self, colvec):51 # from column vector, assign values to a, b52 a = colvec[0,0]53 b = colvec[1,0]54 self.set_pa(a, b)55 @staticmethod56 def plot(*args, **kwargs):57 def repel_from_center(x, y, z, m=0.1):58 return x + (-m if x < 0 else m), \59 y + (-m if y < 0 else m), \60 z + (-m if z < 0 else m)61 def bloch_sphere():62 fig = plt.figure()63 ax = fig.add_subplot(111, projection='3d')64 u = np.linspace(0, 2*np.pi, 30)65 v = np.linspace(0, np.pi, 20)66 x = 1 * np.outer(np.cos(u), np.sin(v))67 y = 1 * np.outer(np.sin(u), np.sin(v))68 z = 1 * np.outer(np.ones(np.size(u)), np.cos(v))69 ax.plot_wireframe(x, y, z, color='gray', linestyle=':')70 ax.plot3D([-1, 1], [0, 0], [0, 0], color='k', linestyle='--')71 ax.text(-1.1, 0, 0, '$|-\\rangle$', 'x', horizontalalignment='right', \72 fontweight='bold', fontsize=11)73 ax.text(1.1, 0, 0, '$|+\\rangle$', 'x', horizontalalignment='left', \74 fontweight='bold', fontsize=11)75 ax.plot3D([0, 0], [-1, 1], [0, 0], color='k', linestyle='--')76 ax.text(0, -1.1, 0, '$|-i\\rangle$', 'y', horizontalalignment='right', \77 fontweight='bold', fontsize=11)78 ax.text(0, 1.1, 0, '$|i\\rangle$', 'y', horizontalalignment='left', \79 fontweight='bold', fontsize=11)80 ax.plot3D([0, 0], [0, 0], [-1, 1], color='k', linestyle='--')81 ax.text(0, 0, -1.1, '$|1\\rangle$', 'x', horizontalalignment='center', \82 fontweight='bold', fontsize=11)83 ax.text(0, 0, 1.1, '$|0\\rangle$', 'x', horizontalalignment='center', \84 fontweight='bold', fontsize=11)85 limits = np.array([getattr(ax, f'get_{axis}lim')() \86 for axis in 'xyz'])87 ax.set_box_aspect(np.ptp(limits, axis = 1))88 ax._axis3don = False89 return ax90 if kwargs.get('title', False):91 title = kwargs['title']92 else:93 title = ''94 ax = bloch_sphere()95 for arg in args:96 label, color = '| ', 'r'97 if type(arg) == tuple:98 if len(arg) == 3: color = arg[2]99 label = '$|' + arg[1] + '\\rangle$'100 arg = arg[0]101 ax.quiver(0, 0, 0, arg.x, arg.y, arg.z, color=color)102 ax.text(*repel_from_center(arg.x, arg.y, arg.z), label, 'x', \103 horizontalalignment='center', fontweight='bold', fontsize=11, \104 color=color)105 plt.title(title)106 plt.show()107# lines to run just when this script is running, if there's another script importing a qubit from the original script, this snippet won't run108if __name__ == "__main__":109 q = Qubit()110 print(q)111 # q.set_bs(50*2*np.pi+3/2*np.pi, 50*2*np.pi+3/2*np.pi)112 # q.set_pa(-1j*np.sqrt(2)/2, (np.sqrt(2)/2))113 q.set_pa(np.sqrt(25), np.sqrt(75))114 # print(q.a, q.b)115 # print(np.sqrt(2)/2, 1j*np.sqrt(2)/2)...

Full Screen

Full Screen

qubit.py

Source:qubit.py Github

copy

Full Screen

...34 if(not(-np.pi <= phi <= np.pi)):35 phi = phi%(2*np.pi) - 2*np.pi36 self.theta = theta37 self.phi = phi38 def set_pa(self, a, b):39 aux = np.abs(a)**2 + np.abs(b)**240 a = np.sqrt(abs(a)**2/aux)41 b = np.sqrt(abs(b)**2/aux)42 ma, pa = np.abs(a), np.angle(a)43 mb, pb = np.abs(b), np.angle(b)44 self.a = ma45 self.b = mb*np.exp(1j*(pb-pa))46 # def validate(self):47 # if(np.sqrt(np.abs(self.a)**2 + np.abs(self.b)**2) < 1):48if __name__ == "__main__":49 q = Qubit()50 print(q)51 q.set_bs(50*2*np.pi+3/2*np.pi, 50*2*np.pi+3/2*np.pi)52 q.set_pa(np.sqrt(2)/2, -1j*(np.sqrt(2)/2))53 print(q.a, q.b)...

Full Screen

Full Screen

neuronlib.py

Source:neuronlib.py Github

copy

Full Screen

...8 x = []9 for i in range(n_inp):10 x.append(1)11 return x12 def set_pa(self, inputs):13 pa = 014 for i in range(len(inputs)):15 pa += inputs[i] * self.weights[i]16 pa += self.bias17 return pa18 def learn(self, inputs, target, to_print=False):19 out, pa = self.output(inputs)20 diff = out - target21 cost = (out - target) ** 222 if to_print:23 print('input:', inputs, 'target:', target, 'Predizione:', out, 'Costo:', cost)24 for i, w in enumerate(self.weights):25 self.weights[i] -= self.lr * 2 * diff * inputs[i] * self.sigmoide(pa, deriv=True)26 self.bias -= self.lr * 2 * diff * self.sigmoide(pa, deriv=True)27 return out28 def output(self, inputs):29 pa = self.set_pa(inputs)30 return self.sigmoide(pa), pa31 def sigmoide(self, pa, deriv=False):32 if not deriv:33 return 1 / (1 + math.exp(-pa))34 else:...

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