How to use Header method in argos

Best JavaScript code snippet using argos

testCQCMessages.py

Source:testCQCMessages.py Github

copy

Full Screen

1#2# Copyright (c) 2018, Stephanie Wehner and Axel Dahlberg3# All rights reserved.4#5# Redistribution and use in source and binary forms, with or without6# modification, are permitted provided that the following conditions are met:7# 1. Redistributions of source code must retain the above copyright8# notice, this list of conditions and the following disclaimer.9# 2. Redistributions in binary form must reproduce the above copyright10# notice, this list of conditions and the following disclaimer in the11# documentation and/or other materials provided with the distribution.12# 3. All advertising materials mentioning features or use of this software13# must display the following acknowledgement:14# This product includes software developed by Stephanie Wehner, QuTech.15# 4. Neither the name of the QuTech organization nor the16# names of its contributors may be used to endorse or promote products17# derived from this software without specific prior written permission.18#19# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER ''AS IS'' AND ANY20# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED21# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE22# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY23# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES24# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;25# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND26# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT27# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS28# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.29import json30import unittest31import os32from SimulaQron.cqc.backend.cqcLogMessageHandler import CQCLogMessageHandler33from SimulaQron.cqc.pythonLib.cqc import CQCConnection, qubit, CQCUnsuppError, QubitNotActiveError34from SimulaQron.cqc.backend.cqcHeader import (35 CQCCmdHeader,36 CQC_CMD_SEND,37 CQC_CMD_EPR,38 CQC_CMD_CNOT,39 CQC_CMD_CPHASE,40 CQC_CMD_ROT_X,41 CQC_CMD_ROT_Y,42 CQC_CMD_ROT_Z,43 CQC_TP_COMMAND,44 CQC_TP_FACTORY,45 CQC_CMD_I,46 CQC_CMD_X,47 CQC_CMD_Y,48 CQC_CMD_Z,49 CQC_CMD_T,50 CQC_CMD_H,51 CQC_CMD_K,52 CQC_CMD_NEW,53 CQC_CMD_MEASURE,54 CQC_CMD_MEASURE_INPLACE,55 CQC_CMD_RESET,56 CQC_CMD_RECV,57 CQC_CMD_EPR_RECV,58 CQC_CMD_ALLOCATE,59 CQC_CMD_RELEASE,60 CQCCommunicationHeader,61 CQCXtraQubitHeader,62 CQCRotationHeader,63 CQCFactoryHeader,64 CQC_CMD_HDR_LENGTH,65)66def get_last_entries(amount):67 file = "{}/logFile.json".format(CQCLogMessageHandler.dir_path)68 with open(file, "r") as outfile:69 logData = json.load(outfile)70 return logData[-amount:]71class CQCMessageTest(unittest.TestCase):72 # Only tests cqc_commands at the moment.73 # So no messages that are send back (notifications)74 @classmethod75 def setUpClass(cls):76 try:77 os.remove("{}/logFile.json".format(CQCLogMessageHandler.dir_path))78 except OSError:79 pass80 @classmethod81 def tearDownClass(cls):82 try:83 os.remove("{}/logFile.json".format(CQCLogMessageHandler.dir_path))84 except OSError:85 pass86 def testNewQubit(self):87 with CQCConnection("Alice", appID=1) as alice:88 qubit(alice, block=False, notify=False)89 lastEntry = get_last_entries(1)[0]90 cmd_header = lastEntry["cmd_header"]91 self.assertEqual(lastEntry["node_name"], "Alice")92 self.assertEqual(cmd_header["instruction"], CQC_CMD_NEW)93 self.assertEqual(cmd_header["block"], False)94 self.assertEqual(cmd_header["notify"], False)95 cqc_header = lastEntry["cqc_header"]96 self.assertEqual(cqc_header["type"], CQC_TP_COMMAND)97 self.assertEqual(cqc_header["header_length"], CQC_CMD_HDR_LENGTH)98 self.assertEqual(cqc_header["app_id"], 1)99 def testI(self):100 with CQCConnection("Alice", appID=1) as alice:101 q1 = qubit(alice)102 q1.I()103 lastEntry = get_last_entries(1)[0]104 self.assertEqual(lastEntry["node_name"], "Alice")105 cmd_header = lastEntry["cmd_header"]106 self.assertEqual(cmd_header["instruction"], CQC_CMD_I)107 self.assertEqual(cmd_header["block"], True)108 self.assertEqual(cmd_header["notify"], True)109 cqc_header = lastEntry["cqc_header"]110 self.assertEqual(cqc_header["type"], CQC_TP_COMMAND)111 self.assertEqual(cqc_header["header_length"], CQC_CMD_HDR_LENGTH)112 self.assertEqual(cqc_header["app_id"], 1)113 def testX(self):114 with CQCConnection("Alice", appID=1) as alice:115 q1 = qubit(alice)116 q1.X()117 lastEntry = get_last_entries(1)[0]118 self.assertEqual(lastEntry["node_name"], "Alice")119 cmd_header = lastEntry["cmd_header"]120 self.assertEqual(cmd_header["instruction"], CQC_CMD_X)121 self.assertEqual(cmd_header["block"], True)122 self.assertEqual(cmd_header["notify"], True)123 cqc_header = lastEntry["cqc_header"]124 self.assertEqual(cqc_header["type"], CQC_TP_COMMAND)125 self.assertEqual(cqc_header["header_length"], CQC_CMD_HDR_LENGTH)126 self.assertEqual(cqc_header["app_id"], 1)127 def testY(self):128 with CQCConnection("Alice", appID=1) as alice:129 q1 = qubit(alice)130 q1.Y()131 lastEntry = get_last_entries(1)[0]132 self.assertEqual(lastEntry["node_name"], "Alice")133 cmd_header = lastEntry["cmd_header"]134 self.assertEqual(cmd_header["instruction"], CQC_CMD_Y)135 self.assertEqual(cmd_header["block"], True)136 self.assertEqual(cmd_header["notify"], True)137 cqc_header = lastEntry["cqc_header"]138 self.assertEqual(cqc_header["type"], CQC_TP_COMMAND)139 self.assertEqual(cqc_header["header_length"], CQC_CMD_HDR_LENGTH)140 self.assertEqual(cqc_header["app_id"], 1)141 def testZ(self):142 with CQCConnection("Alice", appID=1) as alice:143 q1 = qubit(alice)144 q1.Z()145 lastEntry = get_last_entries(1)[0]146 self.assertEqual(lastEntry["node_name"], "Alice")147 cmd_header = lastEntry["cmd_header"]148 self.assertEqual(cmd_header["instruction"], CQC_CMD_Z)149 self.assertEqual(cmd_header["block"], True)150 self.assertEqual(cmd_header["notify"], True)151 cqc_header = lastEntry["cqc_header"]152 self.assertEqual(cqc_header["type"], CQC_TP_COMMAND)153 self.assertEqual(cqc_header["header_length"], CQC_CMD_HDR_LENGTH)154 self.assertEqual(cqc_header["app_id"], 1)155 def testH(self):156 with CQCConnection("Alice", appID=1) as alice:157 q1 = qubit(alice)158 q1.H()159 lastEntry = get_last_entries(1)[0]160 self.assertEqual(lastEntry["node_name"], "Alice")161 cmd_header = lastEntry["cmd_header"]162 self.assertEqual(cmd_header["instruction"], CQC_CMD_H)163 self.assertEqual(cmd_header["block"], True)164 self.assertEqual(cmd_header["notify"], True)165 cqc_header = lastEntry["cqc_header"]166 self.assertEqual(cqc_header["type"], CQC_TP_COMMAND)167 self.assertEqual(cqc_header["header_length"], CQC_CMD_HDR_LENGTH)168 self.assertEqual(cqc_header["app_id"], 1)169 def testT(self):170 with CQCConnection("Alice", appID=1) as alice:171 q1 = qubit(alice)172 q1.T()173 lastEntry = get_last_entries(1)[0]174 self.assertEqual(lastEntry["node_name"], "Alice")175 cmd_header = lastEntry["cmd_header"]176 self.assertEqual(cmd_header["instruction"], CQC_CMD_T)177 self.assertEqual(cmd_header["block"], True)178 self.assertEqual(cmd_header["notify"], True)179 cqc_header = lastEntry["cqc_header"]180 self.assertEqual(cqc_header["type"], CQC_TP_COMMAND)181 self.assertEqual(cqc_header["header_length"], CQC_CMD_HDR_LENGTH)182 self.assertEqual(cqc_header["app_id"], 1)183 def testK(self):184 with CQCConnection("Alice", appID=1) as alice:185 q1 = qubit(alice)186 q1.K()187 lastEntry = get_last_entries(1)[0]188 self.assertEqual(lastEntry["node_name"], "Alice")189 cmd_header = lastEntry["cmd_header"]190 self.assertEqual(cmd_header["instruction"], CQC_CMD_K)191 self.assertEqual(cmd_header["block"], True)192 self.assertEqual(cmd_header["notify"], True)193 cqc_header = lastEntry["cqc_header"]194 self.assertEqual(cqc_header["type"], CQC_TP_COMMAND)195 self.assertEqual(cqc_header["header_length"], CQC_CMD_HDR_LENGTH)196 self.assertEqual(cqc_header["app_id"], 1)197 def testRotX(self):198 with CQCConnection("Alice", appID=1) as alice:199 q1 = qubit(alice)200 q1.rot_X(200)201 lastEntry = get_last_entries(1)[0]202 self.assertEqual(lastEntry["node_name"], "Alice")203 cmd_header = lastEntry["cmd_header"]204 self.assertEqual(cmd_header["instruction"], CQC_CMD_ROT_X)205 self.assertEqual(cmd_header["block"], True)206 self.assertEqual(cmd_header["notify"], True)207 cqc_header = lastEntry["cqc_header"]208 self.assertEqual(cqc_header["type"], CQC_TP_COMMAND)209 self.assertEqual(cqc_header["header_length"], CQC_CMD_HDR_LENGTH + CQCRotationHeader.HDR_LENGTH)210 self.assertEqual(cqc_header["app_id"], 1)211 xtra_header = lastEntry["xtra_header"]212 self.assertEqual(xtra_header["step"], 200)213 def testRotY(self):214 with CQCConnection("Alice", appID=1) as alice:215 q1 = qubit(alice)216 q1.rot_Y(200)217 lastEntry = get_last_entries(1)[0]218 self.assertEqual(lastEntry["node_name"], "Alice")219 cmd_header = lastEntry["cmd_header"]220 self.assertEqual(cmd_header["instruction"], CQC_CMD_ROT_Y)221 self.assertEqual(cmd_header["block"], True)222 self.assertEqual(cmd_header["notify"], True)223 cqc_header = lastEntry["cqc_header"]224 self.assertEqual(cqc_header["type"], CQC_TP_COMMAND)225 self.assertEqual(cqc_header["header_length"], CQC_CMD_HDR_LENGTH + CQCRotationHeader.HDR_LENGTH)226 self.assertEqual(cqc_header["app_id"], 1)227 xtra_header = lastEntry["xtra_header"]228 self.assertEqual(xtra_header["step"], 200)229 def testRotZ(self):230 with CQCConnection("Alice", appID=1) as alice:231 q1 = qubit(alice)232 q1.rot_Z(200)233 lastEntry = get_last_entries(1)[0]234 self.assertEqual(lastEntry["node_name"], "Alice")235 cmd_header = lastEntry["cmd_header"]236 self.assertEqual(cmd_header["instruction"], CQC_CMD_ROT_Z)237 self.assertEqual(cmd_header["block"], True)238 self.assertEqual(cmd_header["notify"], True)239 cqc_header = lastEntry["cqc_header"]240 self.assertEqual(cqc_header["type"], CQC_TP_COMMAND)241 self.assertEqual(cqc_header["header_length"], CQC_CMD_HDR_LENGTH + CQCRotationHeader.HDR_LENGTH)242 self.assertEqual(cqc_header["app_id"], 1)243 xtra_header = lastEntry["xtra_header"]244 self.assertEqual(xtra_header["step"], 200)245 def testRotXFail(self):246 with CQCConnection("Alice", appID=1) as alice:247 q1 = qubit(alice)248 with self.assertRaises(ValueError):249 q1.rot_X(256)250 def testRotXFailNone(self):251 with CQCConnection("Alice", appID=1) as alice:252 q1 = qubit(alice)253 with self.assertRaises(ValueError):254 q1.rot_X(None)255 def testRotXFailNaN(self):256 with CQCConnection("Alice", appID=1) as alice:257 q1 = qubit(alice)258 with self.assertRaises(ValueError):259 q1.rot_X("four")260 def testRotXFailNegative(self):261 with CQCConnection("Alice", appID=1) as alice:262 q1 = qubit(alice)263 with self.assertRaises(ValueError):264 q1.rot_X(-1)265 def testRotXFailFloat(self):266 with CQCConnection("Alice", appID=1) as alice:267 q1 = qubit(alice)268 with self.assertRaises(ValueError):269 q1.rot_X(1.1)270 def testCNot(self):271 with CQCConnection("Alice", appID=1) as alice:272 q1 = qubit(alice)273 q2 = qubit(alice)274 q1.cnot(q2)275 lastEntry = get_last_entries(1)[0]276 self.assertEqual(lastEntry["node_name"], "Alice")277 cmd_header = lastEntry["cmd_header"]278 self.assertEqual(cmd_header["instruction"], CQC_CMD_CNOT)279 self.assertEqual(cmd_header["block"], True)280 self.assertEqual(cmd_header["notify"], True)281 cqc_header = lastEntry["cqc_header"]282 self.assertEqual(cqc_header["type"], CQC_TP_COMMAND)283 self.assertEqual(cqc_header["header_length"], CQC_CMD_HDR_LENGTH + CQCXtraQubitHeader.HDR_LENGTH)284 self.assertEqual(cqc_header["app_id"], 1)285 xtra_header = lastEntry["xtra_header"]286 self.assertEqual(xtra_header["qubit_id"], cmd_header["qubit_id"] + 1)287 def testCNotRemote(self):288 with CQCConnection("Alice", appID=1) as alice:289 # The appId in xtra_header['app_id'] is not 2 when testing.290 # In fact, doing this code in a real application result in an error as of 2018-03-12291 with CQCConnection("Bob", appID=2) as bob:292 q1 = qubit(alice)293 q2 = qubit(bob)294 with self.assertRaises(CQCUnsuppError):295 q1.cnot(q2)296 def testCPhase(self):297 with CQCConnection("Alice", appID=1) as alice:298 q1 = qubit(alice)299 q2 = qubit(alice)300 q1.cphase(q2)301 lastEntry = get_last_entries(1)[0]302 self.assertEqual(lastEntry["node_name"], "Alice")303 cmd_header = lastEntry["cmd_header"]304 self.assertEqual(cmd_header["instruction"], CQC_CMD_CPHASE)305 self.assertEqual(cmd_header["block"], True)306 self.assertEqual(cmd_header["notify"], True)307 cqc_header = lastEntry["cqc_header"]308 self.assertEqual(cqc_header["type"], CQC_TP_COMMAND)309 self.assertEqual(cqc_header["header_length"], CQC_CMD_HDR_LENGTH + CQCXtraQubitHeader.HDR_LENGTH)310 self.assertEqual(cqc_header["app_id"], 1)311 xtra_header = lastEntry["xtra_header"]312 self.assertEqual(xtra_header["qubit_id"], cmd_header["qubit_id"] + 1)313 def testSend(self):314 with CQCConnection("Alice", appID=1) as alice:315 q1 = qubit(alice)316 alice.sendQubit(q1, "Bob", remote_appID=2)317 lastEntry = get_last_entries(1)[0]318 self.assertEqual(lastEntry["node_name"], "Alice")319 cmd_header = lastEntry["cmd_header"]320 self.assertEqual(cmd_header["instruction"], CQC_CMD_SEND)321 self.assertEqual(cmd_header["block"], True)322 self.assertEqual(cmd_header["notify"], True)323 cqc_header = lastEntry["cqc_header"]324 self.assertEqual(cqc_header["type"], CQC_TP_COMMAND)325 self.assertEqual(cqc_header["header_length"], CQC_CMD_HDR_LENGTH + CQCCommunicationHeader.HDR_LENGTH)326 self.assertEqual(cqc_header["app_id"], 1)327 xtra_header = lastEntry["xtra_header"]328 self.assertEqual(xtra_header["remote_app_id"], 2)329 self.assertNotEqual(xtra_header["remote_node"], 0)330 self.assertNotEqual(xtra_header["remote_port"], 0)331 def testSendSelf(self):332 with CQCConnection("Alice", appID=1) as alice:333 # Should not work in a real application334 q1 = qubit(alice)335 alice.sendQubit(q1, "Alice", remote_appID=1)336 lastEntry = get_last_entries(1)[0]337 self.assertEqual(lastEntry["node_name"], "Alice")338 cmd_header = lastEntry["cmd_header"]339 self.assertEqual(cmd_header["instruction"], CQC_CMD_SEND)340 self.assertEqual(cmd_header["block"], True)341 self.assertEqual(cmd_header["notify"], True)342 cqc_header = lastEntry["cqc_header"]343 self.assertEqual(cqc_header["type"], CQC_TP_COMMAND)344 self.assertEqual(cqc_header["header_length"], CQC_CMD_HDR_LENGTH + CQCCommunicationHeader.HDR_LENGTH)345 self.assertEqual(cqc_header["app_id"], 1)346 xtra_header = lastEntry["xtra_header"]347 self.assertEqual(xtra_header["remote_app_id"], 1)348 self.assertNotEqual(xtra_header["remote_node"], 0)349 self.assertNotEqual(xtra_header["remote_port"], 0)350 def testRecv(self):351 with CQCConnection("Alice", appID=1) as alice:352 alice.recvQubit()353 lastEntry = get_last_entries(1)[0]354 self.assertEqual(lastEntry["node_name"], "Alice")355 cmd_header = lastEntry["cmd_header"]356 self.assertEqual(cmd_header["instruction"], CQC_CMD_RECV)357 self.assertEqual(cmd_header["block"], True)358 self.assertEqual(cmd_header["notify"], True)359 cqc_header = lastEntry["cqc_header"]360 self.assertEqual(cqc_header["type"], CQC_TP_COMMAND)361 self.assertEqual(cqc_header["header_length"], CQC_CMD_HDR_LENGTH)362 self.assertEqual(cqc_header["app_id"], 1)363 def testEPRSend(self):364 with CQCConnection("Alice", appID=1) as alice:365 alice.createEPR("Bob", remote_appID=2)366 entries = get_last_entries(5)367 cmd_header_epr = entries[0]["cmd_header"]368 self.assertEqual(entries[0]["node_name"], "Alice")369 self.assertEqual(cmd_header_epr["instruction"], CQC_CMD_EPR)370 self.assertEqual(cmd_header_epr["block"], True)371 self.assertEqual(cmd_header_epr["notify"], True)372 cqc_header_epr = entries[0]["cqc_header"]373 self.assertEqual(cqc_header_epr["type"], CQC_TP_COMMAND)374 for i in range(5):375 self.assertEqual(376 entries[i]["cqc_header"]["header_length"], CQC_CMD_HDR_LENGTH + CQCCommunicationHeader.HDR_LENGTH377 )378 self.assertEqual(cqc_header_epr["app_id"], 1)379 xtra_header_epr = entries[0]["xtra_header"]380 self.assertEqual(xtra_header_epr["remote_app_id"], 2)381 self.assertNotEqual(xtra_header_epr["remote_node"], 0)382 self.assertNotEqual(xtra_header_epr["remote_port"], 0)383 # Check if the qubits are created correctly384 # The protocol already knows what do to on EPR, so no new headers are made,385 # This means that the header of createEPR() is send into new(),386 # New headers have to be made for H() and CNOT() for the qubit ids,387 # but the instruction is not needed, defaults to 0388 self.assertEqual(entries[1]["cmd_header"]["instruction"], CQC_CMD_EPR)389 self.assertEqual(entries[3]["cmd_header"]["instruction"], 0)390 self.assertEqual(entries[4]["cmd_header"]["instruction"], 0)391 self.assertEqual(entries[4]["cmd_header"]["qubit_id"] + 1, entries[4]["xtra_header"]["qubit_id"])392 def testEPRRecv(self):393 with CQCConnection("Alice", appID=1) as alice:394 alice.recvEPR()395 lastEntry = get_last_entries(1)[0]396 self.assertEqual(lastEntry["node_name"], "Alice")397 cmd_header = lastEntry["cmd_header"]398 self.assertEqual(cmd_header["instruction"], CQC_CMD_EPR_RECV)399 self.assertEqual(cmd_header["block"], True)400 self.assertEqual(cmd_header["notify"], True)401 cqc_header = lastEntry["cqc_header"]402 self.assertEqual(cqc_header["type"], CQC_TP_COMMAND)403 self.assertEqual(cqc_header["header_length"], CQC_CMD_HDR_LENGTH)404 self.assertEqual(cqc_header["app_id"], 1)405 def testMeasure(self):406 with CQCConnection("Alice", appID=1) as alice:407 q1 = qubit(alice)408 m1 = q1.measure()409 # We've set that for this testing purposes, the measurement outcome is410 # always 2411 self.assertEqual(m1, 2)412 lastEntry = get_last_entries(1)[0]413 self.assertEqual(lastEntry["node_name"], "Alice")414 cmd_header = lastEntry["cmd_header"]415 self.assertEqual(cmd_header["instruction"], CQC_CMD_MEASURE)416 self.assertEqual(cmd_header["block"], True)417 self.assertEqual(cmd_header["notify"], False)418 cqc_header = lastEntry["cqc_header"]419 self.assertEqual(cqc_header["type"], CQC_TP_COMMAND)420 self.assertEqual(cqc_header["header_length"], CQC_CMD_HDR_LENGTH)421 self.assertEqual(cqc_header["app_id"], 1)422 self.assertFalse(q1._active)423 def testMeasureInplace(self):424 with CQCConnection("Alice", appID=1) as alice:425 q1 = qubit(alice)426 m1 = q1.measure(inplace=True)427 # We've set that for this testing purposes, the measurement outcome is428 # always 2429 self.assertEqual(m1, 2)430 lastEntry = get_last_entries(1)[0]431 self.assertEqual(lastEntry["node_name"], "Alice")432 cmd_header = lastEntry["cmd_header"]433 self.assertEqual(cmd_header["instruction"], CQC_CMD_MEASURE_INPLACE)434 self.assertEqual(cmd_header["block"], True)435 self.assertEqual(cmd_header["notify"], False)436 cqc_header = lastEntry["cqc_header"]437 self.assertEqual(cqc_header["type"], CQC_TP_COMMAND)438 self.assertEqual(cqc_header["header_length"], CQC_CMD_HDR_LENGTH)439 self.assertEqual(cqc_header["app_id"], 1)440 self.assertTrue(q1._active)441 def testFactoryZero(self):442 with CQCConnection("Alice", appID=1) as alice:443 q1 = qubit(alice)444 alice.set_pending(True)445 q1.X()446 alice.flush_factory(0, do_sequence=False)447 alice.set_pending(False)448 q1.measure(inplace=True)449 # Checking the factory and the measure, factory should not log any commands450 lastEntries = get_last_entries(2)451 factoryEntry = lastEntries[0]452 self.assertEqual(factoryEntry["node_name"], "Alice")453 factory_cqc_header = factoryEntry["cqc_header"]454 self.assertEqual(factory_cqc_header["type"], CQC_TP_FACTORY)455 expected_length = CQCFactoryHeader.HDR_LENGTH + CQC_CMD_HDR_LENGTH456 self.assertEqual(factory_cqc_header["header_length"], expected_length)457 self.assertEqual(factoryEntry["factory_iterations"], 0)458 measureEntry = lastEntries[1]459 self.assertEqual(measureEntry["node_name"], "Alice")460 self.assertEqual(measureEntry["cmd_header"]["instruction"], CQC_CMD_MEASURE_INPLACE)461 self.assertEqual(measureEntry["cmd_header"]["qubit_id"], q1._qID)462 q1.measure()463 def testFactoryOnce(self):464 with CQCConnection("Alice", appID=1) as alice:465 q1 = qubit(alice)466 alice.set_pending(True)467 q1.X()468 alice.flush_factory(1, do_sequence=False)469 alice.set_pending(False)470 q1.measure(inplace=True)471 # Doing a factory once is equal to doing a sequence, so the factory header is not send472 lastEntries = get_last_entries(2)473 xEntry = lastEntries[0]474 self.assertEqual(xEntry["node_name"], "Alice")475 x_cmd_cmd_header = xEntry["cmd_header"]476 self.assertEqual(x_cmd_cmd_header["instruction"], CQC_CMD_X)477 self.assertEqual(x_cmd_cmd_header["qubit_id"], q1._qID)478 # cqc header is the same as the first.479 measureEntry = lastEntries[1]480 self.assertEqual(measureEntry["node_name"], "Alice")481 self.assertEqual(measureEntry["cmd_header"]["instruction"], CQC_CMD_MEASURE_INPLACE)482 self.assertEqual(measureEntry["cmd_header"]["qubit_id"], q1._qID)483 def testFactoryN(self):484 with CQCConnection("Alice", appID=1) as alice:485 q1 = qubit(alice)486 alice.set_pending(True)487 q1.X()488 alice.flush_factory(10, do_sequence=False)489 alice.set_pending(False)490 q1.measure(inplace=True)491 # Checking the factory and the measure, factory should not log any commands492 lastEntries = get_last_entries(12)493 factoryEntry = lastEntries[0]494 self.assertEqual(factoryEntry["node_name"], "Alice")495 factory_cqc_header = factoryEntry["cqc_header"]496 self.assertEqual(factory_cqc_header["type"], CQC_TP_FACTORY)497 expected_length = CQCFactoryHeader.HDR_LENGTH + CQC_CMD_HDR_LENGTH498 self.assertEqual(factory_cqc_header["header_length"], expected_length)499 self.assertEqual(factoryEntry["factory_iterations"], 10)500 for i in range(1, 11):501 xEntry = lastEntries[i]502 x_cmd_cmd_header = xEntry["cmd_header"]503 self.assertEqual(x_cmd_cmd_header["instruction"], CQC_CMD_X)504 self.assertEqual(x_cmd_cmd_header["qubit_id"], q1._qID)505 # cqc header is the same as the first.506 measureEntry = lastEntries[11]507 self.assertEqual(measureEntry["cmd_header"]["instruction"], CQC_CMD_MEASURE_INPLACE)508 self.assertEqual(measureEntry["cmd_header"]["qubit_id"], q1._qID)509 def testFactoryCNOTFalse(self):510 with CQCConnection("Alice", appID=1) as alice:511 q1 = qubit(alice)512 qubit(alice)513 with self.assertRaises(CQCUnsuppError):514 alice.set_pending(True)515 q1.cnot(q1)516 alice.flush_factory(10, do_sequence=False)517 alice.set_pending(False)518 def testFactoryCNOT(self):519 with CQCConnection("Alice", appID=1) as alice:520 q1 = qubit(alice)521 q2 = qubit(alice)522 alice.set_pending(True)523 q1.cnot(q2)524 alice.flush_factory(10, do_sequence=False)525 alice.set_pending(False)526 entries = get_last_entries(11)527 factoryEntry = entries[0]528 self.assertEqual(factoryEntry["node_name"], "Alice")529 factory_cqc_header = factoryEntry["cqc_header"]530 self.assertEqual(factory_cqc_header["type"], CQC_TP_FACTORY)531 expected_length = CQCFactoryHeader.HDR_LENGTH + CQC_CMD_HDR_LENGTH + CQCXtraQubitHeader.HDR_LENGTH532 self.assertEqual(factory_cqc_header["header_length"], expected_length)533 self.assertEqual(factoryEntry["factory_iterations"], 10)534 for i in range(1, 11):535 xEntry = entries[i]536 x_cmd_cmd_header = xEntry["cmd_header"]537 self.assertEqual(x_cmd_cmd_header["instruction"], CQC_CMD_CNOT)538 self.assertEqual(x_cmd_cmd_header["qubit_id"], q1._qID)539 x = xEntry["xtra_header"]540 self.assertEqual(x["qubit_id"], q2._qID)541 def testFactoryCPHASE(self):542 with CQCConnection("Alice", appID=1) as alice:543 q1 = qubit(alice)544 q2 = qubit(alice)545 alice.set_pending(True)546 q1.cphase(q2)547 alice.flush_factory(10, do_sequence=False)548 alice.set_pending(False)549 entries = get_last_entries(11)550 factoryEntry = entries[0]551 self.assertEqual(factoryEntry["node_name"], "Alice")552 factory_cqc_header = factoryEntry["cqc_header"]553 self.assertEqual(factory_cqc_header["type"], CQC_TP_FACTORY)554 expected_length = CQCFactoryHeader.HDR_LENGTH + CQC_CMD_HDR_LENGTH + CQCXtraQubitHeader.HDR_LENGTH555 self.assertEqual(factory_cqc_header["header_length"], expected_length)556 self.assertEqual(factoryEntry["factory_iterations"], 10)557 for i in range(1, 11):558 xEntry = entries[i]559 x_cmd_cmd_header = xEntry["cmd_header"]560 self.assertEqual(x_cmd_cmd_header["instruction"], CQC_CMD_CPHASE)561 self.assertEqual(x_cmd_cmd_header["qubit_id"], q1._qID)562 x = xEntry["xtra_header"]563 self.assertEqual(x["qubit_id"], q2._qID)564 def testFactoryROTX(self):565 with CQCConnection("Alice", appID=1) as alice:566 q1 = qubit(alice)567 alice.set_pending(True)568 q1.rot_X(step=5)569 alice.flush_factory(10, do_sequence=False)570 alice.set_pending(False)571 q1.measure(inplace=True)572 # Checking the factory and the measure, factory should not log any commands573 lastEntries = get_last_entries(12)574 factoryEntry = lastEntries[0]575 self.assertEqual(factoryEntry["node_name"], "Alice")576 factory_cqc_header = factoryEntry["cqc_header"]577 self.assertEqual(factory_cqc_header["type"], CQC_TP_FACTORY)578 expected_length = CQCFactoryHeader.HDR_LENGTH + CQC_CMD_HDR_LENGTH + CQCRotationHeader.HDR_LENGTH579 self.assertEqual(factory_cqc_header["header_length"], expected_length)580 self.assertEqual(factoryEntry["factory_iterations"], 10)581 for i in range(1, 11):582 xEntry = lastEntries[i]583 x_cmd_cmd_header = xEntry["cmd_header"]584 self.assertEqual(x_cmd_cmd_header["instruction"], CQC_CMD_ROT_X)585 self.assertEqual(x_cmd_cmd_header["qubit_id"], q1._qID)586 xtra_header = xEntry["xtra_header"]587 self.assertEqual(xtra_header["step"], 5)588 # cqc header is the same as the first.589 measureEntry = lastEntries[11]590 self.assertEqual(measureEntry["cmd_header"]["instruction"], CQC_CMD_MEASURE_INPLACE)591 self.assertEqual(measureEntry["cmd_header"]["qubit_id"], q1._qID)592 def testFactoryNew(self):593 with CQCConnection("Alice", appID=1) as alice:594 # Should return a list of qubits with consecutive qubit ids595 alice.set_pending(True)596 qubit(alice)597 qubits = alice.flush_factory(10, do_sequence=False)598 # It is preferable to use the following however:599 # qubits = alice.allocate_qubits(10)600 alice.set_pending(False)601 # Checking the factory and the measure, factory should not log any commands602 lastEntries = get_last_entries(11)603 factoryEntry = lastEntries[0]604 self.assertEqual(factoryEntry["node_name"], "Alice")605 factory_cqc_header = factoryEntry["cqc_header"]606 self.assertEqual(factory_cqc_header["type"], CQC_TP_FACTORY)607 expected_length = CQCFactoryHeader.HDR_LENGTH + CQC_CMD_HDR_LENGTH608 self.assertEqual(factory_cqc_header["header_length"], expected_length)609 self.assertEqual(factoryEntry["factory_iterations"], 10)610 for i in range(1, 11):611 xEntry = lastEntries[i]612 x_cmd_cmd_header = xEntry["cmd_header"]613 self.assertEqual(x_cmd_cmd_header["instruction"], CQC_CMD_NEW)614 curID = qubits[0]._qID615 for q in qubits[1:]:616 self.assertEqual(q._qID, curID + 1)617 curID = q._qID618 def testFactoryMeasure(self):619 with CQCConnection("Alice", appID=1) as alice:620 # this one will go wrong in actual environment621 q1 = qubit(alice)622 alice.set_pending(True)623 q1.measure(inplace=False)624 # with self.assertRaises(QubitNotActiveError):625 measurements = alice.flush_factory(10, do_sequence=False)626 alice.set_pending(False)627 # All measurements should be equal to 2628 self.assertTrue(all(x == 2 for x in measurements))629 lastEntries = get_last_entries(11)630 factoryEntry = lastEntries[0]631 self.assertEqual(factoryEntry["node_name"], "Alice")632 factory_cqc_header = factoryEntry["cqc_header"]633 self.assertEqual(factory_cqc_header["type"], CQC_TP_FACTORY)634 expected_length = CQCFactoryHeader.HDR_LENGTH + CQC_CMD_HDR_LENGTH635 self.assertEqual(factory_cqc_header["header_length"], expected_length)636 self.assertEqual(factoryEntry["factory_iterations"], 10)637 for i in range(1, 11):638 xEntry = lastEntries[i]639 x_cmd_cmd_header = xEntry["cmd_header"]640 self.assertEqual(x_cmd_cmd_header["instruction"], CQC_CMD_MEASURE)641 self.assertEqual(x_cmd_cmd_header["qubit_id"], q1._qID)642 def testFactoryMeasureInplace(self):643 with CQCConnection("Alice", appID=1) as alice:644 # should give the same results as inplace = false645 q1 = qubit(alice)646 alice.set_pending(True)647 q1.measure(inplace=True)648 measurements = alice.flush_factory(10, do_sequence=False)649 alice.set_pending(False)650 # All measurements should be equal to 2651 self.assertTrue(all(x == 2 for x in measurements))652 lastEntries = get_last_entries(11)653 factoryEntry = lastEntries[0]654 self.assertEqual(factoryEntry["node_name"], "Alice")655 factory_cqc_header = factoryEntry["cqc_header"]656 self.assertEqual(factory_cqc_header["type"], CQC_TP_FACTORY)657 expected_length = CQCFactoryHeader.HDR_LENGTH + CQC_CMD_HDR_LENGTH658 self.assertEqual(factory_cqc_header["header_length"], expected_length)659 self.assertEqual(factoryEntry["factory_iterations"], 10)660 for i in range(1, 11):661 xEntry = lastEntries[i]662 x_cmd_cmd_header = xEntry["cmd_header"]663 self.assertEqual(x_cmd_cmd_header["instruction"], CQC_CMD_MEASURE_INPLACE)664 self.assertEqual(x_cmd_cmd_header["qubit_id"], q1._qID)665 def testFactoryReset(self):666 with CQCConnection("Alice", appID=1) as alice:667 q1 = qubit(alice)668 alice.set_pending(True)669 q1.reset()670 res = alice.flush_factory(10, do_sequence=False)671 alice.set_pending(False)672 self.assertListEqual(res, [])673 lastEntries = get_last_entries(11)674 factoryEntry = lastEntries[0]675 self.assertEqual(factoryEntry["node_name"], "Alice")676 factory_cqc_header = factoryEntry["cqc_header"]677 self.assertEqual(factory_cqc_header["type"], CQC_TP_FACTORY)678 expected_length = CQCFactoryHeader.HDR_LENGTH + CQC_CMD_HDR_LENGTH679 self.assertEqual(factory_cqc_header["header_length"], expected_length)680 self.assertEqual(factoryEntry["factory_iterations"], 10)681 for i in range(1, 11):682 xEntry = lastEntries[i]683 x_cmd_cmd_header = xEntry["cmd_header"]684 self.assertEqual(x_cmd_cmd_header["instruction"], CQC_CMD_RESET)685 self.assertEqual(x_cmd_cmd_header["qubit_id"], q1._qID)686 def testFactorySend(self):687 with CQCConnection("Alice", appID=1) as alice:688 q1 = qubit(alice)689 alice.set_pending(True)690 alice.sendQubit(q1, name="Bob", remote_appID=5)691 res = alice.flush_factory(10, do_sequence=False)692 alice.set_pending(False)693 self.assertListEqual(res, [])694 lastEntries = get_last_entries(11)695 factoryEntry = lastEntries[0]696 self.assertEqual(factoryEntry["node_name"], "Alice")697 factory_cqc_header = factoryEntry["cqc_header"]698 self.assertEqual(factory_cqc_header["type"], CQC_TP_FACTORY)699 expected_length = CQCFactoryHeader.HDR_LENGTH + CQC_CMD_HDR_LENGTH + CQCCommunicationHeader.HDR_LENGTH700 self.assertEqual(factory_cqc_header["header_length"], expected_length)701 self.assertEqual(factoryEntry["factory_iterations"], 10)702 for i in range(1, 11):703 xEntry = lastEntries[i]704 x_cmd_cmd_header = xEntry["cmd_header"]705 self.assertEqual(x_cmd_cmd_header["instruction"], CQC_CMD_SEND)706 self.assertEqual(x_cmd_cmd_header["qubit_id"], q1._qID)707 xtra_header = xEntry["xtra_header"]708 self.assertEqual(xtra_header["remote_app_id"], 5)709 self.assertGreater(xtra_header["remote_node"], 1)710 self.assertGreater(xtra_header["remote_port"], 1)711 def testFactoryRecv(self):712 with CQCConnection("Alice", appID=1) as alice:713 alice.set_pending(True)714 alice.recvQubit()715 qubits = alice.flush_factory(10, do_sequence=False)716 alice.set_pending(False)717 curID = qubits[0]._qID718 for q in qubits[1:]:719 self.assertEqual(q._qID, curID + 1)720 curID = q._qID721 lastEntries = get_last_entries(11)722 factoryEntry = lastEntries[0]723 self.assertEqual(factoryEntry["node_name"], "Alice")724 factory_cqc_header = factoryEntry["cqc_header"]725 self.assertEqual(factory_cqc_header["type"], CQC_TP_FACTORY)726 expected_length = CQCFactoryHeader.HDR_LENGTH + CQC_CMD_HDR_LENGTH727 self.assertEqual(factory_cqc_header["header_length"], expected_length)728 self.assertEqual(factoryEntry["factory_iterations"], 10)729 for i in range(1, 11):730 xEntry = lastEntries[i]731 x_cmd_cmd_header = xEntry["cmd_header"]732 self.assertEqual(x_cmd_cmd_header["instruction"], CQC_CMD_RECV)733 def testFactoryEPR(self):734 with CQCConnection("Alice", appID=1) as alice:735 alice.set_pending(True)736 alice.createEPR(name="Bob", remote_appID=5)737 qubits = alice.flush_factory(10, do_sequence=False)738 alice.set_pending(False)739 lastEntries = get_last_entries(51)740 factoryEntry = lastEntries[0]741 self.assertEqual(factoryEntry["node_name"], "Alice")742 factory_cqc_header = factoryEntry["cqc_header"]743 self.assertEqual(factory_cqc_header["type"], CQC_TP_FACTORY)744 expected_length = CQCFactoryHeader.HDR_LENGTH + CQC_CMD_HDR_LENGTH + CQCCommunicationHeader.HDR_LENGTH745 self.assertEqual(factory_cqc_header["header_length"], expected_length)746 self.assertEqual(factoryEntry["factory_iterations"], 10)747 # Check if the qubits are created correctly748 # The protocol already knows what do to on EPR, so no new headers are made,749 # This means that the header of createEPR() is send into new(),750 # New headers have to be made for H() and CNOT() for the qubit ids,751 # but the instruction is not needed, defaults to 0752 curID = [qubits[0]._qID]753 for q in qubits[1:]:754 self.assertEqual(q._qID, curID[-1] + 2)755 curID.append(q._qID)756 for i in range(10):757 xEntry = lastEntries[5 * i + 1]758 x_cmd_cmd_header = xEntry["cmd_header"]759 self.assertEqual(x_cmd_cmd_header["instruction"], CQC_CMD_EPR)760 xtra_header = xEntry["xtra_header"]761 self.assertEqual(xtra_header["remote_app_id"], 5)762 self.assertGreater(xtra_header["remote_node"], 0)763 self.assertGreater(xtra_header["remote_port"], 0)764 xEntry = lastEntries[5 * i + 2]765 x_cmd_cmd_header = xEntry["cmd_header"]766 self.assertEqual(x_cmd_cmd_header["instruction"], CQC_CMD_EPR)767 xEntry = lastEntries[5 * i + 3]768 x_cmd_cmd_header = xEntry["cmd_header"]769 self.assertEqual(x_cmd_cmd_header["instruction"], CQC_CMD_EPR)770 xEntry = lastEntries[5 * i + 4]771 x_cmd_cmd_header = xEntry["cmd_header"] # H Header772 self.assertEqual(x_cmd_cmd_header["instruction"], 0)773 id1 = x_cmd_cmd_header["qubit_id"]774 # Let's see the qubit id is in agreement with the received ones775 self.assertEqual(id1, curID[i])776 xEntry = lastEntries[5 * i + 5]777 x_cmd_cmd_header = xEntry["cmd_header"] # CNOT Header778 self.assertEqual(x_cmd_cmd_header["instruction"], 0)779 self.assertEqual(id1, x_cmd_cmd_header["qubit_id"])780 self.assertEqual(id1 + 1, xEntry["xtra_header"]["qubit_id"])781 def testFactoryEPR_RECV(self):782 with CQCConnection("Alice", appID=1) as alice:783 alice.set_pending(True)784 alice.recvEPR()785 qubits = alice.flush_factory(10, do_sequence=False)786 alice.set_pending(False)787 curID = qubits[0]._qID788 for q in qubits[1:]:789 self.assertEqual(q._qID, curID + 1)790 curID = q._qID791 lastEntries = get_last_entries(11)792 factoryEntry = lastEntries[0]793 self.assertEqual(factoryEntry["node_name"], "Alice")794 factory_cqc_header = factoryEntry["cqc_header"]795 self.assertEqual(factory_cqc_header["type"], CQC_TP_FACTORY)796 expected_length = CQCFactoryHeader.HDR_LENGTH + CQC_CMD_HDR_LENGTH797 self.assertEqual(factory_cqc_header["header_length"], expected_length)798 self.assertEqual(factoryEntry["factory_iterations"], 10)799 for i in range(1, 11):800 xEntry = lastEntries[i]801 x_cmd_cmd_header = xEntry["cmd_header"]802 self.assertEqual(x_cmd_cmd_header["instruction"], CQC_CMD_EPR_RECV)803 def testAllocate0(self):804 with CQCConnection("Alice", appID=1) as alice:805 qubits = alice.allocate_qubits(0)806 self.assertEqual(qubits, [])807 entry = get_last_entries(1)[0]808 self.assertEqual(entry["node_name"], "Alice")809 cqc_hdr = entry["cqc_header"]810 self.assertEqual(cqc_hdr["type"], CQC_TP_COMMAND)811 self.assertEqual(cqc_hdr["header_length"], CQCCmdHeader.HDR_LENGTH)812 cmd_hdr = entry["cmd_header"]813 self.assertEqual(cmd_hdr["instruction"], CQC_CMD_ALLOCATE)814 self.assertEqual(cmd_hdr["qubit_id"], 0)815 def testAllocate10(self):816 with CQCConnection("Alice", appID=1) as alice:817 qubits = alice.allocate_qubits(10)818 self.assertEqual(len(qubits), 10)819 curID = qubits[0]._qID820 for q in qubits[1:]:821 self.assertTrue(q._active)822 self.assertEqual(q._qID, curID + 1)823 curID = q._qID824 entry = get_last_entries(1)[0]825 self.assertEqual(entry["node_name"], "Alice")826 cqc_hdr = entry["cqc_header"]827 self.assertEqual(cqc_hdr["type"], CQC_TP_COMMAND)828 self.assertEqual(cqc_hdr["header_length"], CQCCmdHeader.HDR_LENGTH)829 cmd_hdr = entry["cmd_header"]830 self.assertEqual(cmd_hdr["instruction"], CQC_CMD_ALLOCATE)831 self.assertEqual(cmd_hdr["qubit_id"], 10)832 def testRelease(self):833 with CQCConnection("Alice", appID=1) as alice:834 qubits = alice.allocate_qubits(10)835 alice.release_qubits(qubits)836 for q in qubits:837 self.assertFalse(q._active)838 entries = get_last_entries(10)839 for i in range(10):840 entry = entries[i]841 self.assertEqual(entry["node_name"], "Alice")842 cqc_hdr = entry["cqc_header"]843 self.assertEqual(cqc_hdr["type"], CQC_TP_COMMAND)844 self.assertEqual(cqc_hdr["header_length"], 10 * CQCCmdHeader.HDR_LENGTH)845 cmd_hdr = entry["cmd_header"]846 self.assertEqual(cmd_hdr["instruction"], CQC_CMD_RELEASE)847 self.assertEqual(cmd_hdr["qubit_id"], qubits[i]._qID)848 def testReleaseWhenAlreadyReleased(self):849 with CQCConnection("Alice", appID=1) as alice:850 qubits = alice.allocate_qubits(10)851 qubits[0].measure()852 with self.assertRaises(QubitNotActiveError):853 alice.release_qubits(qubits)854 self.assertTrue(qubits[1]._active)855if __name__ == "__main__":...

Full Screen

Full Screen

personal.js

Source:personal.js Github

copy

Full Screen

1 // start header2 function getScrollAmountForStickyHeader() {3 return void 0 !== qodeGlobalVars.vars.page_scroll_amount_for_sticky && "" !== qodeGlobalVars.vars.page_scroll_amount_for_sticky ? amount = qodeGlobalVars.vars.page_scroll_amount_for_sticky : $(".carousel.full_screen").length ? amount = $(".carousel").height() : amount = scroll_amount_for_sticky, amount4 }5 6 function qodeBrowserDetection() {7 var e = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor),8 t = /Safari/.test(navigator.userAgent) && /Apple Computer/.test(navigator.vendor),9 o = navigator.userAgent.toLowerCase().indexOf("firefox") > -1,10 n = window.navigator.userAgent.indexOf("MSIE ");11 e && qode_body.addClass("qode-chrome"), t && qode_body.addClass("qode-safari"), o && qode_body.addClass("qode-firefox"), (n > 0 || navigator.userAgent.match(/Trident.*rv\:11\./)) && qode_body.addClass("qode-ms-explorer"), /Edge\/\d./i.test(navigator.userAgent) && qode_body.addClass("qode-edge")12 }13 14 function headerSize(e) {15 "use strict";16 //if ($("header.page_header").hasClass("scroll_top") && $("header.page_header").hasClass("has_top") && ($("header.page_header").hasClass("fixed") || $("header.page_header").hasClass("fixed_hiding")) && (e >= 0 && e <= 34 ? ($("header.page_header").css("top", -e), $("header.page_header").css("margin-top", 0), $(".header_top").show()) : e > 34 && ($("header.page_header").css("top", "-34px"), $("header.page_header").css("margin-top", 34), $(".header_top").hide())), sticky_amount = getScrollAmountForStickyHeader(), $("header").hasClass("regular") && (header_height - logo_height >= 10 ? $(".q_logo a").height(logo_height) : $(".q_logo a").height(header_height - 10), $(".q_logo a img").css("height", "100%")), $("header.page_header").hasClass("fixed") && ($top_header_height = $("header.page_header").hasClass("scroll_top") ? 34 : 0, header_height - e + $top_header_height >= min_header_height_scroll && e >= $top_header_height ? ($("header.page_header").removeClass("scrolled"), $("header:not(.centered_logo.centered_logo_animate) nav.main_menu > ul > li > a").css("line-height", header_height - e + $top_header_height + "px"), $("header:not(.centered_logo.centered_logo_animate) .side_menu_button").css("height", header_height - e + $top_header_height + "px"), $("header:not(.centered_logo.centered_logo_animate) .shopping_cart_inner").css("height", header_height - e + $top_header_height + "px"), $("header:not(.centered_logo.centered_logo_animate) .header_bottom .qode-login-register-widget.qode-user-logged-in .qode-logged-in-user").css("height", header_height - e + $top_header_height + "px"), $("header:not(.centered_logo.centered_logo_animate) .logo_wrapper").css("height", header_height - e + $top_header_height + "px"), header_height - logo_height > 0 ? $("header:not(.centered_logo.centered_logo_animate) .q_logo a").css("height", logo_height + "px") : $("header:not(.centered_logo.centered_logo_animate) .q_logo a").css("height", header_height - e + $top_header_height - 10 + "px")) : e < $top_header_height ? ($("header.page_header").removeClass("scrolled"), $("header:not(.centered_logo.centered_logo_animate) nav.main_menu > ul > li > a").css("line-height", header_height + "px"), $("header:not(.centered_logo.centered_logo_animate) .side_menu_button").css("height", header_height + "px"), $("header:not(.centered_logo.centered_logo_animate) .shopping_cart_inner").css("height", header_height + "px"), $("header:not(.centered_logo.centered_logo_animate) .header_bottom .qode-login-register-widget.qode-user-logged-in .qode-logged-in-user").css("height", header_height + "px"), $("header:not(.centered_logo.centered_logo_animate) .logo_wrapper").css("height", header_height + "px"), header_height - logo_height > 0 ? $("header:not(.centered_logo.centered_logo_animate) .q_logo a").css("height", logo_height + "px") : $("header:not(.centered_logo.centered_logo_animate) .q_logo a").css("height", header_height - 10 + "px")) : header_height - e + $top_header_height < min_header_height_scroll && ($("header.page_header").addClass("scrolled"), $("header:not(.centered_logo.centered_logo_animate) nav.main_menu > ul > li > a").css("line-height", min_header_height_scroll + "px"), $("header:not(.centered_logo.centered_logo_animate) .side_menu_button").css("height", min_header_height_scroll + "px"), $("header:not(.centered_logo.centered_logo_animate) .shopping_cart_inner").css("height", min_header_height_scroll + "px"), $("header:not(.centered_logo.centered_logo_animate) .header_bottom .qode-login-register-widget.qode-user-logged-in .qode-logged-in-user").css("height", min_header_height_scroll + "px"), $("header:not(.centered_logo.centered_logo_animate) .logo_wrapper").css("height", min_header_height_scroll + "px"), min_header_height_scroll - logo_height > 0 ? $("header:not(.centered_logo.centered_logo_animate) .q_logo a").css("height", logo_height + "px") : $("header:not(.centered_logo.centered_logo_animate) .q_logo a").css("height", min_header_height_scroll - 10 + "px")), $("header.page_header").hasClass("centered_logo") && $("header.page_header").hasClass("centered_logo_animate") ? header_height - e + $top_header_height < logo_height && header_height - e + $top_header_height >= min_header_height_scroll && logo_height > min_header_height_scroll - 10 && e >= $top_header_height ? $(".q_logo a").height(header_height - e + $top_header_height - 10) : header_height - e + $top_header_height < logo_height && header_height - e + $top_header_height >= min_header_height_scroll && logo_height > min_header_height_scroll - 10 && e < $top_header_height ? $(".q_logo a").height(header_height - 10) : header_height - e + $top_header_height < logo_height && header_height - e + $top_header_height < min_header_height_scroll && logo_height > min_header_height_scroll - 10 ? $(".q_logo a").height(min_header_height_scroll - 10) : header_height - e + $top_header_height < logo_height && header_height - e + $top_header_height < min_header_height_scroll && logo_height < min_header_height_scroll - 10 ? $(".q_logo a").height(logo_height) : (e + $top_header_height === 0 && header_height, $(".q_logo a").height(logo_height)) : $("header.page_header").hasClass("centered_logo") ? ($(".q_logo a").height(logo_height), $(".q_logo img").height("auto")) : $(".q_logo img").height("100%"), setLeftPostionedMenuPadding()), $("header.page_header").hasClass("fixed_hiding") && (e < scroll_amount_for_fixed_hiding ? $("header.page_header").removeClass("scrolled") : $("header.page_header").addClass("scrolled"), $(".q_logo a").height(logo_height / 2), $(".q_logo img").height("100%")), $("header.page_header").hasClass("stick") || $("header.page_header").hasClass("stick_with_left_right_menu")) {17 if ($("header.page_header").hasClass("scroll_top") && $("header.page_header").hasClass("has_top") && ($("header.page_header").hasClass("fixed") || $("header.page_header").hasClass("fixed_hiding")) && (e >= 0 && e <= 34 ? ($("header.page_header").css("top", -e),18 $("header.page_header").css("margin-top", 0),19 $(".header_top").show()) : e > 34 && ($("header.page_header").css("top", "-34px"),20 $("header.page_header").css("margin-top", 34),21 $(".header_top").hide())),22 sticky_amount = getScrollAmountForStickyHeader(),23 $("header").hasClass("regular") && (header_height - logo_height >= 10 ? $(".q_logo a").height(logo_height) : $(".q_logo a").height(header_height - 10),24 $(".q_logo a img").css("height", "100%")),25 $("header.page_header").hasClass("fixed") && ($top_header_height = $("header.page_header").hasClass("scroll_top") ? 34 : 0,26 header_height - e + $top_header_height >= min_header_height_scroll && e >= $top_header_height ? ($("header.page_header").removeClass("scrolled"),27 $("header:not(.centered_logo.centered_logo_animate) nav.main_menu > ul > li > a").css("line-height", header_height - e + $top_header_height + "px"),28 $("header:not(.centered_logo.centered_logo_animate) .side_menu_button").css("height", header_height - e + $top_header_height + "px"),29 $("header:not(.centered_logo.centered_logo_animate) .shopping_cart_inner").css("height", header_height - e + $top_header_height + "px"),30 $("header:not(.centered_logo.centered_logo_animate) .header_bottom .qode-login-register-widget.qode-user-logged-in .qode-logged-in-user").css("height", header_height - e + $top_header_height + "px"),31 $("header:not(.centered_logo.centered_logo_animate) .logo_wrapper").css("height", header_height - e + $top_header_height + "px"), header_height - logo_height > 0 ? $("header:not(.centered_logo.centered_logo_animate) .q_logo a").css("height", logo_height + "px") : $("header:not(.centered_logo.centered_logo_animate) .q_logo a").css("height", header_height - e + $top_header_height - 10 + "px")) : e < $top_header_height ? ($("header.page_header").removeClass("scrolled"),32 $("header:not(.centered_logo.centered_logo_animate) nav.main_menu > ul > li > a").css("line-height", header_height + "px"),33 $("header:not(.centered_logo.centered_logo_animate) .side_menu_button").css("height", header_height + "px"),34 $("header:not(.centered_logo.centered_logo_animate) .shopping_cart_inner").css("height", header_height + "px"),35 $("header:not(.centered_logo.centered_logo_animate) .header_bottom .qode-login-register-widget.qode-user-logged-in .qode-logged-in-user").css("height", header_height + "px"),36 $("header:not(.centered_logo.centered_logo_animate) .logo_wrapper").css("height", header_height + "px"),...

Full Screen

Full Screen

base.py

Source:base.py Github

copy

Full Screen

...191 base_db: AtomicDatabaseAPI,192 genesis_params: Dict[str, HeaderParams],193 genesis_state: AccountState = None) -> 'BaseChain':194 genesis_vm_class = cls.get_vm_class_for_block_number(BlockNumber(0))195 pre_genesis_header = BlockHeader(difficulty=0, block_number=-1, gas_limit=0)196 chain_context = ChainContext(cls.chain_id)197 state = genesis_vm_class.build_state(base_db, pre_genesis_header, chain_context)198 if genesis_state is None:199 genesis_state = {}200 # mutation201 apply_state_dict(state, genesis_state)202 state.persist()203 if 'state_root' not in genesis_params:204 # If the genesis state_root was not specified, use the value205 # computed from the initialized state database.206 genesis_params = assoc(genesis_params, 'state_root', state.state_root)207 elif genesis_params['state_root'] != state.state_root:208 # If the genesis state_root was specified, validate that it matches209 # the computed state from the initialized state database....

Full Screen

Full Screen

cqcLogMessageHandler.py

Source:cqcLogMessageHandler.py Github

copy

Full Screen

...85 subdata["node_name"] = node_name86 subdata["comment"] = comment87 subdata["cqc_header"] = cls.parse_header(header)88 if len(data) >= cmd_l:89 subdata["cmd_header"] = cls.parse_cmd(CQCCmdHeader(data[:cmd_l]))90 if len(data) >= cmd_l + xtra_l:91 subdata["xtra_header"] = cls.parse_xtra(CQCXtraHeader(data[cmd_l: cmd_l + xtra_l]))92 cls.logData.append(subdata)93 with open(cls.file, "w") as outfile:94 json.dump(cls.logData, outfile)95 @classmethod96 def parse_handle_factory(cls, header, data, comment, node_name):97 subdata = {}98 subdata["node_name"] = node_name99 subdata["comment"] = comment100 subdata["cqc_header"] = cls.parse_header(header)101 fact_hdr = CQCFactoryHeader(data[: CQCFactoryHeader.HDR_LENGTH])102 subdata["factory_iterations"] = fact_hdr.num_iter103 subdata["notify"] = fact_hdr.notify104 cls.logData.append(subdata)105 with open(cls.file, "w") as outfile:106 json.dump(cls.logData, outfile)107 @classmethod108 def parse_header(cls, header):109 header_data = {}110 header_data["type"] = header.tp111 header_data["app_id"] = header.app_id112 header_data["header_length"] = header.length113 header_data["is_set"] = header.is_set114 return header_data115 @classmethod116 def parse_cmd(cls, cmd):117 cmd_data = {}118 cmd_data["notify"] = cmd.notify119 cmd_data["block"] = cmd.block120 cmd_data["action"] = cmd.action121 cmd_data["is_set"] = cmd.is_set122 cmd_data["qubit_id"] = cmd.qubit_id123 cmd_data["instruction"] = cmd.instr124 return cmd_data125 @classmethod126 def parse_xtra(cls, xtra):127 if isinstance(xtra, CQCCommunicationHeader):128 return cls.parse_com_hdr(xtra)129 if isinstance(xtra, CQCXtraQubitHeader):130 return cls.parse_xtra_qubit_hdr(xtra)131 if isinstance(xtra, CQCRotationHeader):132 return cls.parse_rot_hdr(xtra)133 xtra_data = {}134 xtra_data["is_set"] = xtra.is_set135 xtra_data["qubit_id"] = xtra.qubit_id136 xtra_data["step"] = xtra.step137 xtra_data["remote_app_id"] = xtra.remote_app_id138 xtra_data["remote_node"] = xtra.remote_node139 xtra_data["remote_port"] = xtra.remote_port140 xtra_data["cmdLength"] = xtra.cmdLength141 return xtra_data142 @classmethod143 def parse_rot_hdr(cls, com_hdr):144 """145 Communication header146 """147 rot_data = {}148 rot_data["type"] = "Rotation header"149 rot_data["step"] = com_hdr.step150 return rot_data151 @classmethod152 def parse_com_hdr(cls, com_hdr):153 """154 Communication header155 """156 com_data = {}157 com_data["type"] = "Communication header"158 com_data["remote_app_id"] = com_hdr.remote_app_id159 com_data["remote_node"] = com_hdr.remote_node160 com_data["remote_port"] = com_hdr.remote_port161 return com_data162 @classmethod163 def parse_xtra_qubit_hdr(cls, com_hdr):164 """165 Communication header166 """167 com_data = {}168 com_data["type"] = "Extra qubit header"169 com_data["qubit_id"] = com_hdr.qubit_id170 return com_data171 def handle_hello(self, header, data):172 """173 Hello just requires us to return hello - for testing availability.174 """175 self.parse_handle_data(header, data, "Handle Hello", self.factory.name)176 return super().handle_hello(header, data)177 def handle_factory(self, header, data):178 # Calls process_command, which should also log179 self.parse_handle_factory(header, data, "Handle factory", self.factory.name)180 return super().handle_factory(header, data)181 def handle_time(self, header, data):182 self.parse_handle_data(header, data, "Handle time", self.factory.name)183 # Read the command header to learn the qubit ID184 raw_cmd_header = data[:CQC_CMD_HDR_LENGTH]185 cmd_hdr = CQCCmdHeader(raw_cmd_header)186 # Craft reply187 # First send an appropriate CQC Header188 if header.version < 2:189 length = CQC_NOTIFY_LENGTH190 else:191 length = CQC_TIMEINFO_HDR_LENGTH192 cqc_msg = self.create_return_message(header.app_id, CQC_TP_INF_TIME, length=length, cqc_version=header.version)193 self.return_messages.append(cqc_msg)194 # Then we send a notify header with the timing details195 # We do not have a qubit, so no timestamp either.196 # So let's send back some random date197 datetime = 758505600198 if header.version < 2:199 hdr = CQCNotifyHeader()200 hdr.setVals(cmd_hdr.qubit_id, 0, 0, 0, 0, datetime)201 else:202 hdr = CQCTimeinfoHeader()203 hdr.setVals(datetime)204 msg = hdr.pack()205 self.return_messages.append(msg)206 return207 def cmd_i(self, cqc_header, cmd, xtra):208 self.parse_data(cqc_header, cmd, xtra, "Identity", self.factory.name)209 def cmd_x(self, cqc_header, cmd, xtra):210 self.parse_data(cqc_header, cmd, xtra, "X gate", self.factory.name)211 def cmd_y(self, cqc_header, cmd, xtra):212 self.parse_data(cqc_header, cmd, xtra, "Y gate", self.factory.name)213 def cmd_z(self, cqc_header, cmd, xtra):214 self.parse_data(cqc_header, cmd, xtra, "Z gate", self.factory.name)215 def cmd_t(self, cqc_header, cmd, xtra):216 self.parse_data(cqc_header, cmd, xtra, "T gate", self.factory.name)217 def cmd_h(self, cqc_header, cmd, xtra):218 self.parse_data(cqc_header, cmd, xtra, "H gate", self.factory.name)219 def cmd_k(self, cqc_header, cmd, xtra):220 self.parse_data(cqc_header, cmd, xtra, "K gate", self.factory.name)221 def cmd_rotx(self, cqc_header, cmd, xtra):222 self.parse_data(cqc_header, cmd, xtra, "Rotate x", self.factory.name)223 def cmd_roty(self, cqc_header, cmd, xtra):224 self.parse_data(cqc_header, cmd, xtra, "Rotate y", self.factory.name)225 def cmd_rotz(self, cqc_header, cmd, xtra):226 self.parse_data(cqc_header, cmd, xtra, "Rotate z", self.factory.name)227 def cmd_cnot(self, cqc_header, cmd, xtra):228 self.parse_data(cqc_header, cmd, xtra, "CNOT gate", self.factory.name)229 def cmd_cphase(self, cqc_header, cmd, xtra):230 self.parse_data(cqc_header, cmd, xtra, "CPhase gate", self.factory.name)231 def cmd_measure(self, cqc_header, cmd, xtra, inplace=False):232 self.parse_data(cqc_header, cmd, xtra, "Measure", self.factory.name)233 # We'll always have 2 as outcome234 if cqc_header.version < 2:235 length = CQC_NOTIFY_LENGTH236 else:237 length = CQC_MEAS_OUT_HDR_LENGTH238 cqc_msg = self.create_return_message(cqc_header.app_id, CQC_TP_MEASOUT, length=length,239 cqc_version=cqc_header.version)240 outcome = 2241 if cqc_header.version < 2:242 hdr = CQCNotifyHeader()243 hdr.setVals(cmd.qubit_id, outcome, 0, 0, 0, 0)244 else:245 hdr = CQCMeasOutHeader()246 hdr.setVals(outcome=outcome)247 msg = hdr.pack()248 self.return_messages.append(cqc_msg)249 self.return_messages.append(msg)250 def cmd_measure_inplace(self, cqc_header, cmd, xtra):251 self.parse_data(cqc_header, cmd, xtra, "Measure in place", self.factory.name)252 # We'll always have 2 as outcome253 if cqc_header.version < 2:254 length = CQC_NOTIFY_LENGTH255 else:256 length = CQC_MEAS_OUT_HDR_LENGTH257 cqc_msg = self.create_return_message(cqc_header.app_id, CQC_TP_MEASOUT, length=length,258 cqc_version=cqc_header.version)259 outcome = 2260 if cqc_header.version < 2:261 hdr = CQCNotifyHeader()262 hdr.setVals(cmd.qubit_id, outcome, 0, 0, 0, 0)263 else:264 hdr = CQCMeasOutHeader()265 hdr.setVals(outcome=outcome)266 msg = hdr.pack()267 self.return_messages.append(cqc_msg)268 self.return_messages.append(msg)269 def cmd_reset(self, cqc_header, cmd, xtra):270 self.parse_data(cqc_header, cmd, xtra, "Rest", self.factory.name)271 def cmd_send(self, cqc_header, cmd, xtra):272 self.parse_data(cqc_header, cmd, xtra, "Send", self.factory.name)273 def cmd_recv(self, cqc_header, cmd, xtra):274 self.parse_data(cqc_header, cmd, xtra, "Receive", self.factory.name)275 q_id = CQCLogMessageHandler.cur_qubit_id276 CQCLogMessageHandler.cur_qubit_id += 1277 if cqc_header.version < 2:278 length = CQC_NOTIFY_LENGTH279 else:280 length = CQC_XTRA_QUBIT_HDR_LENGTH281 recv_msg = self.create_return_message(cqc_header.app_id, CQC_TP_RECV, length=length,282 cqc_version=cqc_header.version)283 if cqc_header.version < 2:284 hdr = CQCNotifyHeader()285 hdr.setVals(q_id, 0, 0, 0, 0, 0)286 else:287 hdr = CQCXtraQubitHeader()288 hdr.setVals(qubit_id=q_id)289 msg = hdr.pack()290 self.return_messages.append(recv_msg)291 self.return_messages.append(msg)292 def cmd_epr(self, cqc_header, cmd, xtra):293 self.parse_data(cqc_header, cmd, xtra, "Create EPR", self.factory.name)294 # Get ip and port of this host295 host_node = self.factory.host.ip296 host_port = self.factory.host.port297 host_app_id = cqc_header.app_id298 # Get ip and port of remote host299 remote_node = xtra.remote_node300 remote_port = xtra.remote_port301 remote_app_id = xtra.remote_app_id302 # Create the first qubit303 (succ, q_id1) = self.cmd_new(cqc_header, cmd, xtra, return_q_id=True, return_succ=True)304 if not succ:305 return306 # Create the second qubit307 (succ, q_id2) = self.cmd_new(cqc_header, cmd, xtra, return_q_id=True, return_succ=True)308 if not succ:309 return310 # Create headers for qubits311 cmd1 = CQCCmdHeader()312 cmd1.setVals(q_id1, 0, 0, 0, 0)313 cmd2 = CQCCmdHeader()314 cmd2.setVals(q_id2, 0, 0, 0, 0)315 xtra_cnot = CQCXtraQubitHeader()316 xtra_cnot.setVals(q_id2)317 # Produce EPR-pair318 self.cmd_h(cqc_header, cmd1, None)319 self.cmd_cnot(cqc_header, cmd1, xtra_cnot)320 if cqc_header.version < 2:321 length = CQC_NOTIFY_LENGTH + ENT_INFO_LENGTH322 else:323 length = CQC_XTRA_QUBIT_HDR_LENGTH + ENT_INFO_LENGTH324 msg_ok = self.create_return_message(325 cqc_header.app_id, CQC_TP_EPR_OK, length=length326 )327 self.return_messages.append(msg_ok)328 if cqc_header.version < 2:329 hdr = CQCNotifyHeader()330 hdr.setVals(q_id1, 0, 0, 0, 0, 0)331 logging.debug("CQC %s: Notify %s", self.name, hdr.printable())332 else:333 hdr = CQCXtraQubitHeader()334 hdr.setVals(qubit_id=q_id1)335 logging.debug("CQC %s: %s", self.name, hdr.printable())336 msg = hdr.pack()337 self.return_messages.append(msg)338 # Send entanglement info339 ent_id = 1340 ent_info = EntInfoHeader()341 ent_info.setVals(342 host_node,343 host_port,344 host_app_id,345 remote_node,346 remote_port,347 remote_app_id,348 ent_id,349 int(time.time()),350 int(time.time()),351 0,352 1,353 )354 msg_ent_info = ent_info.pack()355 self.return_messages.append(msg_ent_info)356 def cmd_epr_recv(self, cqc_header, cmd, xtra):357 self.parse_data(cqc_header, cmd, xtra, "Receive EPR", self.factory.name)358 q_id = CQCLogMessageHandler.cur_qubit_id359 CQCLogMessageHandler.cur_qubit_id += 1360 # We're not sending the entanglement info atm, because we do not have any361 if cqc_header.version < 2:362 length = CQC_NOTIFY_LENGTH363 else:364 length = CQC_XTRA_QUBIT_HDR_LENGTH365 cqc_msg = self.create_return_message(cqc_header.app_id, CQC_TP_RECV, length=length,366 cqc_version=cqc_header.version)367 if cqc_header.version < 2:368 hdr = CQCNotifyHeader()369 hdr.setVals(q_id, 0, 0, 0, 0, 0)370 else:371 hdr = CQCXtraQubitHeader()372 hdr.setVals(qubit_id=q_id)373 msg = hdr.pack()374 self.return_messages.append(cqc_msg)375 self.return_messages.append(msg)376 def cmd_new(self, cqc_header, cmd, xtra, return_q_id=False, return_succ=False, to_file=True):377 if to_file:378 self.parse_data(cqc_header, cmd, xtra, "Create new qubit", self.factory.name)379 q_id = CQCLogMessageHandler.cur_qubit_id380 CQCLogMessageHandler.cur_qubit_id += 1381 if not return_q_id:382 # Send message we created a qubit back383 if cqc_header.version < 2:384 length = CQC_NOTIFY_LENGTH385 else:386 length = CQC_XTRA_QUBIT_HDR_LENGTH387 cqc_msg = self.create_return_message(cqc_header.app_id, CQC_TP_NEW_OK, length=length,388 cqc_version=cqc_header.version)389 self.return_messages.append(cqc_msg)390 if cqc_header.version < 2:391 hdr = CQCNotifyHeader()392 hdr.setVals(q_id, 0, 0, 0, 0, 0)393 else:394 hdr = CQCXtraQubitHeader()395 hdr.setVals(qubit_id=q_id)396 msg = hdr.pack()397 self.return_messages.append(msg)398 if return_q_id:399 return True, q_id400 elif return_succ:401 return True402 else:403 return404 def cmd_allocate(self, cqc_header, cmd, xtra):405 """406 Allocate multipe qubits.407 """408 self.parse_data(cqc_header, cmd, xtra, "Allocating qubits", self.factory.name)...

Full Screen

Full Screen

HeaderButtons.js

Source:HeaderButtons.js Github

copy

Full Screen

1/* eslint-disable import/no-extraneous-dependencies, import/no-unresolved, import/extensions, react/prop-types */2import React from 'react';3import { storiesOf } from '@storybook/react-native';4import { View } from 'react-native';5import * as HeaderButton from '../../app/containers/HeaderButton';6import Header from '../../app/containers/Header';7import { ThemeContext } from '../../app/theme';8const stories = storiesOf('Header Buttons', module);9const HeaderExample = ({ left, right }) => (10 <Header11 headerLeft={left}12 headerTitle={() => <View style={{ flex: 1 }} />}13 headerRight={right}14 />15);16stories.add('title', () => (17 <>18 <HeaderExample19 left={() => (20 <HeaderButton.Container left>21 <HeaderButton.Item title='threads' />22 </HeaderButton.Container>23 )}24 right={() => (25 <HeaderButton.Container>26 <HeaderButton.Item title='threads' />27 </HeaderButton.Container>28 )}29 />30 <HeaderExample31 left={() => (32 <HeaderButton.Container left>33 <HeaderButton.Item title='threads' />34 <HeaderButton.Item title='search' />35 </HeaderButton.Container>36 )}37 right={() => (38 <HeaderButton.Container>39 <HeaderButton.Item title='threads' />40 <HeaderButton.Item title='search' />41 </HeaderButton.Container>42 )}43 />44 </>45));46stories.add('icons', () => (47 <>48 <HeaderExample49 left={() => (50 <HeaderButton.Container left>51 <HeaderButton.Item iconName='threads' />52 </HeaderButton.Container>53 )}54 right={() => (55 <HeaderButton.Container>56 <HeaderButton.Item iconName='threads' />57 </HeaderButton.Container>58 )}59 />60 <HeaderExample61 left={() => (62 <HeaderButton.Container left>63 <HeaderButton.Item iconName='threads' />64 <HeaderButton.Item iconName='search' />65 </HeaderButton.Container>66 )}67 right={() => (68 <HeaderButton.Container>69 <HeaderButton.Item iconName='threads' />70 <HeaderButton.Item iconName='search' />71 </HeaderButton.Container>72 )}73 />74 </>75));76stories.add('badge', () => (77 <>78 <HeaderExample79 left={() => (80 <HeaderButton.Container left>81 <HeaderButton.Item iconName='threads' badge={() => <HeaderButton.Badge tunread={[1]} />} />82 <HeaderButton.Item iconName='threads' badge={() => <HeaderButton.Badge tunread={[1]} tunreadUser={[1]} />} />83 <HeaderButton.Item iconName='threads' badge={() => <HeaderButton.Badge tunread={[1]} tunreadGroup={[1]} />} />84 </HeaderButton.Container>85 )}86 />87 </>88));89const ThemeStory = ({ theme }) => (90 <ThemeContext.Provider91 value={{ theme }}92 >93 <HeaderExample94 left={() => (95 <HeaderButton.Container left>96 <HeaderButton.Item iconName='threads' />97 </HeaderButton.Container>98 )}99 right={() => (100 <HeaderButton.Container>101 <HeaderButton.Item title='Threads' />102 <HeaderButton.Item iconName='threads' badge={() => <HeaderButton.Badge tunread={[1]} />} />103 </HeaderButton.Container>104 )}105 />106 </ThemeContext.Provider>107);108stories.add('themes', () => (109 <>110 <ThemeStory theme='light' />111 <ThemeStory theme='dark' />112 <ThemeStory theme='black' />113 </>114));115stories.add('common', () => (116 <>117 <HeaderExample118 left={() => (119 <HeaderButton.Drawer />120 )}121 />122 <HeaderExample123 left={() => (124 <HeaderButton.CloseModal />125 )}126 />127 <HeaderExample128 left={() => (129 <HeaderButton.CancelModal />130 )}131 />132 <HeaderExample133 right={() => (134 <HeaderButton.More />135 )}136 />137 <HeaderExample138 right={() => (139 <HeaderButton.Download />140 )}141 />142 <HeaderExample143 right={() => (144 <HeaderButton.Preferences />145 )}146 />147 <HeaderExample148 right={() => (149 <HeaderButton.Legal />150 )}151 />152 </>...

Full Screen

Full Screen

cardHeaderStyle.jsx

Source:cardHeaderStyle.jsx Github

copy

Full Screen

1import {2 warningCardHeader,3 successCardHeader,4 dangerCardHeader,5 infoCardHeader,6 primaryCardHeader,7 roseCardHeader8} from "assets/jss/material-dashboard-react.jsx";9const cardHeaderStyle = {10 cardHeader: {11 padding: "0.75rem 1.25rem",12 marginBottom: "0",13 borderBottom: "none",14 background: "transparent",15 zIndex: "3 !important",16 "&$cardHeaderPlain,&$cardHeaderIcon,&$cardHeaderStats,&$warningCardHeader,&$successCardHeader,&$dangerCardHeader,&$infoCardHeader,&$primaryCardHeader,&$roseCardHeader": {17 margin: "0 15px",18 padding: "0",19 position: "relative",20 color: "#FFFFFF"21 },22 "&:first-child": {23 borderRadius: "calc(.25rem - 1px) calc(.25rem - 1px) 0 0"24 },25 "&$warningCardHeader,&$successCardHeader,&$dangerCardHeader,&$infoCardHeader,&$primaryCardHeader,&$roseCardHeader": {26 "&:not($cardHeaderIcon)": {27 borderRadius: "3px",28 marginTop: "-20px",29 padding: "15px"30 }31 },32 "&$cardHeaderStats svg": {33 fontSize: "36px",34 lineHeight: "56px",35 textAlign: "center",36 width: "36px",37 height: "36px",38 margin: "10px 10px 4px"39 },40 "&$cardHeaderStats i,&$cardHeaderStats .material-icons": {41 fontSize: "36px",42 lineHeight: "56px",43 width: "56px",44 height: "56px",45 textAlign: "center",46 overflow: "unset",47 marginBottom: "1px"48 },49 "&$cardHeaderStats$cardHeaderIcon": {50 textAlign: "right"51 }52 },53 cardHeaderPlain: {54 marginLeft: "0px !important",55 marginRight: "0px !important"56 },57 cardHeaderStats: {58 "& $cardHeaderIcon": {59 textAlign: "right"60 },61 "& h1,& h2,& h3,& h4,& h5,& h6": {62 margin: "0 !important"63 }64 },65 cardHeaderIcon: {66 "&$warningCardHeader,&$successCardHeader,&$dangerCardHeader,&$infoCardHeader,&$primaryCardHeader,&$roseCardHeader": {67 background: "transparent",68 boxShadow: "none"69 },70 "& i,& .material-icons": {71 width: "33px",72 height: "33px",73 textAlign: "center",74 lineHeight: "33px"75 },76 "& svg": {77 width: "24px",78 height: "24px",79 textAlign: "center",80 lineHeight: "33px",81 margin: "5px 4px 0px"82 }83 },84 warningCardHeader: {85 color: "#FFFFFF",86 "&:not($cardHeaderIcon)": {87 ...warningCardHeader88 }89 },90 successCardHeader: {91 color: "#FFFFFF",92 "&:not($cardHeaderIcon)": {93 ...successCardHeader94 }95 },96 dangerCardHeader: {97 color: "#FFFFFF",98 "&:not($cardHeaderIcon)": {99 ...dangerCardHeader100 }101 },102 infoCardHeader: {103 color: "#FFFFFF",104 "&:not($cardHeaderIcon)": {105 ...infoCardHeader106 }107 },108 primaryCardHeader: {109 color: "#FFFFFF",110 "&:not($cardHeaderIcon)": {111 ...primaryCardHeader112 }113 },114 roseCardHeader: {115 color: "#FFFFFF",116 "&:not($cardHeaderIcon)": {117 ...roseCardHeader118 }119 }120};...

Full Screen

Full Screen

header.js

Source:header.js Github

copy

Full Screen

1const header = document.querySelector('[data-element="header"]')2export function headerExport() {3 if (header) setTimeout(headerInit, 0)4}5function headerInit() {6 const headerNav = header.querySelector('[data-element="header__nav"]')7 const headerButtonBurger = header.querySelector('[data-element="header__button_burger"]')8 const headerLayer = header.querySelector('[data-element="header__layer"]')9 headerButtonBurger.addEventListener('click', toggleMenu)10 headerLayer.addEventListener('click', closeMenu)11 const headerSearchButton = header.querySelector('[data-element="header__button_search"]')12 const headerSearchForm = header.querySelector('[data-element="header__search-form"]')13 const headerLayerSearch = header.querySelector('[data-element="header__layer-search"]')14 const headerSearchBtnClose = header.querySelector('[data-element="header__search-btn_close"]')15 const headerSearchInput = headerSearchForm.getElementsByClassName("header__search-input")[0]16 headerSearchButton.addEventListener("click", openSearch)17 headerLayerSearch.addEventListener("click", closeSearch)18 headerSearchBtnClose.addEventListener("click", closeSearch)19 function openSearch() {20 headerSearchForm.classList.add("header__search-form_active")21 headerLayerSearch.classList.add("header__layer-search_active")22 headerSearchInput.focus()23 }24 function closeSearch() {25 headerSearchForm.classList.remove("header__search-form_active")26 headerLayerSearch.classList.remove("header__layer-search_active")27 }28 function closeMenu() {29 headerButtonBurger.classList.remove("header__button_burger-active")30 headerNav.classList.remove("header__nav_active")31 headerLayer.classList.remove("header__layer_active")32 }33 function toggleMenu() {34 if (headerButtonBurger.classList.contains("header__button_burger-active")) {35 closeMenu()36 } else {37 headerButtonBurger.classList.add("header__button_burger-active")38 headerNav.classList.add("header__nav_active")39 headerLayer.classList.add("header__layer_active")40 }41 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var argosy = require('argosy')2var argosyHeader = require('argosy-header')3var argosyPattern = require('argosy-pattern')4var argosyRpc = require('argosy-rpc')5var argosyWeb = require('argosy-web')6var service = argosy()7service.pipe(argosyHeader())8service.pipe(argosyPattern({9 'hello': function (name, cb) {10 cb(null, 'hello ' + name)11 }12}))13service.pipe(argosyRpc())14service.pipe(argosyWeb())15service.pipe(process.stdout)16var argosy = require('argosy')17var argosyHeader = require('argosy-header')18var argosyPattern = require('argosy-pattern')19var argosyRpc = require('argosy-rpc')20var argosyWeb = require('argosy-web')21var service = argosy()22service.pipe(argosyHeader())23service.pipe(argosyPattern({24 'hello': function (name, cb) {25 cb(null, 'hello ' + name)26 }27}))28service.pipe(argosyRpc())29service.pipe(argosyWeb())30service.pipe(process.stdout)31var argosy = require('argosy')32var argosyHeader = require('argosy-header')33var argosyPattern = require('argosy-pattern')34var argosyRpc = require('argosy-rpc')35var argosyWeb = require('argosy-web')36var service = argosy()37service.pipe(argosyHeader())38service.pipe(argosyPattern({39 'hello': function (name, cb) {40 cb(null, 'hello ' + name)41 }42}))43service.pipe(argosyRpc())44service.pipe(argosyWeb())45service.pipe(process.stdout)46var argosy = require('argosy')47var argosyHeader = require('argosy-header')48var argosyPattern = require('argosy-pattern')49var argosyRpc = require('argosy-rpc')50var argosyWeb = require('argosy

Full Screen

Using AI Code Generation

copy

Full Screen

1var argosy = require('argosy')2var argosyPattern = require('argosy-pattern')3var argosyHeader = require('argosy-header')4var service = argosy()5service.pipe(argosyHeader()).pipe(service)6service.accept({role: 'math', cmd: 'sum'}, function (msg, respond) {7 respond(null, {answer: msg.left + msg.right})8})9service.act({role: 'math', cmd: 'sum', left: 1, right: 2}, function (err, result) {10 if (err) throw err11})12var service = argosy()13service.pipe(argosyPattern()).pipe(service)14service.accept({role: 'math', cmd: 'sum'}, function (msg, respond) {15 respond(null, {answer: msg.left + msg.right})16})17service.act({role: 'math', cmd: 'sum', left: 1, right: 2}, function (err, result) {18 if (err) throw err19})20var service = argosy()21service.pipe(argosyTransportHttp()).pipe(service)22service.accept({role: 'math', cmd: 'sum'}, function (msg, respond) {23 respond(null, {answer: msg.left + msg.right})24})25service.act({role: 'math', cmd: 'sum', left: 1, right: 2}, function (err, result) {26 if (err) throw err27})28var service = argosy()29service.pipe(argosyTransportZeromq()).pipe(service)30service.accept({role: 'math', cmd: 'sum'}, function (msg, respond) {31 respond(null, {answer: msg.left + msg.right})32})33service.act({role: 'math', cmd: 'sum', left: 1, right: 2}, function (err, result) {34 if (err) throw err

Full Screen

Using AI Code Generation

copy

Full Screen

1const argosy = require('argosy')2const argosyPattern = require('argosy-pattern')3const argosyHeader = require('argosy-header')4const service = argosy()5service.pipe(argosyHeader()).pipe(service)6const argosy = require('argosy')7const argosyPattern = require('argosy-pattern')8const argosyHeader = require('argosy-header')9const service = argosy()10service.pipe(argosyPattern({ping: 'ping'})).pipe(service)11const argosy = require('argosy')12const argosyPattern = require('argosy-pattern')13const argosyHeader = require('argosy-header')14const service = argosy()15service.pipe(argosyHeader()).pipe(argosyPattern({ping: 'ping'})).pipe(service)16const argosy = require('argosy')17const argosyPattern = require('argosy-pattern')18const argosyHeader = require('argosy-header')19const service = argosy()20service.pipe(argosyPattern({ping: 'ping'})).pipe(argosyHeader()).pipe(service)21const argosy = require('argosy')22const argosyPattern = require('argosy-pattern')23const argosyHeader = require('argosy-header')24const service = argosy()25service.pipe(argosyHeader()).pipe(argosyPattern({ping: 'ping'})).pipe(argosyHeader()).pipe(service)26const argosy = require('argosy')27const argosyPattern = require('argosy-pattern')28const argosyHeader = require('argosy-header')29const service = argosy()30service.pipe(argosyHeader()).pipe(argosyPattern({ping: 'ping'})).pipe(argosyHeader()).pipe(argosyPattern({ping: 'ping'})).pipe(service)31const argosy = require('argosy')32const argosyPattern = require('argosy-pattern

Full Screen

Using AI Code Generation

copy

Full Screen

1var argosy = require('argosy')2var argosyPattern = require('argosy-pattern')3var service = argosy()4service.pipe(argosyHeader({hello: 'world'})).pipe(service)5service.accept({hello: 'world'}, function (message, cb) {6 console.log(message)7 cb(null, 'hello')8})9var argosy = require('argosy')10var argosyPattern = require('argosy-pattern')11var service = argosy()12service.pipe(argosyBody({hello: 'world'})).pipe(service)13service.accept({hello: 'world'}, function (message, cb) {14 console.log(message)15 cb(null, 'hello')16})17var argosy = require('argosy')18var argosyPattern = require('argosy-pattern')19var service = argosy()20service.pipe(argosyHeaderAndBody({hello: 'world'}, {hello: 'world'})).pipe(service)21service.accept({hello: 'world'}, function (message, cb) {22 console.log(message)23 cb(null, 'hello')24})25var argosy = require('argosy')

Full Screen

Using AI Code Generation

copy

Full Screen

1var argosy = require('argosy')2var myService = argosy()3myService.pipe(argosy.accept({hello: 'world'})).pipe(myService)4myService.on('header', function (header) {5 console.log('header', header)6})7var argosyPattern = require('argosy-pattern')8var myService = argosy()9myService.pipe(argosyPattern({hello: 'world'})).pipe(myService)10myService.on('header', function (header) {11 console.log('header', header)12})13var argosyPattern = require('argosy-pattern')14var myService = argosy()15myService.pipe(argosyPattern({hello: 'world'})).pipe(myService)16myService.on('header', function (header) {17 console.log('header', header)18})19var argosyPattern = require('argosy-pattern')20var myService = argosy()21myService.pipe(argosyPattern({hello: 'world'})).pipe(myService)22myService.on('header', function (header) {23 console.log('header', header)24})25var argosyPattern = require('argosy-pattern')26var myService = argosy()27myService.pipe(argosyPattern({hello: 'world'})).pipe(myService)28myService.on('header', function (header) {29 console.log('header', header)30})31var argosyPattern = require('argosy-pattern')32var myService = argosy()33myService.pipe(argosyPattern({hello: 'world'})).pipe(myService)34myService.on('header', function (header) {35 console.log('header', header)36})37var argosyPattern = require('argosy-pattern')38var myService = argosy()39myService.pipe(argosyPattern({hello: 'world'})).pipe(myService)40myService.on('

Full Screen

Using AI Code Generation

copy

Full Screen

1const argosy = require('argosy')2const pattern = require('argosy-pattern')3const service = argosy()4service.accept({role: 'math', cmd: 'sum'}, header('x', 'y', function (msg, cb) {5 cb(null, msg.x + msg.y)6}))7service.pipe(service)8service.act({role: 'math', cmd: 'sum', x: 1, y: 2}, function (err, result) {9})10const argosy = require('argosy')11const pattern = require('argosy-pattern')12const service = argosy()13service.accept({role: 'math', cmd: 'sum'}, header('x', 'y', function (msg, cb) {14 cb(null, msg.x + msg.y)15}))16service.pipe(service)17service.act({role: 'math', cmd: 'sum', x: 1, y: 2}, function (err, result) {18})19const argosy = require('argosy')20const pattern = require('argosy-pattern')21const service = argosy()22service.accept({role: 'math', cmd: 'sum'}, header('x', 'y', function (msg, cb) {23 cb(null, msg.x + msg.y)24}))25service.pipe(service)26service.act({role: 'math', cmd: 'sum', x: 1, y: 2}, function (err, result) {27})28const argosy = require('argosy')29const pattern = require('argosy-pattern')30const service = argosy()31service.accept({role: 'math', cmd: 'sum'}, header('x', 'y', function (msg, cb) {32 cb(null, msg.x + msg.y)33}))34service.pipe(service)35service.act({role: 'math', cmd: 'sum', x: 1,

Full Screen

Using AI Code Generation

copy

Full Screen

1var argosy = require('argosy')2var header = require('argosy-header')3var service = argosy()4service.pipe(header('hello', 'world')).pipe(service)5service.accept({ hello: 'world' }, function (request, callback) {6 callback(null, { world: 'hello' })7})8service.on('request', function (request, callback) {9 console.log(request)10 callback(null, { world: 'hello' })11})12var argosy = require('argosy')13var header = require('argosy-header')14var service = argosy()15service.pipe(header('hello', 'world')).pipe(service)16service.accept({ hello: 'world' }, function (request, callback) {17 callback(null, { world: 'hello' })18})19service.on('request', function (request, callback) {20 console.log(request)21 callback(null, { world: 'hello' })22})23var argosy = require('argosy')24var header = require('argosy-header')25var service = argosy()26service.pipe(header('hello', 'world')).pipe(service)27service.accept({ hello: 'world' }, function (request, callback) {28 callback(null, { world: 'hello' })29})30service.on('request', function (request, callback) {31 console.log(request)32 callback(null, { world: 'hello' })33})34var argosy = require('argosy')35var header = require('argosy-header')36var service = argosy()37service.pipe(header('hello', 'world')).pipe(service)38service.accept({ hello: 'world' }, function (request, callback) {39 callback(null, { world: 'hello' })40})41service.on('request', function (request, callback) {42 console.log(request)43 callback(null, { world: 'hello' })44})45var argosy = require('argosy')46var header = require('argosy-header')47var service = argosy()

Full Screen

Using AI Code Generation

copy

Full Screen

1const argosy = require('argosy')2const pattern = require('argosy-pattern')3const service = argosy()4service.accept({5 header: pattern.header({6 })7}, (msg, cb) => {8 cb(null, { message: 'Hello World!' })9})10service.pipe(process.stdout)11const argosy = require('argosy')12const pattern = require('argosy-pattern')13const service = argosy()14service.accept({15 header: pattern.header({16 })17}, (msg, cb) => {18 cb(null, { message: 'Hello World!' })19})20service.pipe(process.stdout)21const argosy = require('argosy')22const pattern = require('argosy-pattern')23const service = argosy()24service.accept({25 header: pattern.header({26 })27}, (msg, cb) => {28 cb(null, { message: 'Hello World!' })29})30service.pipe(process.stdout)31const argosy = require('argosy')32const pattern = require('argosy-pattern')33const service = argosy()34service.accept({35 header: pattern.header({36 })37}, (msg, cb) => {38 cb(null, { message: 'Hello World!' })39})40service.pipe(process.stdout)41const argosy = require('argosy')42const pattern = require('argosy-pattern')43const service = argosy()44service.accept({45 header: pattern.header({46 })47}, (msg, cb) => {48 cb(null, { message: 'Hello World!' })49})50service.pipe(process.stdout)51const argosy = require('argosy')52const pattern = require('argosy-pattern')53const service = argosy()54service.accept({55 header: pattern.header({

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