query
stringlengths
9
9.05k
document
stringlengths
10
222k
negatives
listlengths
19
20
metadata
dict
create a new branch that merges the clusters of two or more branches that have different clusters
def create_merge_branch(self, cid, merge_child, occluded_parents, fathers, line_num, point_list): saved_parent_nodes = [] for oparent in occluded_parents: parent_node = [pnode for pnode in fathers if pnode.flat_children == oparent][0] parent_node.cluster_id = cid # !!!!!!!!!!...
[ "def merge(c1, c2):\n global number_of_effective_clusters, all_clusters\n number_of_effective_clusters += 1\n new_cluster = Cluster(number_of_effective_clusters)\n new_cluster.guest_ids = list(set(c1.guest_ids + c2.guest_ids))\n new_cluster.mean = get_mean(new_cluster.guest_ids)\n all_clusters.app...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
In order to use this it must be part of a cluster already. This is used in splits or merges to create a new branch and close the old ones Do we create a father less node??
def create_split_branch(self, cid, child_father, father_node, line_num, point_list, lame_parent=0): child, parent = child_father cid_father = father_node.cluster_id bid_father = father_node.branch_id # create the new branch key from the flat child value if type(child)==int: # ...
[ "def create_cluster_branch(self, orphan, line_num): # create cluster\n\n try:\n cluster_id = orphan.flat_value\n except:\n cluster_id = tuple([x.flat_value for x in orphan])\n\n # create a node instance and add it to the graph\n orphan_node = Node(cluster_id, clust...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Take a list of nucleotide sequences, break into all peptides with lengths in L, expanding degenerate bases after peptides are generated, as needed.
def generateMersFromNT(seqList, L=[8, 9, 10, 11]): L = np.array(L) Lnt = L*3 mers = set() for i, seq in enumerate(seqList): print('Working on seq {} of {}'.format(i+1, len(seqList))) dna = skbio.sequence.DNA(seq).degap() for l in Lnt: for starti in range(0, len(dna)-l...
[ "def dinucleotide(sequence):\n\tfrog = []\n\n\tfor i in range(0,(len(sequence)-1)):\n\t\tbp = sequence[i]\n\t\tbp_next = sequence[i+1]\n\t\tbp = bp.capitalize()\n\t\tbp_next = bp_next.capitalize()\n\n\t\tif bp == 'A':\n\t\t\tif bp_next == 'A':\n\t\t\t\tfrog.append([-1,-1,-1,-1])\n\t\t\telif bp_next == 'C':\n\t\t\t\...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Api can limit the number of documents returned
def test_18_api_can_limit_the_number_of_documents(self): res = self.client.get('/documents?limit=1') data = json.loads(res.content) assert len(data['rows']) == 1 assert data['rows'][0]['id'] == 2
[ "def get_latest_documents(context, count=5):\n req = context.get('request')\n qs = Document.objects.published(req)[:count]\n return qs", "def test_19_api_can_offset_the_number_of_documents(self):\n res = self.client.get('/documents?offset=1')\n assert json.loads(res.content)['rows'][0]['id'...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Api supports offsets for documents
def test_19_api_can_offset_the_number_of_documents(self): res = self.client.get('/documents?offset=1') assert json.loads(res.content)['rows'][0]['id'] == 1
[ "def test_offset():\n segmenter = NLTKSentencizer()\n text = ' This , text is... . Amazing !!'\n docs_chunks = segmenter.segment(np.stack([text, text]))\n for chunks in docs_chunks:\n assert len(chunks) - 1 == chunks[-1]['offset']", "def docbyoffset(self, offset):\n # empty documents ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Api can get a particular document
def test_20_api_can_get_a_document(self): res = self.client.get( '/documents/1', format='json' ) self.assertEqual(res.status_code, status.HTTP_200_OK) assert json.loads(res.content)['id'] == 1
[ "def test_get_document_using_get(self):\n pass", "def getDocumentById(self, request):\n R = Resource.objects.getResourceById(request)\n D = Document.objects.get(resource=R)\n return D", "def retrieve_document(doc_id):\n\n db = config_db.get_db()\n success, output = db.get_docum...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Api can update a particular document
def test_21_api_can_update_document(self): res = self.client.put( '/documents/2', {'title': 'new_name'}, format='json' ) self.assertEqual(res.status_code, status.HTTP_200_OK) assert json.loads(res.content)['title'] == 'new_name'
[ "def test_update_document_using_put(self):\n pass", "def update_document(self, doc_id, document):\n request = \"update \" + doc_id + \" \" + document\n response = self.__send_to_server(request)\n return response", "def updateDocument(self,document, documentListName, documentId, respo...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Verifies proxy field label
def test_proxy_fields_label_entity(self, ucc_smartx_selenium_helper, ucc_smartx_rest_helper): proxy = Proxy(TA_NAME, TA_PROXY_URL, TA_CONF, ucc_smartx_selenium_helper, ucc_smartx_rest_helper) self.assert_util( proxy.proxy_enable.get_input_label, 'Enable' ) sel...
[ "def _check_prepopulated_fields_key(self, obj, field_name, label):\n\n try:\n field = obj.model._meta.get_field(field_name)\n except FieldDoesNotExist:\n return refer_to_missing_field(\n field=field_name, option=label, obj=obj, id=\"admin.E027\"\n )\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Verifies the default proxy configurations
def test_proxy_default_configs(self, ucc_smartx_selenium_helper, ucc_smartx_rest_helper): proxy = Proxy(TA_NAME, TA_PROXY_URL, TA_CONF, ucc_smartx_selenium_helper, ucc_smartx_rest_helper) self.assert_util( proxy.proxy_enable.is_checked, False ) self.assert_uti...
[ "def test_proxy_work(self):\n utils.LazyPyraxProxy().cloudservers.should.be\\\n .equal(pyrax.cloudservers)", "def checkproxies():\n puts(green('Checking proxy service available on all demo servers.'))\n demo_servers = list(env.roledefs.items())\n proxy_hosts = []\n for role_name, rol...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Verifies whether the host field in proxy is required and displays an error if left empty
def test_proxy_required_field_host(self, ucc_smartx_selenium_helper, ucc_smartx_rest_helper): proxy = Proxy(TA_NAME, TA_PROXY_URL, TA_CONF, ucc_smartx_selenium_helper, ucc_smartx_rest_helper) proxy.proxy_enable.check() proxy.type.cancel_selected_value() proxy.type.select("http") ...
[ "def test_proxy_host_valid_input(self, ucc_smartx_selenium_helper, ucc_smartx_rest_helper):\n proxy = Proxy(TA_NAME, TA_PROXY_URL, TA_CONF, ucc_smartx_selenium_helper, ucc_smartx_rest_helper)\n proxy.host.set_value(\"abc$$\")\n self.assert_util(\n proxy.save,\n \"Proxy Hos...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Verifies if host contains special characters displays an error
def test_proxy_host_valid_input(self, ucc_smartx_selenium_helper, ucc_smartx_rest_helper): proxy = Proxy(TA_NAME, TA_PROXY_URL, TA_CONF, ucc_smartx_selenium_helper, ucc_smartx_rest_helper) proxy.host.set_value("abc$$") self.assert_util( proxy.save, "Proxy Host should not ...
[ "def test_bad_hostname():\n pytest.xfail(\"Bad hostname.\")\n connect_to_dremio_flight_server_endpoint(\"badHostNamE\",\n \"32010\", \"dremio\", \"dremio123\", False, False, False)", "def is_valid_host_name(hostname):\n if len(hostname) > 255:\n return False\n if hostname[0].isdigit(): ret...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Verifies host field length validation
def test_proxy_host_field_length_validation(self, ucc_smartx_selenium_helper, ucc_smartx_rest_helper): proxy = Proxy(TA_NAME, TA_PROXY_URL, TA_CONF, ucc_smartx_selenium_helper, ucc_smartx_rest_helper) host_value = "a" * 4097 proxy.host.set_value(host_value) self.assert_util( ...
[ "def check_hash_len(hash):\n if len(hash) != 40 + 1:\n raise ProtocolError(\"Invalid hash len!\")", "def test_check_field_length(self):\n form = EditCouponForm(data={\n 'headline': 'This headline is over twenty-five characters'})\n self.assertFalse(form.is_valid())\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
This test case checks list of proxy types present in the drop down
def test_proxy_list_proxy_types(self, ucc_smartx_selenium_helper, ucc_smartx_rest_helper): proxy = Proxy(TA_NAME, TA_PROXY_URL, TA_CONF, ucc_smartx_selenium_helper, ucc_smartx_rest_helper) self.assert_util( proxy.type.list_of_values(), ["http", "socks4", "socks5"] )
[ "def test_proxy_required_field_proxy_type(self, ucc_smartx_selenium_helper, ucc_smartx_rest_helper):\n proxy = Proxy(TA_NAME, TA_PROXY_URL, TA_CONF, ucc_smartx_selenium_helper, ucc_smartx_rest_helper)\n proxy.proxy_enable.check()\n proxy.type.cancel_selected_value()\n proxy.type.select(\...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Verifies whether proxy type is required and displays an error if left empty
def test_proxy_required_field_proxy_type(self, ucc_smartx_selenium_helper, ucc_smartx_rest_helper): proxy = Proxy(TA_NAME, TA_PROXY_URL, TA_CONF, ucc_smartx_selenium_helper, ucc_smartx_rest_helper) proxy.proxy_enable.check() proxy.type.cancel_selected_value() proxy.type.select("http") ...
[ "def test_proxy_required_field_host(self, ucc_smartx_selenium_helper, ucc_smartx_rest_helper):\n proxy = Proxy(TA_NAME, TA_PROXY_URL, TA_CONF, ucc_smartx_selenium_helper, ucc_smartx_rest_helper)\n proxy.proxy_enable.check()\n proxy.type.cancel_selected_value()\n proxy.type.select(\"http\...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Verifies the proxy is saved properly in frontend after saving it
def test_proxy_frontend_validation(self, ucc_smartx_selenium_helper, ucc_smartx_rest_helper): proxy = Proxy(TA_NAME, TA_PROXY_URL, TA_CONF, ucc_smartx_selenium_helper, ucc_smartx_rest_helper) proxy.proxy_enable.check() proxy.type.cancel_selected_value() proxy.type.select("http") ...
[ "def test_proxy_backend_validation(self, ucc_smartx_selenium_helper, ucc_smartx_rest_helper):\n proxy = Proxy(TA_NAME, TA_PROXY_URL, TA_CONF, ucc_smartx_selenium_helper, ucc_smartx_rest_helper)\n proxy.proxy_enable.check()\n proxy.type.cancel_selected_value()\n proxy.type.select(\"http\"...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Verifies the proxy is saved properly in frontend after saving it
def test_proxy_backend_validation(self, ucc_smartx_selenium_helper, ucc_smartx_rest_helper): proxy = Proxy(TA_NAME, TA_PROXY_URL, TA_CONF, ucc_smartx_selenium_helper, ucc_smartx_rest_helper) proxy.proxy_enable.check() proxy.type.cancel_selected_value() proxy.type.select("http") p...
[ "def test_proxy_frontend_validation(self, ucc_smartx_selenium_helper, ucc_smartx_rest_helper):\n proxy = Proxy(TA_NAME, TA_PROXY_URL, TA_CONF, ucc_smartx_selenium_helper, ucc_smartx_rest_helper)\n proxy.proxy_enable.check()\n proxy.type.cancel_selected_value()\n proxy.type.select(\"http\...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Configure Matplotlib to draw figures for my thesis. The `size` argument can be a tuple (width, height) or a string indicating whether it whether the figure takes the `full` text width or a `fraction` of it (in which case the `fraction` can be specified). In both cases, the height is automatically determined using the g...
def _set_rcparams(size, fraction=0.85, subplots=(1, 1)): if type(size) is tuple: figsize = size else: # Set height and width. width = TEXT_WIDTH # Scale height according to golden ratio and number of subplots. height = width / GOLDEN_RATIO # * (subplots[0] / subplots[1])...
[ "def set_figsize(self, sizes):\n self.__figsize = sizes\n return self", "def figsize(scale):\n fig_width_pt = 469.755 # Get this from LaTeX using \\the\\textwidth\n inches_per_pt = 1.0 / 72.27 # Convert pt to inch\n golden_mean = (np.sqrt(5.0) - 1.0) / 2.0 # Aesthetic ratio (you could ch...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Returns number of wires in the circuit.
def num_wires(self) -> int: return self._num_wires
[ "def getNeuronCount(self):\r\n return self.network.neuronCount", "def wiimote_TotalConnected():\n return _wiimote.wiimote_TotalConnected()", "def number_of_nodes(self):\n\t\treturn number_of_nodes(self.network)", "def getNumConnections(self) -> \"int\":\n return _coin.SoField_getNumConnections(...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Tests for various values passed to convert_integer_to_roman_numerals.
def test_convert_integer_to_roman_numerals(self): def assert_convert_integer_to_roman_numerals(integer, roman): self.assertEqual( views.convert_integer_to_roman_numerals(integer), roman ) assert_convert_integer_to_roman_numerals(6, 'VI') assert_conver...
[ "def test_conversion_of_one(self):\n r = RomanNumeral()\n\n self.assertEqual(r.convert(1), 'I')\n self.assertEqual(r.convert(2), 'II')\n self.assertEqual(r.convert(3), 'III')\n self.assertEqual(r.convert(4), 'IV')\n self.assertEqual(r.convert(5), 'V')\n self.assertEq...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Infer the role of the agent from an incoming/outgoing first message
def role_from_first_message(message: Message) -> Dialogue.Role: return DefaultDialogue.Role.AGENT
[ "def role_from_first_message(message: Message) -> Dialogue.Role:\n return BaseOefSearchDialogue.Role.AGENT", "def import_role(self, msg):\n self.role = msg.data", "def get_other_agent(self, agent):\n if agent is None:\n return None\n if agent == self.home_agent:\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Get if it is a seller search.
def is_seller_search(self) -> bool: assert self._is_seller_search is not None, "is_seller_search not set!" return self._is_seller_search
[ "def is_bestseller(self, book) -> bool:\n\n product = WebDriverWait(self.driver, 20).until(\n EC.presence_of_element_located(\n (By.XPATH, '//div[@data-cel-widget=\"search_result_1\"]')\n )\n )\n ans = WebDriverWait(product, 20).until(\n EC.presen...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Infer the role of the agent from an incoming/outgoing first message
def role_from_first_message(message: Message) -> Dialogue.Role: return BaseOefSearchDialogue.Role.AGENT
[ "def role_from_first_message(message: Message) -> Dialogue.Role:\n return DefaultDialogue.Role.AGENT", "def import_role(self, msg):\n self.role = msg.data", "def get_other_agent(self, agent):\n if agent is None:\n return None\n if agent == self.home_agent:\n ret...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Test that accessing the observable return types through qml.operation emit a warning.
def test_obersvablereturntypes_import_warnings(return_type): with pytest.warns(UserWarning, match=r"is deprecated"): getattr(qml.operation, return_type)
[ "def test_observable_not_returned(self, operable_mock_device_2_wires):\n\n def circuit(x):\n qml.RX(x, wires=[0])\n ex = qml.expval(qml.PauliZ(wires=1))\n return qml.expval(qml.PauliZ(wires=0))\n\n node = qml.QNode(circuit, operable_mock_device_2_wires)\n\n with...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Test that an exception is raised if called with wrong number of wires
def test_incorrect_num_wires(self): class DummyOp(qml.operation.Operator): r"""Dummy custom operator""" num_wires = 1 with pytest.raises(ValueError, match="wrong number of wires"): DummyOp(0.5, wires=[0, 1])
[ "def test_check_wires_exception(self, wires):\n with pytest.raises(ValueError, match=\"wires must be a positive integer\"):\n check_wires(wires=wires)", "def test_raises(self):\n with pytest.raises(InstanceCountError):\n self.test_wbn.fit(\n data=SAMPLE_DATASET.d...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Test that an exception is raised if called with identical wires
def test_non_unique_wires(self): class DummyOp(qml.operation.Operator): r"""Dummy custom operator""" num_wires = 1 with pytest.raises(qml.wires.WireError, match="Wires must be unique"): DummyOp(0.5, wires=[1, 1], do_queue=False)
[ "def test_same_wires(self):\n\n with pytest.raises(qml.QuantumFunctionError, match=\"The target wires and estimation wires\"):\n QuantumPhaseEstimation(np.eye(2), target_wires=[0, 1], estimation_wires=[1, 2])", "def test_should_check_raise_multiple_register_errors(self):\n instance = erro...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
r"""Test that initialization of an operator with broadcasted parameters works and sets the ``batch_size`` correctly.
def test_broadcasted_params(self, params, exp_batch_size): class DummyOp(qml.operation.Operator): r"""Dummy custom operator that declares ndim_params as a class property""" ndim_params = (0, 2) num_wires = 1 op = DummyOp(*params, wires=0) assert op.ndim_para...
[ "def test_broadcasted_params(self, params, exp_batch_size):\n import jax\n\n class DummyOp(qml.operation.Operator):\n r\"\"\"Dummy custom operator that declares ndim_params as a class property\"\"\"\n ndim_params = (0, 2)\n num_wires = 1\n\n params = tuple(jax.n...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
r"""Test that initialization of an operator with broadcasted parameters works and sets the ``batch_size`` correctly with Autograd parameters.
def test_broadcasted_params(self, params, exp_batch_size): class DummyOp(qml.operation.Operator): r"""Dummy custom operator that declares ndim_params as a class property""" ndim_params = (0, 2) num_wires = 1 params = tuple(pnp.array(p, requires_grad=True) for p in p...
[ "def test_broadcasted_params(self, params, exp_batch_size):\n import jax\n\n class DummyOp(qml.operation.Operator):\n r\"\"\"Dummy custom operator that declares ndim_params as a class property\"\"\"\n ndim_params = (0, 2)\n num_wires = 1\n\n params = tuple(jax.n...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
r"""Test that initialization of an operator with broadcasted parameters works and sets the ``batch_size`` correctly with JAX parameters.
def test_broadcasted_params(self, params, exp_batch_size): import jax class DummyOp(qml.operation.Operator): r"""Dummy custom operator that declares ndim_params as a class property""" ndim_params = (0, 2) num_wires = 1 params = tuple(jax.numpy.array(p) for p...
[ "def test_broadcasted_params(self, params, exp_batch_size):\n\n class DummyOp(qml.operation.Operator):\n r\"\"\"Dummy custom operator that declares ndim_params as a class property\"\"\"\n ndim_params = (0, 2)\n num_wires = 1\n\n params = tuple(pnp.array(p, requires_gra...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
r"""Test that initialization of an operator with broadcasted parameters works and sets the ``batch_size`` correctly with TensorFlow parameters.
def test_broadcasted_params(self, params, exp_batch_size): import tensorflow as tf class DummyOp(qml.operation.Operator): r"""Dummy custom operator that declares ndim_params as a class property""" ndim_params = (0, 2) num_wires = 1 params = tuple(tf.Variable...
[ "def test_broadcasted_params(self, params, exp_batch_size):\n import jax\n\n class DummyOp(qml.operation.Operator):\n r\"\"\"Dummy custom operator that declares ndim_params as a class property\"\"\"\n ndim_params = (0, 2)\n num_wires = 1\n\n params = tuple(jax.n...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
r"""Test that initialization of an operator with broadcasted parameters works and sets the ``batch_size`` correctly with Torch parameters.
def test_broadcasted_params(self, params, exp_batch_size): import torch class DummyOp(qml.operation.Operator): r"""Dummy custom operator that declares ndim_params as a class property""" ndim_params = (0, 2) num_wires = 1 params = tuple(torch.tensor(p, requir...
[ "def test_broadcasted_params(self, params, exp_batch_size):\n import jax\n\n class DummyOp(qml.operation.Operator):\n r\"\"\"Dummy custom operator that declares ndim_params as a class property\"\"\"\n ndim_params = (0, 2)\n num_wires = 1\n\n params = tuple(jax.n...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Test an error is raised if no wires are passed.
def test_no_wires(self): class DummyOp(qml.operation.Operator): num_wires = 1 num_params = 1 with pytest.raises(ValueError, match="Must specify the wires"): DummyOp(1.234)
[ "def test_check_wires_exception(self, wires):\n with pytest.raises(ValueError, match=\"wires must be a positive integer\"):\n check_wires(wires=wires)", "def test_operation_on_nonexistant_wire(self, operable_mock_device_2_wires):\n\n operable_mock_device_2_wires.num_wires = 2\n\n d...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Tests that we can set the name of an operator
def test_name_setter(self): class DummyOp(qml.operation.Operator): r"""Dummy custom operator""" num_wires = 1 op = DummyOp(wires=0) op.name = "MyOp" assert op.name == "MyOp"
[ "def test_operator_get_operator(self):\n pass", "def test_operator_create_operator(self):\n pass", "def test_explicitly_specified_control_op(self, op, target_name):\n assert _get_target_name(op) == target_name", "def testSetOperator(self):\n parser = expression_parser.EventFilterExpres...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Test has_matrix property detects overriding of `compute_matrix` method.
def test_has_matrix_true(self): class MyOp(qml.operation.Operator): num_wires = 1 @staticmethod def compute_matrix(): return np.eye(2) assert MyOp.has_matrix assert MyOp(wires=0).has_matrix
[ "def test_has_matrix_false(self):\n\n class MyOp(qml.operation.Operator):\n num_wires = 1\n\n assert not MyOp.has_matrix\n assert not MyOp(wires=0).has_matrix", "def _compute_matrix_profile(self):\n raise NotImplementedError", "def has_ub_matrix(self):\n return Fals...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Test has_matrix property defaults to false if `compute_matrix` not overwritten.
def test_has_matrix_false(self): class MyOp(qml.operation.Operator): num_wires = 1 assert not MyOp.has_matrix assert not MyOp(wires=0).has_matrix
[ "def test_has_matrix_true(self):\n\n class MyOp(qml.operation.Operator):\n num_wires = 1\n\n @staticmethod\n def compute_matrix():\n return np.eye(2)\n\n assert MyOp.has_matrix\n assert MyOp(wires=0).has_matrix", "def is_matrix(self):\r\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Test has_matrix with a concrete operation (StronglyEntanglingLayers) that does not have a matrix defined.
def test_has_matrix_false_concrete_template(self): rng = qml.numpy.random.default_rng(seed=42) shape = qml.StronglyEntanglingLayers.shape(n_layers=2, n_wires=2) params = rng.random(shape) op = qml.StronglyEntanglingLayers(params, wires=range(2)) assert not op.has_matrix
[ "def test_has_matrix_false(self):\n\n class MyOp(qml.operation.Operator):\n num_wires = 1\n\n assert not MyOp.has_matrix\n assert not MyOp(wires=0).has_matrix", "def test_has_matrix_true(self):\n\n class MyOp(qml.operation.Operator):\n num_wires = 1\n\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Tests using tf.function with an operation works with and without just in time (JIT) compilation.
def test_with_tf_function(self, jit_compile): import tensorflow as tf class MyRX(qml.RX): @property def ndim_params(self): return self._ndim_params def fun(x): op0 = qml.RX(x, 0) op1 = MyRX(x, 0) # No kwargs fun0 ...
[ "def _generic_test(self,\n f_raw,\n examples,\n input_signature=None,\n skip_modes=None):\n f_tf = None\n if not skip_modes:\n skip_modes = []\n\n if tf_inspect.isfunction(f_raw):\n self.recordProperty('f', tf_inspect.get...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Test that an operation with a gradient recipe that depends on its instantiated parameter values works correctly
def test_grad_recipe_parameter_dependent(self): class DummyOp(qml.operation.Operation): r"""Dummy custom operation""" num_wires = 1 grad_method = "A" @property def grad_recipe(self): x = self.data[0] return ([[1.0, 1.0...
[ "def test_qc_custom_gradient_training_loop_param_learning(self):\n\n tf.compat.v1.reset_default_graph()\n tf.compat.v1.set_random_seed(0)\n np.random.seed(0)\n with tf.device('/cpu:0'):\n inputs = tf.keras.Input(shape=(32, 32, 1,))\n conv_op = tf.keras.layers.Conv2D...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Test that ``get_parameter_shift`` issues a deprecation warning.
def test_warning_get_parameter_shift(self): class DummyOp(qml.operation.Operation): r"""Dummy custom operation""" num_wires = 1 num_params = 1 grad_recipe = ("Dummy recipe",) op = DummyOp(0.1, wires=0) with pytest.warns(UserWarning, match="get_pa...
[ "def test_legacy_deprecated(recwarn):\n warnings.simplefilter('always')\n from luma.led_matrix import legacy\n\n assert len(recwarn) == 1\n w = recwarn.pop(DeprecationWarning)\n\n assert str(w.message) == legacy.deprecation_msg", "def test_deprecated(self):\n @misc.deprecated\n def fu...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Test that ``get_parameter_shift`` raises an Error if no grad_recipe is available, as we no longer assume the twoterm rule by default.
def test_error_get_parameter_shift_no_recipe(self): class DummyOp(qml.operation.Operation): r"""Dummy custom operation""" num_wires = 1 num_params = 1 grad_recipe = (None,) op = DummyOp(0.1, wires=0) with pytest.raises( qml.operation....
[ "def test_warning_get_parameter_shift(self):\n\n class DummyOp(qml.operation.Operation):\n r\"\"\"Dummy custom operation\"\"\"\n num_wires = 1\n num_params = 1\n grad_recipe = (\"Dummy recipe\",)\n\n op = DummyOp(0.1, wires=0)\n with pytest.warns(User...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Test that the correct ``grad_method`` is returned by default if ``parameter_frequencies`` are present.
def test_default_grad_method_with_frequencies(self): class DummyOp(qml.operation.Operation): r"""Dummy custom operation""" num_wires = 1 @property def parameter_frequencies(self): return [(0.4, 1.2)] x = 0.654 op = DummyOp(x, wir...
[ "def test_get_grad_parameters(self):\n self.assertLess(\n 0, len(list(self.instance.get_grad_params())), msg=\"There is not at least one trainable parameter\"\n )\n\n # Check that all the parameters actually require a gradient\n for parameter in self.instance.get_grad_params()...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Test that the correct ``grad_method`` is returned by default if a generator is present to determine parameter_frequencies from.
def test_default_grad_method_with_generator(self): class DummyOp(qml.operation.Operation): r"""Dummy custom operation""" num_wires = 1 def generator(self): return -0.2 * qml.PauliX(wires=self.wires) x = 0.654 op = DummyOp(x, wires=0) ...
[ "def test_get_grad_parameters(self):\n self.assertLess(\n 0, len(list(self.instance.get_grad_params())), msg=\"There is not at least one trainable parameter\"\n )\n\n # Check that all the parameters actually require a gradient\n for parameter in self.instance.get_grad_params()...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Test that the correct ``grad_method`` is returned by default if no information is present to deduce an analytic gradient method.
def test_default_grad_method_numeric(self): class DummyOp(qml.operation.Operation): r"""Dummy custom operation""" num_wires = 1 x = 0.654 op = DummyOp(x, wires=0) assert op.grad_method == "F"
[ "def test_unknown_grad_method_error(self):\n tape = JacobianTape()\n with pytest.raises(ValueError, match=\"Unknown gradient method\"):\n tape.jacobian(None, method=\"unknown method\")", "def has_grad(self) -> bool:\n return self.check_sensi_orders((1,), MODE_FUN)", "def test_bog...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Test that the correct ``grad_method`` is returned by default if a grad_recipe is present.
def test_default_grad_method_with_grad_recipe(self): class DummyOp(qml.operation.Operation): r"""Dummy custom operation""" num_wires = 1 grad_recipe = ["not a recipe"] x = 0.654 op = DummyOp(x, wires=0) assert op.grad_method == "A"
[ "def requires_grad(self):\n return self.param_info.requires_grad", "def has_grad(self) -> bool:\n return self.check_sensi_orders((1,), MODE_FUN)", "def test_unknown_grad_method_error(self):\n tape = JacobianTape()\n with pytest.raises(ValueError, match=\"Unknown gradient method\"):\n...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Test that the correct ``grad_method`` is returned by default if an operation does not have a parameter.
def test_default_grad_no_param(self): class DummyOp(qml.operation.Operation): r"""Dummy custom operation""" num_wires = 1 op = DummyOp(wires=0) assert op.grad_method is None
[ "def test_unknown_grad_method_error(self):\n tape = JacobianTape()\n with pytest.raises(ValueError, match=\"Unknown gradient method\"):\n tape.jacobian(None, method=\"unknown method\")", "def test_bogus_gradient_method_set(self, operable_mock_device_2_wires):\n\n def circuit(x):\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Test that an operation with default parameter frequencies and a single parameter works correctly.
def test_frequencies_default_single_param(self): class DummyOp(qml.operation.Operation): r"""Dummy custom operation""" num_wires = 1 grad_method = "A" def generator(self): return -0.2 * qml.PauliX(wires=self.wires) x = 0.654 op =...
[ "def test_frequencies_default_multi_param(self):\n\n class DummyOp(qml.operation.Operation):\n r\"\"\"Dummy custom operation\"\"\"\n num_params = 3\n num_wires = 1\n grad_method = \"A\"\n\n x = [0.654, 2.31, 0.1]\n op = DummyOp(*x, wires=0)\n w...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Test that an operation with default parameter frequencies and multiple parameters raises an error when calling parameter_frequencies.
def test_frequencies_default_multi_param(self): class DummyOp(qml.operation.Operation): r"""Dummy custom operation""" num_params = 3 num_wires = 1 grad_method = "A" x = [0.654, 2.31, 0.1] op = DummyOp(*x, wires=0) with pytest.raises( ...
[ "def test_wrong_num_of_num_freqs_per_parameter(fun, param, num_freq):\n\n opt = RotosolveOptimizer()\n\n with pytest.raises(ValueError, match=\"The number of the frequency counts\"):\n opt.step(fun, *param, num_freqs=num_freq)", "def test_frequencies_default_single_param(self):\n\n class Dummy...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Test that an operation with parameter frequencies that depend on its instantiated parameter values works correctly
def test_frequencies_parameter_dependent(self, num_param): class DummyOp(qml.operation.Operation): r"""Dummy custom operation""" num_params = num_param num_wires = 1 grad_method = "A" @property def parameter_frequencies(self): ...
[ "def test_frequencies_default_multi_param(self):\n\n class DummyOp(qml.operation.Operation):\n r\"\"\"Dummy custom operation\"\"\"\n num_params = 3\n num_wires = 1\n grad_method = \"A\"\n\n x = [0.654, 2.31, 0.1]\n op = DummyOp(*x, wires=0)\n w...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Test that control_wires defaults to an empty Wires object.
def test_control_wires(self): class DummyOp(qml.operation.Operation): r"""Dummy custom operation""" num_wires = 1 grad_method = None op = DummyOp(1.0, wires=0, id="test") assert op.control_wires == qml.wires.Wires([])
[ "def test_check_wires(self, wires, target):\n res = check_wires(wires=wires)\n assert res == target", "def test_uninitialized_setting(self):\n ...", "def test_wise_config_constructor_defaults(self) -> None:\n wise_config = WiseConfig()\n\n self.assertIsNone(wise_config.weight)...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Test that is_hermitian defaults to False for an Operator
def test_is_hermitian(self): class DummyOp(qml.operation.Operation): r"""Dummy custom operation""" num_wires = 1 grad_method = None op = DummyOp(wires=0) assert op.is_hermitian is False
[ "def test_binary_operator(self):\n t = ExpressionTreeNode.build_tree(['A', 'B', 'or'])\n self.assertFalse(t.is_really_unary)", "def test_operator_get_operator(self):\n pass", "def assertCalcFalse(self, calc, context=None):\n context = context or {}\n self.assertFalse(calc.reso...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Check that the return_type of an observable is initially None
def test_observable_return_type_none(self): class DummyObserv(qml.operation.Observable): r"""Dummy custom observable""" num_wires = 1 grad_method = None assert DummyObserv(0, wires=[1]).return_type is None
[ "def test_builtins_cast_return_none():\n assert m.return_none_string() is None\n assert m.return_none_char() is None\n assert m.return_none_bool() is None\n assert m.return_none_int() is None\n assert m.return_none_float() is None\n assert m.return_none_pair() is None", "def test_return_type_non...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Check that the Observable class inherits from an Operator, not from an Operation
def test_observable_is_not_operation_but_operator(self): assert issubclass(qml.operation.Observable, qml.operation.Operator) assert not issubclass(qml.operation.Observable, qml.operation.Operation)
[ "def test_multiple_inheritance():\n\n class SomeBaseClass(object):\n pass\n\n class SomeBaseAndObservable(SomeBaseClass, Observable):\n def __init__(self):\n super(SomeBaseAndObservable, self).__init__()\n\n def test(self):\n self.trigger('some', True)\n\n def som...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Check that the Observable class inherits from an Operator class as well
def test_observable_is_operation_as_well(self): class DummyObserv(qml.operation.Observable, qml.operation.Operation): r"""Dummy custom observable""" num_wires = 1 grad_method = None assert issubclass(DummyObserv, qml.operation.Operator) assert issubclass(Dum...
[ "def test_multiple_inheritance():\n\n class SomeBaseClass(object):\n pass\n\n class SomeBaseAndObservable(SomeBaseClass, Observable):\n def __init__(self):\n super(SomeBaseAndObservable, self).__init__()\n\n def test(self):\n self.trigger('some', True)\n\n def som...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Checks that the TensorN operator was constructed correctly when multiple modes were specified.
def test_tensor_n_multiple_modes(self): cv_obs = qml.TensorN(wires=[0, 1]) assert isinstance(cv_obs, qml.TensorN) assert cv_obs.wires == Wires([0, 1]) assert cv_obs.ev_order is None
[ "def test_init_fail(self):\n # ------ the following tests should FAIL\n correct_shape = (2, 4, 8)\n size = reduce(lambda x, y: x * y, correct_shape)\n order = len(correct_shape)\n correct_data = np.ones(size).reshape(correct_shape)\n\n # ------ tests that Tensor object can ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Checks that instantiating a TensorN when passing a single mode as a keyword argument returns a NumberOperator.
def test_tensor_n_single_mode_wires_explicit(self): cv_obs = qml.TensorN(wires=[0]) assert isinstance(cv_obs, qml.NumberOperator) assert cv_obs.wires == Wires([0]) assert cv_obs.ev_order == 2
[ "def test_tensor_number_operator(self, tol):\n cutoff_dim = 10\n\n dev = qml.device(\"strawberryfields.fock\", wires=2, cutoff_dim=cutoff_dim)\n\n gate_name = \"TensorN\"\n assert dev.supports_observable(gate_name)\n\n op = qml.TensorN\n sf_expectation = dev._observable_map...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Test that the id attribute of an observable can be set.
def test_id(self): class DummyObserv(qml.operation.Observable): r"""Dummy custom observable""" num_wires = 1 grad_method = None op = DummyObserv(1.0, wires=0, id="test") assert op.id == "test"
[ "def test_set_id(self):\n test_id = 5\n self.test_manager.set_id(test_id)\n self.assertEqual(self.test_manager.get_id(), test_id)\n self.test_manager.set_id(self.NO_ID)\n self.assertEqual(self.test_manager.get_id(), self.NO_ID)", "def test_setValidid(self):\n object1 = Ba...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Test that simplify method returns the same instance.
def test_simplify_method(self): class DummyObserv(qml.operation.Observable): r"""Dummy custom observable""" num_wires = 1 grad_method = None op = DummyObserv(wires=0) sim_op = op.simplify() assert op is sim_op
[ "def test_simplify_unit(self, simplify_unit_test_case: SimplifyUnitTest\n ) -> None:\n # Arrange done in fixtures.\n # Act.\n simplified = unit_analysis.simplify(\n simplify_unit_test_case.to_simplify,\n simplify_unit_test_case.mock_type_factories...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Test that when raising an Operator to a power that is not a number raises a ValueError.
def test_pow_method_with_non_numeric_power_raises_error(self): class DummyOp(qml.operation.Operation): r"""Dummy custom operator""" num_wires = 1 with pytest.raises(ValueError, match="Cannot raise an Operator"): _ = DummyOp(wires=[0]) ** DummyOp(wires=[0])
[ "def test_power_except(self):\n chan = SuperOp(self.depol_sop(1))\n # Non-integer power raises error\n self.assertRaises(QiskitError, chan.power, 0.5)", "def test_raise_error_fewer_than_2_operands(self):\n with pytest.raises(ValueError, match=\"Require at least two operators to combine...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Test the __sum__ dunder method with two operators.
def test_sum_with_operator(self): sum_op = qml.PauliX(0) + qml.RX(1, 0) final_op = qml.op_sum(qml.PauliX(0), qml.RX(1, 0)) # TODO: Use qml.equal when fixed. assert isinstance(sum_op, qml.ops.Sum) for s1, s2 in zip(sum_op.summands, final_op.summands): assert s1.name =...
[ "def test_sum_multi_wire_operator_with_scalar(self):\n sum_op = 5 + qml.CNOT(wires=[0, 1])\n final_op = qml.op_sum(\n qml.CNOT(wires=[0, 1]),\n qml.s_prod(5, qml.prod(qml.Identity(0), qml.Identity(1))),\n )\n # TODO: Use qml.equal when fixed.\n assert isinsta...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Test the __sum__ dunder method with a scalar value.
def test_sum_with_scalar(self): sum_op = 5 + qml.PauliX(0) + 0 final_op = qml.op_sum(qml.PauliX(0), qml.s_prod(5, qml.Identity(0))) # TODO: Use qml.equal when fixed. assert isinstance(sum_op, qml.ops.Sum) for s1, s2 in zip(sum_op.summands, final_op.summands): assert s...
[ "def test_scale_sum(self):\n u = self.abUsage([1,3])\n self.assertEqual(u.scale_sum(12), self.abUsage([3.0, 9.0]))\n self.assertEqual(u.scale_sum(1), self.abUsage([0.25,0.75]))\n #default is sum to 1\n self.assertEqual(u.scale_sum(), self.abUsage([0.25,0.75]))", "def test_sum_mu...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Test the __sum__ dunder method with a multiwire operator and a scalar value.
def test_sum_multi_wire_operator_with_scalar(self): sum_op = 5 + qml.CNOT(wires=[0, 1]) final_op = qml.op_sum( qml.CNOT(wires=[0, 1]), qml.s_prod(5, qml.prod(qml.Identity(0), qml.Identity(1))), ) # TODO: Use qml.equal when fixed. assert isinstance(sum_op, ...
[ "def test_sum_with_scalar(self):\n sum_op = 5 + qml.PauliX(0) + 0\n final_op = qml.op_sum(qml.PauliX(0), qml.s_prod(5, qml.Identity(0)))\n # TODO: Use qml.equal when fixed.\n assert isinstance(sum_op, qml.ops.Sum)\n for s1, s2 in zip(sum_op.summands, final_op.summands):\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Test the __sub__, __rsub__ and __neg__ dunder methods.
def test_sub_rsub_and_neg_dunder_methods(self): sum_op = qml.PauliX(0) - 5 sum_op_2 = -(5 - qml.PauliX(0)) assert np.allclose(a=sum_op.matrix(), b=np.array([[-5, 1], [1, -5]]), rtol=0) assert np.allclose(a=sum_op.matrix(), b=sum_op_2.matrix(), rtol=0) neg_op = -qml.PauliX(0) ...
[ "def test_rsub():\n\tcomplexnr = 2 - Complex(4, 5) - (9 + 2j)\n\tassert complexnr == Complex(-11, -7)", "def test_subtract():\n calc = Calculator(5)\n assert calc.subtract(6) == -1", "def _sub(lhs=None, rhs=None, name=None, attr=None, out=None, **kwargs):\n return (0,)", "def test_subtract_scalar(sel...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Test that the __mul__ dunder method raises an error when using a nonsupported object.
def test_mul_with_not_supported_object_raises_error(self): with pytest.raises(ValueError, match="Cannot multiply Observable by"): _ = "dummy" * qml.PauliX(0)
[ "def test_matmul_with_not_supported_object_raises_error(self):\n with pytest.raises(ValueError, match=\"Can only perform tensor products between operators.\"):\n _ = qml.PauliX(0) @ \"dummy\"", "def test_multiply_except(self):\n chan = SuperOp(self.sopI)\n self.assertRaises(QiskitE...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Test that the __matmul__ dunder method raises an error when using a nonsupported object.
def test_matmul_with_not_supported_object_raises_error(self): with pytest.raises(ValueError, match="Can only perform tensor products between operators."): _ = qml.PauliX(0) @ "dummy"
[ "def test_mul_with_not_supported_object_raises_error(self):\n with pytest.raises(ValueError, match=\"Cannot multiply Observable by\"):\n _ = \"dummy\" * qml.PauliX(0)", "def test_operation_multiply_invalid(self):\n X = qml.PauliX(0)\n Y = qml.CNOT(wires=[0, 1])\n Z = qml.Pau...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Test that inv updates the inverse property in place during queuing.
def test_inv_queuing(self): class DummyOp(qml.operation.Operation): r"""Dummy custom Operation""" num_wires = 1 with qml.tape.QuantumTape() as tape: op = DummyOp(wires=[0]).inv() assert op.inverse is True assert op.inverse is True
[ "def test_inv(self):\n\n operation = CirqOperation(\n lambda a, b, c: [cirq.X, cirq.Ry(a), cirq.Rx(b), cirq.Z, cirq.Rz(c)]\n )\n\n assert not operation.is_inverse\n\n operation.inv()\n\n assert operation.is_inverse\n\n operation.inv()\n\n assert not operat...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Test that the inverse of operations is not currently supported on the default gaussian device
def test_inverse_operations_not_supported(self): dev1 = qml.device("default.gaussian", wires=2) @qml.qnode(dev1) def mean_photon_gaussian(mag_alpha, phase_alpha, phi): qml.Displacement(mag_alpha, phase_alpha, wires=0) qml.Rotation(phi, wires=0).inv() return ...
[ "def test_gaussian(self):\n self.logTestName()\n res = self.H.is_gaussian()\n self.assertFalse(res)", "def test_gaussian(self):\n self.logTestName()\n res = self.H.is_gaussian()\n self.assertTrue(res)", "def test_inverse(self):\n\n\t\tgsm = GSM(3, 10)\n\t\tgsm.initializ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Provides a QNode for the subsequent tests of inv
def qnode_for_inverse(self, mock_device): def circuit(x): qml.RZ(x, wires=[1]).inv() qml.RZ(x, wires=[1]).inv().inv() return qml.expval(qml.PauliX(0)), qml.expval(qml.PauliZ(1)) node = qml.QNode(circuit, mock_device) node.construct([1.0], {}) return...
[ "def test_inv_queuing(self):\n\n class DummyOp(qml.operation.Operation):\n r\"\"\"Dummy custom Operation\"\"\"\n num_wires = 1\n\n with qml.tape.QuantumTape() as tape:\n op = DummyOp(wires=[0]).inv()\n assert op.inverse is True\n\n assert op.inverse i...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Test that the inverse of an operation is added to the QNode queue and the operation is an instance of the original class
def test_operation_inverse_defined(self, qnode_for_inverse): assert qnode_for_inverse.qtape.operations[0].name == "RZ.inv" assert qnode_for_inverse.qtape.operations[0].inverse assert issubclass(qnode_for_inverse.qtape.operations[0].__class__, qml.operation.Operation) assert qnode_for_inv...
[ "def test_inv_queuing(self):\n\n class DummyOp(qml.operation.Operation):\n r\"\"\"Dummy custom Operation\"\"\"\n num_wires = 1\n\n with qml.tape.QuantumTape() as tape:\n op = DummyOp(wires=[0]).inv()\n assert op.inverse is True\n\n assert op.inverse i...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Test construction of a tensor product
def test_construct(self): X = qml.PauliX(0) Y = qml.PauliY(2) T = Tensor(X, Y) assert T.obs == [X, Y] T = Tensor(T, Y) assert T.obs == [X, Y, Y] with pytest.raises( ValueError, match="Can only perform tensor products between observables" ): ...
[ "def test_prod_(self):\n self.run_test(\"\"\"\n def np_prod_(a):\n return a.prod()\"\"\",\n numpy.arange(10),\n np_prod_=[NDArray[int,:]])", "def test_operation_multiply_invalid(self):\n X = qml.PauliX(0)\n Y = qml.CNOT(wires...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Test the queuing of a Tensor object.
def test_queuing_defined_outside(self): op1 = qml.PauliX(0) op2 = qml.PauliY(1) T = Tensor(op1, op2) with qml.tape.QuantumTape() as tape: T.queue() assert len(tape.queue) == 1 assert tape.queue[0] is T assert tape._queue[T] == {"owns": (op1, op2)}
[ "def test_queuing(self):\n\n with qml.tape.QuantumTape() as tape:\n op1 = qml.PauliX(0)\n op2 = qml.PauliY(1)\n T = Tensor(op1, op2)\n\n assert len(tape.queue) == 3\n assert tape.queue[0] is op1\n assert tape.queue[1] is op2\n assert tape.queue[2] ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Test the queuing of a Tensor object.
def test_queuing(self): with qml.tape.QuantumTape() as tape: op1 = qml.PauliX(0) op2 = qml.PauliY(1) T = Tensor(op1, op2) assert len(tape.queue) == 3 assert tape.queue[0] is op1 assert tape.queue[1] is op2 assert tape.queue[2] is T a...
[ "def test_queuing_defined_outside(self):\n\n op1 = qml.PauliX(0)\n op2 = qml.PauliY(1)\n T = Tensor(op1, op2)\n\n with qml.tape.QuantumTape() as tape:\n T.queue()\n\n assert len(tape.queue) == 1\n assert tape.queue[0] is T\n\n assert tape._queue[T] == {\"o...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Tests the tensorspecific matmul method updates queuing metadata.
def test_queuing_tensor_matmul(self): with qml.tape.QuantumTape() as tape: op1 = qml.PauliX(0) op2 = qml.PauliY(1) t = Tensor(op1, op2) op3 = qml.PauliZ(2) t2 = t @ op3 assert tape._queue[t2] == {"owns": (op1, op2, op3)} assert tape....
[ "def test_queuing_tensor_rmatmul(self):\n\n with qml.tape.QuantumTape() as tape:\n op1 = qml.PauliX(0)\n op2 = qml.PauliY(1)\n\n t1 = op1 @ op2\n\n op3 = qml.PauliZ(3)\n\n t2 = op3 @ t1\n\n assert tape._queue[op3] == {\"owner\": t2}\n asser...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Tests the tensorspecific matmul method when components are defined outside the queuing context.
def test_queuing_tensor_matmul_components_outside(self): op1 = qml.PauliX(0) op2 = qml.PauliY(1) t1 = Tensor(op1, op2) with qml.tape.QuantumTape() as tape: op3 = qml.PauliZ(2) t2 = t1 @ op3 assert len(tape._queue) == 2 assert tape._queue[op3] ==...
[ "def test_queuing_tensor_matmul(self):\n\n with qml.tape.QuantumTape() as tape:\n op1 = qml.PauliX(0)\n op2 = qml.PauliY(1)\n t = Tensor(op1, op2)\n\n op3 = qml.PauliZ(2)\n t2 = t @ op3\n\n assert tape._queue[t2] == {\"owns\": (op1, op2, op3)}\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Tests tensorspecific rmatmul updates queuing metatadata.
def test_queuing_tensor_rmatmul(self): with qml.tape.QuantumTape() as tape: op1 = qml.PauliX(0) op2 = qml.PauliY(1) t1 = op1 @ op2 op3 = qml.PauliZ(3) t2 = op3 @ t1 assert tape._queue[op3] == {"owner": t2} assert tape._queue[t2] ==...
[ "def test_queuing_tensor_matmul(self):\n\n with qml.tape.QuantumTape() as tape:\n op1 = qml.PauliX(0)\n op2 = qml.PauliY(1)\n t = Tensor(op1, op2)\n\n op3 = qml.PauliZ(2)\n t2 = t @ op3\n\n assert tape._queue[t2] == {\"owns\": (op1, op2, op3)}\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Test that Tensors are labelled as expected
def test_label(self): x = qml.PauliX(0) y = qml.PauliZ(2) T = Tensor(x, y) assert T.label() == "X@Z" assert T.label(decimals=2) == "X@Z" assert T.label(base_label=["X0", "Z2"]) == "X0@Z2" with pytest.raises(ValueError, match=r"Tensor label requires"): ...
[ "def test_label():\n label_path = pjoin(data_path, \"label\", \"lh.BA1.label\")\n label = read_label(label_path)\n # XXX : test more\n assert_true(np.all(label > 0))\n\n labels, scalars = read_label(label_path, True)\n assert_true(np.all(labels == label))\n assert_true(len(labels) == len(scalar...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Test that multiplying a tensor by an observable produces a tensor
def test_multiply_tensor_obs(self): X = qml.PauliX(0) Y = qml.Hadamard(2) Z = qml.PauliZ(1) t = X @ Y t = t @ Z assert isinstance(t, Tensor) assert t.obs == [X, Y, Z]
[ "def test_subscribe_tensors_on_different_devices(self):\n c1 = constant_op.constant(10)\n c2 = constant_op.constant(20)\n\n with ops.device('cpu:0'):\n add = math_ops.add(c1, c2)\n\n with ops.device('cpu:1'):\n mul = math_ops.multiply(c1, c2)\n\n def sub(t):\n return t\n\n add_sub =...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Test that multiplying a tensor by a tensor produces a tensor
def test_multiply_tensor_tensor(self): X = qml.PauliX(0) Y = qml.PauliY(2) Z = qml.PauliZ(1) H = qml.Hadamard(3) t1 = X @ Y t2 = Z @ H t = t2 @ t1 assert isinstance(t, Tensor) assert t.obs == [Z, H, X, Y]
[ "def __mul__(self, other: Union['Tensor', TensorableT]) -> 'Tensor':\r\n return mul(self, assure_tensor(other))", "def mul(self, other: Union['Tensor', TensorableT]) -> 'Tensor':\r\n return mul(self, other)", "def test_queuing_tensor_matmul(self):\n\n with qml.tape.QuantumTape() as tape:\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Test that multiplying a tensor inplace produces a tensor
def test_multiply_tensor_in_place(self): X = qml.PauliX(0) Y = qml.PauliY(2) Z = qml.PauliZ(1) H = qml.Hadamard(3) t = X t @= Y t @= Z @ H assert isinstance(t, Tensor) assert t.obs == [X, Y, Z, H]
[ "def __mul__(self, other: Union['Tensor', TensorableT]) -> 'Tensor':\r\n return mul(self, assure_tensor(other))", "def vm_impl_mat_mul(self):\n\n def vm_impl(x, w):\n x = x.asnumpy()\n w = w.asnumpy()\n if self.transpose_a:\n x = x.transpose()\n if self.transpose_b...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Test that an exception is raised if an observable is multiplied by an operation
def test_operation_multiply_invalid(self): X = qml.PauliX(0) Y = qml.CNOT(wires=[0, 1]) Z = qml.PauliZ(0) with pytest.raises( ValueError, match="Can only perform tensor products between observables" ): T = X @ Z T @ Y with pytest.rais...
[ "def test_multiply_except(self):\n chan = SuperOp(self.sopI)\n self.assertRaises(QiskitError, chan.multiply, 's')\n self.assertRaises(QiskitError, chan.multiply, chan)", "def test_mul_with_not_supported_object_raises_error(self):\n with pytest.raises(ValueError, match=\"Cannot multiply...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Test that the correct eigenvalues are returned for the Tensor
def test_eigvals(self): X = qml.PauliX(0) Y = qml.PauliY(2) t = Tensor(X, Y) assert np.array_equal(t.eigvals(), np.kron([1, -1], [1, -1])) # test that the eigvals are now cached and not recalculated assert np.array_equal(t._eigvals_cache, t.eigvals())
[ "def test_eigen_caching(self):\n diag_op = ValidOp(*self.simple_operands)\n eig_decomp = diag_op.eigendecomposition\n\n eig_vecs = eig_decomp[\"eigvec\"]\n eig_vals = eig_decomp[\"eigval\"]\n\n eigs_cache = diag_op._eigs[diag_op.hash]\n cached_vecs = eigs_cache[\"eigvec\"]\...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Test that the correct eigenvalues are returned for the Tensor containing an Hermitian observable
def test_eigvals_hermitian(self, tol): X = qml.PauliX(0) hamiltonian = np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0]]) Herm = qml.Hermitian(hamiltonian, wires=[1, 2]) t = Tensor(X, Herm) d = np.kron(np.array([1.0, -1.0]), np.array([-1.0, 1.0, 1.0, 1.0])) ...
[ "def test_eigenvals_calcfunction(\n configure, # pylint: disable=unused-argument\n sample,\n):\n eigenvals_calcfunction = CalculationFactory(\n 'tbmodels.calcfunctions.eigenvals'\n )\n tb_model = DataFactory('singlefile')(file=sample('model.hdf5'))\n\n k_mesh = DataFactory('array.kpoints')...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Test that the correct eigenvalues are returned for the Tensor containing an Identity
def test_eigvals_identity(self, tol): X = qml.PauliX(0) Iden = qml.Identity(1) t = Tensor(X, Iden) d = np.kron(np.array([1.0, -1.0]), np.array([1.0, 1.0])) t = t.eigvals() assert np.allclose(t, d, atol=tol, rtol=0)
[ "def test_eigen_caching(self):\n diag_op = ValidOp(*self.simple_operands)\n eig_decomp = diag_op.eigendecomposition\n\n eig_vecs = eig_decomp[\"eigvec\"]\n eig_vals = eig_decomp[\"eigval\"]\n\n eigs_cache = diag_op._eigs[diag_op.hash]\n cached_vecs = eigs_cache[\"eigvec\"]\...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Test that the diagonalizing gate set numerically diagonalizes the tensor observable
def test_diagonalizing_gates_numerically_diagonalizes(self, tol): # create a tensor observable acting on consecutive wires H = np.diag([1, 2, 3, 4]) O = qml.PauliX(0) @ qml.PauliY(1) @ qml.Hermitian(H, [2, 3]) O_mat = O.matrix() diag_gates = O.diagonalizing_gates() # g...
[ "def test_diagonalizing_gates_non_overlapping(self):\n diag_op = ValidOp(qml.PauliZ(wires=0), qml.Identity(wires=1))\n assert diag_op.diagonalizing_gates() == []", "def test_diagonalizing_gates_overlapping(self):\n diag_op = ValidOp(qml.S(0), qml.PauliX(0))\n diagonalizing_gates = diag...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Test that an exception is raised if a wire_order is passed to the matrix method
def test_matrix_wire_order_not_implemented(self): O = qml.PauliX(0) @ qml.PauliY(1) with pytest.raises(NotImplementedError, match="wire_order"): O.matrix(wire_order=[1, 0])
[ "def test_sparse_matrix_undefined(self):\n with pytest.raises(NotImplementedError):\n MyOp(wires=\"a\").sparse_matrix(wire_order=[\"a\", \"b\"])\n with pytest.raises(qml.operation.SparseMatrixUndefinedError):\n MyOp.compute_sparse_matrix()\n with pytest.raises(qml.operatio...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Tests that a warning is raised if the wires the factors in the tensor product act on have partial overlaps.
def test_tensor_matrix_partial_wires_overlap_warning(self, tol): H = np.diag([1, 2, 3, 4]) O1 = qml.PauliX(0) @ qml.Hermitian(H, [0, 1]) O2 = qml.Hermitian(H, [0, 1]) @ qml.PauliY(1) for O in (O1, O2): with pytest.warns(UserWarning, match="partially overlapping"): ...
[ "def test_dimension_warning(self):\n np.random.seed(0)\n X = np.random.rand(3, 10)\n with pytest.warns(UserWarning, match=\"has more columns than rows\") as w:\n linmdtw.linmdtw(X, X)\n with pytest.warns(UserWarning, match=\"has more columns than rows\") as w:\n lin...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Tests that a warning is raised if wires occur in multiple of the factors in the tensor product, leading to a wronglysized matrix.
def test_tensor_matrix_too_large_warning(self, tol): O = qml.PauliX(0) @ qml.PauliX(1) @ qml.PauliX(0) with pytest.warns(UserWarning, match="The size of the returned matrix"): O.matrix()
[ "def test_dimension_warning(self):\n np.random.seed(0)\n X = np.random.rand(3, 10)\n with pytest.warns(UserWarning, match=\"has more columns than rows\") as w:\n linmdtw.linmdtw(X, X)\n with pytest.warns(UserWarning, match=\"has more columns than rows\") as w:\n lin...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Tests that the non_identity_obs property returns a list that contains no Identity instances.
def test_non_identity_obs(self, tensor_observable, expected): O = tensor_observable for idx, obs in enumerate(O.non_identity_obs): assert type(obs) == type(expected[idx]) assert obs.wires == expected[idx].wires
[ "def test_list_of_unallocated_people(self):\r\n self.assertIsNotNone(self.amity.get_a_list_of_unallocated_people())", "def get_not_verified_nins_list(request, user):\n active_nins = user.get_nins()\n nins = []\n verifications = request.db.verifications\n not_verified_nins = verifications.find({...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Tests that the prune method returns the expected Tensor or single nonTensor Observable.
def test_prune(self, tensor_observable, expected): O = tensor_observable O_expected = expected O_pruned = O.prune() assert type(O_pruned) == type(expected) assert O_pruned.wires == expected.wires
[ "def test_not_break_torch(self):\n length = 5\n a = torch.zeros(length)\n b = torch.zeros(length)\n self.assertEqual(len(a == b), length)\n self.assertTrue(torch.all(a == b))\n\n c = Tensor(torch.ones(5))\n # If Tensor is either argument, it uses the equality method ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Tests that pruning a tensor to a tensor in a tape context registers the pruned tensor as owned by the measurement, and turns the original tensor into an orphan without an owner.
def test_prune_while_queueing_return_tensor(self): with qml.tape.QuantumTape() as tape: # we assign operations to variables here so we can compare them below a = qml.PauliX(wires=0) b = qml.PauliY(wires=1) c = qml.Identity(wires=2) T = qml.operation.T...
[ "def prune(tp):\n if isinstance(tp, TypeVariable):\n if tp.instance is not None:\n tp.instance = prune(tp.instance)\n return tp.instance\n return tp", "def test_tucker_dropout():\n shape = (10, 11, 12)\n rank = (7, 8, 9)\n tensor = FactorizedTensor.new(shape, rank=rank,...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Tests that pruning a tensor to an observable in a tape context registers the pruned observable as owned by the measurement, and turns the original tensor into an orphan without an owner.
def test_prune_while_queueing_return_obs(self): with qml.tape.QuantumTape() as tape: a = qml.PauliX(wires=0) c = qml.Identity(wires=2) T = qml.operation.Tensor(a, c) T_pruned = T.prune() m = qml.expval(T_pruned) ann_queue = tape._queue ...
[ "def prune(tp):\n if isinstance(tp, TypeVariable):\n if tp.instance is not None:\n tp.instance = prune(tp.instance)\n return tp.instance\n return tp", "def test_owner_no_ownership(self):\n self.assert_ownership(True)", "def hint_xobj_notheld(actionsystem, action) :\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Tests that the correct sparse matrix representation is used when the custom wires swap the order.
def test_sparse_matrix_swapped_wires(self): t = qml.PauliX(0) @ qml.PauliZ(1) s = t.sparse_matrix(wires=[1, 0]) assert np.allclose(s.data, [1, 1, -1, -1]) assert np.allclose(s.indices, [1, 0, 3, 2]) assert np.allclose(s.indptr, [0, 1, 2, 3, 4])
[ "def test_sparse_matrix_extra_wire(self):\n\n t = qml.PauliX(0) @ qml.PauliZ(1)\n s = t.sparse_matrix(wires=[0, 1, 2])\n\n assert s.shape == (8, 8)\n assert np.allclose(s.data, [1.0, 1.0, -1.0, -1.0, 1.0, 1.0, -1.0, -1.0])\n assert np.allclose(s.indices, [4, 5, 6, 7, 0, 1, 2, 3])\...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Tests that the correct sparse matrix representation is used when the custom wires add an extra wire with an implied identity operation.
def test_sparse_matrix_extra_wire(self): t = qml.PauliX(0) @ qml.PauliZ(1) s = t.sparse_matrix(wires=[0, 1, 2]) assert s.shape == (8, 8) assert np.allclose(s.data, [1.0, 1.0, -1.0, -1.0, 1.0, 1.0, -1.0, -1.0]) assert np.allclose(s.indices, [4, 5, 6, 7, 0, 1, 2, 3]) asse...
[ "def test_sparse_matrix_undefined(self):\n with pytest.raises(NotImplementedError):\n MyOp(wires=\"a\").sparse_matrix(wire_order=[\"a\", \"b\"])\n with pytest.raises(qml.operation.SparseMatrixUndefinedError):\n MyOp.compute_sparse_matrix()\n with pytest.raises(qml.operatio...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Tests that an error is raised if the sparse matrix is computed for a tensor whose constituent operations are not all singlequbit gates.
def test_sparse_matrix_error(self): t = qml.PauliX(0) @ qml.Hermitian(np.eye(4), wires=[1, 2]) with pytest.raises(ValueError, match="Can only compute"): t.sparse_matrix()
[ "def test_sparse_matrix_undefined(self):\n with pytest.raises(NotImplementedError):\n MyOp(wires=\"a\").sparse_matrix(wire_order=[\"a\", \"b\"])\n with pytest.raises(qml.operation.SparseMatrixUndefinedError):\n MyOp.compute_sparse_matrix()\n with pytest.raises(qml.operatio...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Tests the data() method for Tensors and Observables
def test_data(self): obs = qml.PauliZ(0) data = obs._obs_data() assert data == {("PauliZ", Wires(0), ())} obs = qml.PauliZ(0) @ qml.PauliX(1) data = obs._obs_data() assert data == {("PauliZ", Wires(0), ()), ("PauliX", Wires(1), ())} obs = qml.Hermitian(np.arr...
[ "def test_temperature_data(self):\n self.assertEqual(self.thermodata.Tdata.value_si.shape, self.Tdata.shape)\n for T, T0 in zip(self.thermodata.Tdata.value_si, self.Tdata):\n self.assertAlmostEqual(T, T0, 4)", "def test_got_data(self):\n # Create and initialize the instrument drive...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Tests addition between Tensors and Observables
def test_addition(self, obs1, obs2, obs): assert obs.compare(obs1 + obs2)
[ "def test_subscribe_tensors_on_different_devices(self):\n c1 = constant_op.constant(10)\n c2 = constant_op.constant(20)\n\n with ops.device('cpu:0'):\n add = math_ops.add(c1, c2)\n\n with ops.device('cpu:1'):\n mul = math_ops.multiply(c1, c2)\n\n def sub(t):\n return t\n\n add_sub =...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Tests adding Tensors and Observables to zero
def test_add_zero(self, obs): assert obs.compare(obs + 0) assert obs.compare(0 + obs) assert obs.compare(obs + 0.0) assert obs.compare(0.0 + obs) assert obs.compare(obs + 0e1) assert obs.compare(0e1 + obs)
[ "def test_sensor_init():\n assert len(app.binary_sensors) > 0", "def test_observation_zeroing(self):\n obs_shape = (84, 84, 1)\n er = ExperienceReplay(5, obs_shape)\n\n for terminal_idx in range(5):\n obs_ = []\n obs_next_ = []\n for i in range(1, 6):\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Tests subtraction between Tensors and Observables
def test_subtraction(self, obs1, obs2, obs): assert obs.compare(obs1 - obs2)
[ "def test_subscribe_tensors_on_different_devices(self):\n c1 = constant_op.constant(10)\n c2 = constant_op.constant(20)\n\n with ops.device('cpu:0'):\n add = math_ops.add(c1, c2)\n\n with ops.device('cpu:1'):\n mul = math_ops.multiply(c1, c2)\n\n def sub(t):\n return t\n\n add_sub =...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Tests the tensor product between Observables
def test_tensor_product(self, obs1, obs2, res): assert res.compare(obs1 @ obs2)
[ "def test_subscribe_tensors_on_different_devices(self):\n c1 = constant_op.constant(10)\n c2 = constant_op.constant(20)\n\n with ops.device('cpu:0'):\n add = math_ops.add(c1, c2)\n\n with ops.device('cpu:1'):\n mul = math_ops.multiply(c1, c2)\n\n def sub(t):\n return t\n\n add_sub =...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Tests that custom error is raised in the default matrix representation.
def test_matrix_undefined(self): with pytest.raises(qml.operation.MatrixUndefinedError): MyOp.compute_matrix() with pytest.raises(qml.operation.MatrixUndefinedError): op.matrix()
[ "def test_incompatible_dimensions(self, matrices):\n # Instantiate 5x10, 10x5, and 10x10 matrices as Matrix class\n square_mat = chap5.Matrix(matrices.square)\n half_row_mat = chap5.Matrix(matrices.half_row)\n half_col_mat = chap5.Matrix(matrices.half_col)\n # Verify Matrix class ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Tests that custom error is raised in the default terms representation.
def test_terms_undefined(self): with pytest.raises(qml.operation.TermsUndefinedError): MyOp.compute_terms(wires=[1]) with pytest.raises(qml.operation.TermsUndefinedError): op.terms()
[ "def test_custom_formatting():\r\n \r\n try: SampleAPI.execute('custom_err.fail')\r\n except Exception, e:\r\n assert e.data['error'] == True\r\n assert 'desc' in e.data\r\n assert e.data['num'] == 99\r\n # hook can modified the error instance directly\r\n assert e.http_s...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Tests that custom error is raised in the default sparse matrix representation.
def test_sparse_matrix_undefined(self): with pytest.raises(NotImplementedError): MyOp(wires="a").sparse_matrix(wire_order=["a", "b"]) with pytest.raises(qml.operation.SparseMatrixUndefinedError): MyOp.compute_sparse_matrix() with pytest.raises(qml.operation.SparseMatrixUn...
[ "def test_sparse_matrix_error(self):\n\n t = qml.PauliX(0) @ qml.Hermitian(np.eye(4), wires=[1, 2])\n with pytest.raises(ValueError, match=\"Can only compute\"):\n t.sparse_matrix()", "def test_sparse_csr_check():\n dense = _dense_matrix_example()\n shape, data, channels, spikes_ptr...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }