{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "0149f787",
   "metadata": {},
   "source": [
    "# How to Combine Samples from Different Parameter Sets"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "855c99a3",
   "metadata": {},
   "source": [
    "The `povm-toolbox` allows you to run a parameterized quantum circuit and efficiently collect samples for multiple parameter sets -- all through a single Primitive Unified Bloc (PUB). This flexibility is powerful, but it raises an important question: Should you combine the resulting samples, or treat them separately?\n",
    "\n",
    "> **Note**:\n",
    "> One parameter set is defined as a set of values that fully fix a parametrized circuit. Check [our tutorial](https://qiskit-community.github.io/povm-toolbox/tutorials/povm_sampler_pub.html) on `POVMSamplerPUB` objects for more details.\n",
    "\n",
    "This guide walks you through how to combine or isolate samples depending on your analysis goals -- whether you're working with raw measurement counts, analyzing sample distributions, or estimating expectation values."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c8a7757f",
   "metadata": {},
   "source": [
    "As a general guideline, we follow the default behaviors established by the Qiskit SDK:\n",
    "\n",
    "* Expectation Values: The [Qiskit Estimator](https://docs.quantum.ibm.com/guides/get-started-with-primitives#get-started-with-estimator) computes expectation values **separately** for each individual parameter set.\n",
    "* Samples and Counts: By default, the [Qiskit Sampler](https://docs.quantum.ibm.com/guides/get-started-with-primitives#get-started-with-sampler), on the other hand, **aggregates** (unions) samples across all parameter sets.\n",
    "\n",
    "We align with those defaults. However, the `povm-toolbox` always gives you full control -- allowing you to explicitly specify whether to combine or separate data, depending on your needs."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c34858c7",
   "metadata": {},
   "source": [
    "## Define your experiment(s)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c0c33e87",
   "metadata": {},
   "source": [
    "Start by defining a parametrized quantum circuit."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "e65b5268",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAATEAAADuCAYAAABRejAmAAAAOnRFWHRTb2Z0d2F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DEiDROr9cjK68Ux1IvoOTydXkCwMHOWva2+nZ3g7PTXW5OpgiGGBEpjWcniUhpDDEiUhpDjIiUxhAjIqUxxIhIaQwxIlIaQ4yIlMYQIyKlMcSISGkMMSJSGkOMiJTGECMipTHEiEhpDDEiUhpDjIiUxhAjIqUxxIhIaQwxIlIaQ4yIlMYQIyKlMcSISGkMMSJSGkOMiJTGECMipTHEiEhpDDEiUhpDjIiUxhAjIqUxxIhIaQwxIlIaQ4yIoLL/BztRfM6WvfOJAAAAAElFTkSuQmCC",
      "text/plain": [
       "<Figure size 371.107x284.278 with 1 Axes>"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np\n",
    "from qiskit.circuit import Parameter, QuantumCircuit\n",
    "\n",
    "qc = QuantumCircuit(3)\n",
    "\n",
    "theta = Parameter(\"theta\")\n",
    "qc.ry(theta, 0)\n",
    "qc.cx(0, 1)\n",
    "qc.cx(1, 2)\n",
    "qc.draw(\"mpl\", style=\"iqp\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c2f84b24",
   "metadata": {},
   "source": [
    "### Understanding the shape of a PUB\n",
    "\n",
    "In general, the array of parameter values in a PUB has the shape $(n_1, ..., n_N, p)$, called the _shape of the PUB_, where\n",
    "- the last dimension corresponds to the _parameter set_, which is always of dimension 1 and whose length, $p$, equals the number of parameters in the circuit;\n",
    "- the leading dimensions form the _binding array_, where each entry represents a single parameter set of size $p$. The binding array is $N$-dimensional.\n",
    "\n",
    "> **Note**:\n",
    "> the binding array may be zero-dimensional resulting in a PUB of shape $(p,)$, which indicates that a single parameter set is provided.\n",
    "\n",
    "In our current example, the quantum circuit has exactly one parameter, therefore a \"parameter set\" will simply be a list with one scalar element.\n",
    "\n",
    "Let’s consider three scenarios:\n",
    "<ol type=\"a\">\n",
    "  <li>One parameter set is submitted, as a PUB of shape (1,); therefore, the corresponding binding array is 0-dimensional,</li>\n",
    "  <li>Two parameter sets are submitted, as a PUB of shape (2,1); therefore, the corresponding binding array is 1-dimensional and of shape (2,), and </li>\n",
    "  <li>Six parameter sets are submitted, as a PUB of shape (3,2,1); therefore, the corresponding binding array is 2-dimensional and of shape (3,2).</li>\n",
    "</ol>\n",
    "\n",
    "> **Note**:\n",
    "> when the circuit has only one parameter, the last dimension of the PUB can be squeezed. In such a case, this will be automatically detected internally and the missing dimension will be added. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "7b01bdcf",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Shape of binding array 0: ()\n",
      "Shape of binding array 1: (2,)\n",
      "Shape of binding array 2: (3, 2)\n"
     ]
    }
   ],
   "source": [
    "pv_0 = np.asarray([np.pi / 2])\n",
    "pub_0 = (qc, pv_0)\n",
    "print(f\"Shape of binding array 0: {pv_0.shape[:-1]}\")\n",
    "\n",
    "pv_1 = np.asarray([[0], [np.pi / 2]])\n",
    "pub_1 = (qc, pv_1)\n",
    "print(f\"Shape of binding array 1: {pv_1.shape[:-1]}\")\n",
    "\n",
    "pv_2 = np.asarray(\n",
    "    [\n",
    "        [[0], [np.pi / 2]],\n",
    "        [[0.1], [np.pi / 2 + 0.1]],\n",
    "        [[0.2], [np.pi / 2 + 0.2]],\n",
    "    ]\n",
    ")\n",
    "pub_2 = (qc, pv_2)\n",
    "print(f\"Shape of binding array 2: {pv_2.shape[:-1]}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6e91d183",
   "metadata": {},
   "source": [
    "We now set up a basic classical shadows POVM and generate the results to be post-processed in the rest of this guide.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "b2bd5594",
   "metadata": {},
   "outputs": [],
   "source": [
    "from povm_toolbox.library import ClassicalShadows\n",
    "from povm_toolbox.sampler import POVMSampler\n",
    "from qiskit.primitives import StatevectorSampler as BaseSampler\n",
    "\n",
    "povm = ClassicalShadows(3)\n",
    "povm_sampler = POVMSampler(sampler=BaseSampler())\n",
    "povm_job = povm_sampler.run([pub_0, pub_1, pub_2], shots=64, povm=povm)\n",
    "primitive_result = povm_job.result()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e32c5b07",
   "metadata": {},
   "source": [
    "## 1) Expectation Values"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3c3de3bb",
   "metadata": {},
   "source": [
    "### Default: compute expectation values separately for each individual parameter sets."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "819fe72b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Expectation values of PUB 0:\n",
      "-0.4687500000000005\n",
      "\n",
      "Expectation values of PUB 1:\n",
      "[1.03125  0.140625]\n",
      "\n",
      "Expectation values of PUB 2:\n",
      "[[ 0.984375  0.046875]\n",
      " [ 0.84375   0.46875 ]\n",
      " [ 1.171875 -0.140625]]\n",
      "\n"
     ]
    }
   ],
   "source": [
    "from povm_toolbox.post_processor import POVMPostProcessor\n",
    "from qiskit.quantum_info import SparsePauliOp\n",
    "\n",
    "obs = SparsePauliOp(\"IZI\")\n",
    "\n",
    "for i, povm_pub_result in enumerate(primitive_result):\n",
    "    post_processor = POVMPostProcessor(povm_pub_result)\n",
    "    print(f\"Expectation values of PUB {i}:\")\n",
    "    evs, stds = post_processor.get_expectation_value(obs)\n",
    "    print(evs, end=\"\\n\\n\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e67d2d59",
   "metadata": {},
   "source": [
    "### Combine the counts via the argument `combine_counts` when initializing the `POVMPostProcessor` object. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "cc9ad501",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Expectation values of PUB 0:\n",
      "-0.4687500000000005\n",
      "\n",
      "Expectation values of PUB 1:\n",
      "0.5859374999999994\n",
      "\n",
      "Expectation values of PUB 2:\n",
      "0.5624999999999996\n",
      "\n"
     ]
    }
   ],
   "source": [
    "for i, povm_pub_result in enumerate(primitive_result):\n",
    "    post_processor = POVMPostProcessor(povm_pub_result, combine_counts=True)\n",
    "    print(f\"Expectation values of PUB {i}:\")\n",
    "    evs, stds = post_processor.get_expectation_value(obs)\n",
    "    print(evs, end=\"\\n\\n\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f8e35640",
   "metadata": {},
   "source": [
    "## 2) Counts and Outcomes"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9b61c700",
   "metadata": {},
   "source": [
    "### Default: outcomes are unioned together across all parameter sets"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "abebf21c",
   "metadata": {},
   "source": [
    "Calling the `POVMPubResult.get_counts` method will return, by default, a single counter object where samples from all parameter sets were unioned together."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "27a0b945",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Counts of PUB 0:\n",
      "Counter({(4, 1, 1): 3, (1, 2, 4): 3, (0, 0, 0): 2, (5, 3, 0): 2, (2, 1, 5): 2, (3, 3, 0): 2, (3, 1, 5): 2, (2, 0, 2): 2, (5, 1, 3): 2, (1, 1, 1): 2, (2, 1, 1): 2, (0, 2, 2): 2, (0, 3, 2): 1, (0, 2, 0): 1, (2, 3, 3): 1, (4, 4, 3): 1, (5, 5, 3): 1, (4, 3, 0): 1, (5, 2, 0): 1, (4, 2, 5): 1, (2, 5, 2): 1, (1, 1, 5): 1, (5, 1, 5): 1, (0, 2, 3): 1, (2, 1, 3): 1, (0, 3, 3): 1, (4, 0, 0): 1, (3, 4, 0): 1, (5, 4, 2): 1, (1, 2, 1): 1, (5, 2, 3): 1, (0, 5, 0): 1, (5, 2, 2): 1, (0, 3, 4): 1, (3, 4, 1): 1, (1, 1, 4): 1, (3, 0, 5): 1, (1, 3, 2): 1, (0, 0, 5): 1, (3, 1, 3): 1, (2, 3, 1): 1, (0, 0, 2): 1, (4, 3, 4): 1, (2, 1, 4): 1, (5, 0, 5): 1, (5, 2, 4): 1, (5, 2, 1): 1, (2, 0, 0): 1, (3, 5, 0): 1, (4, 1, 2): 1})\n",
      "\n",
      "Counts of PUB 1:\n",
      "Counter({(0, 0, 0): 4, (0, 3, 5): 4, (0, 0, 4): 4, (2, 0, 0): 3, (3, 4, 2): 3, (3, 0, 4): 3, (0, 5, 2): 3, (3, 0, 0): 3, (5, 3, 2): 3, (3, 2, 3): 2, (2, 3, 5): 2, (0, 0, 2): 2, (2, 3, 4): 2, (5, 5, 2): 2, (5, 4, 0): 2, (4, 4, 5): 2, (2, 2, 2): 2, (5, 2, 2): 2, (4, 4, 3): 2, (4, 3, 3): 2, (2, 3, 0): 2, (4, 3, 2): 2, (5, 0, 3): 2, (2, 0, 2): 2, (0, 0, 5): 2, (4, 5, 4): 2, (3, 3, 2): 2, (2, 3, 3): 2, (1, 1, 3): 2, (2, 2, 4): 2, (1, 1, 4): 2, (0, 4, 3): 1, (2, 4, 5): 1, (0, 2, 3): 1, (3, 4, 3): 1, (0, 3, 0): 1, (5, 0, 5): 1, (4, 4, 2): 1, (0, 2, 2): 1, (4, 0, 5): 1, (4, 5, 5): 1, (0, 4, 4): 1, (5, 0, 0): 1, (2, 5, 5): 1, (0, 3, 3): 1, (3, 0, 2): 1, (0, 4, 2): 1, (5, 2, 0): 1, (4, 2, 4): 1, (3, 3, 0): 1, (5, 0, 4): 1, (5, 3, 3): 1, (1, 4, 2): 1, (5, 4, 5): 1, (0, 5, 4): 1, (3, 3, 1): 1, (2, 5, 4): 1, (1, 3, 4): 1, (0, 2, 4): 1, (5, 3, 0): 1, (3, 5, 2): 1, (5, 2, 1): 1, (5, 3, 5): 1, (3, 2, 0): 1, (1, 1, 5): 1, (1, 3, 2): 1, (2, 2, 5): 1, (5, 4, 4): 1, (3, 5, 3): 1, (4, 2, 2): 1, (4, 2, 1): 1, (0, 3, 2): 1, (5, 3, 1): 1, (1, 3, 1): 1, (1, 4, 4): 1, (2, 5, 2): 1, (0, 4, 5): 1, (3, 4, 4): 1, (0, 5, 0): 1, (3, 0, 3): 1, (2, 2, 0): 1, (4, 2, 3): 1, (2, 1, 4): 1, (2, 0, 3): 1, (2, 1, 2): 1})\n",
      "\n",
      "Counts of PUB 2:\n",
      "Counter({(0, 0, 5): 11, (0, 0, 0): 10, (5, 0, 2): 10, (3, 0, 2): 9, (0, 2, 0): 7, (2, 4, 5): 6, (0, 5, 2): 6, (0, 5, 0): 6, (0, 0, 3): 6, (0, 3, 2): 6, (2, 5, 0): 6, (5, 5, 3): 6, (3, 5, 5): 6, (2, 5, 4): 6, (3, 2, 4): 5, (0, 0, 2): 5, (3, 5, 0): 5, (1, 1, 4): 5, (0, 5, 4): 5, (3, 0, 0): 5, (0, 2, 5): 4, (3, 2, 3): 4, (2, 2, 0): 4, (4, 5, 2): 4, (2, 0, 0): 4, (0, 0, 4): 4, (0, 3, 0): 4, (3, 4, 0): 4, (4, 0, 0): 4, (5, 4, 1): 4, (1, 3, 3): 4, (5, 5, 0): 4, (3, 0, 5): 4, (3, 0, 3): 4, (4, 0, 2): 4, (0, 4, 0): 4, (4, 4, 2): 3, (2, 5, 3): 3, (0, 4, 4): 3, (0, 4, 3): 3, (0, 2, 2): 3, (5, 0, 0): 3, (3, 3, 2): 3, (1, 5, 1): 3, (0, 3, 5): 3, (1, 2, 1): 3, (5, 3, 2): 3, (2, 3, 3): 3, (1, 1, 5): 3, (4, 2, 5): 3, (5, 3, 5): 3, (0, 2, 3): 3, (5, 0, 4): 3, (2, 3, 5): 3, (2, 2, 2): 3, (4, 2, 1): 3, (4, 3, 5): 2, (4, 0, 3): 2, (0, 5, 3): 2, (3, 2, 5): 2, (2, 4, 3): 2, (0, 3, 4): 2, (2, 0, 2): 2, (2, 0, 4): 2, (5, 3, 3): 2, (4, 4, 4): 2, (3, 4, 4): 2, (5, 4, 4): 2, (4, 3, 0): 2, (2, 1, 3): 2, (3, 4, 3): 2, (2, 1, 1): 2, (5, 4, 5): 2, (4, 4, 0): 2, (2, 5, 2): 2, (1, 5, 4): 2, (3, 5, 3): 2, (3, 5, 2): 2, (2, 4, 2): 2, (1, 4, 4): 2, (3, 3, 0): 2, (5, 0, 5): 2, (2, 0, 3): 2, (3, 3, 4): 2, (3, 1, 1): 2, (5, 2, 1): 2, (4, 4, 5): 2, (4, 3, 4): 2, (4, 1, 3): 2, (1, 4, 5): 2, (3, 3, 1): 2, (4, 0, 5): 2, (0, 4, 5): 2, (1, 1, 3): 2, (0, 5, 5): 1, (2, 4, 4): 1, (3, 5, 4): 1, (5, 0, 3): 1, (5, 3, 0): 1, (4, 3, 3): 1, (5, 1, 4): 1, (3, 1, 2): 1, (1, 2, 3): 1, (2, 3, 4): 1, (2, 2, 5): 1, (1, 4, 1): 1, (2, 3, 0): 1, (2, 3, 1): 1, (1, 4, 2): 1, (2, 0, 5): 1, (3, 4, 1): 1, (0, 2, 4): 1, (0, 3, 3): 1, (5, 5, 5): 1, (2, 2, 4): 1, (4, 5, 5): 1, (3, 3, 5): 1, (3, 1, 4): 1, (4, 4, 3): 1, (3, 2, 0): 1, (4, 2, 3): 1, (0, 4, 2): 1, (1, 1, 1): 1, (3, 4, 5): 1, (5, 5, 2): 1, (2, 4, 0): 1, (5, 2, 4): 1, (4, 5, 3): 1, (4, 2, 2): 1, (2, 5, 5): 1, (1, 3, 4): 1, (1, 3, 2): 1, (1, 1, 2): 1, (3, 5, 1): 1, (5, 3, 1): 1, (4, 3, 2): 1, (1, 3, 5): 1, (5, 2, 2): 1, (4, 5, 1): 1, (1, 2, 4): 1, (2, 1, 2): 1, (2, 1, 5): 1, (5, 2, 0): 1, (4, 1, 2): 1, (3, 1, 5): 1, (2, 5, 1): 1, (4, 1, 5): 1})\n",
      "\n"
     ]
    }
   ],
   "source": [
    "for i, povm_pub_result in enumerate(primitive_result):\n",
    "    print(f\"Counts of PUB {i}:\")\n",
    "    counts = povm_pub_result.get_counts()  # equivalent to `.get_counts(loc=None)`\n",
    "    print(counts, end=\"\\n\\n\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fa5ab550",
   "metadata": {},
   "source": [
    "Similarly, when calling the `POVMPubResult.get_samples` method, a single flatten list of samples is returned."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "a0a38997",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Samples of PUB 0:\n",
      "[(0, 3, 2), (0, 0, 0), (0, 2, 0), (2, 3, 3), (0, 0, 0), (4, 1, 1), (4, 4, 3), (5, 5, 3), (5, 3, 0), (1, 2, 4), (2, 1, 5), (4, 3, 0), (5, 2, 0), (3, 3, 0), (4, 1, 1), (3, 1, 5), (2, 0, 2), (4, 2, 5), (2, 5, 2), (1, 1, 5), (5, 1, 5), (0, 2, 3), (1, 2, 4), (3, 3, 0), (2, 1, 3), (1, 2, 4), (0, 3, 3), (4, 0, 0), (5, 1, 3), (4, 1, 1), (3, 4, 0), (5, 4, 2), (1, 2, 1), (1, 1, 1), (5, 2, 3), (2, 1, 5), (0, 5, 0), (5, 2, 2), (0, 3, 4), (1, 1, 1), (2, 1, 1), (0, 2, 2), (2, 1, 1), (3, 4, 1), (1, 1, 4), (5, 1, 3), (3, 0, 5), (1, 3, 2), (0, 0, 5), (3, 1, 5), (3, 1, 3), (2, 3, 1), (0, 0, 2), (4, 3, 4), (2, 1, 4), (5, 0, 5), (5, 2, 4), (5, 2, 1), (0, 2, 2), (2, 0, 0), (2, 0, 2), (5, 3, 0), (3, 5, 0), (4, 1, 2)]\n",
      "\n",
      "Samples of PUB 1:\n",
      "[(0, 4, 3), (2, 0, 0), (0, 0, 0), (3, 2, 3), (0, 3, 5), (2, 4, 5), (0, 3, 5), (2, 3, 5), (0, 0, 2), (2, 3, 4), (0, 2, 3), (3, 4, 3), (0, 3, 0), (0, 0, 4), (3, 4, 2), (3, 0, 4), (5, 5, 2), (5, 4, 0), (5, 0, 5), (4, 4, 2), (0, 2, 2), (4, 0, 5), (4, 5, 5), (0, 5, 2), (4, 4, 5), (3, 0, 0), (2, 2, 2), (0, 0, 0), (5, 5, 2), (0, 4, 4), (5, 4, 0), (5, 3, 2), (5, 0, 0), (5, 2, 2), (4, 4, 3), (2, 0, 0), (4, 3, 3), (5, 2, 2), (2, 0, 0), (5, 3, 2), (2, 5, 5), (2, 3, 0), (2, 2, 2), (4, 3, 2), (5, 0, 3), (0, 3, 3), (2, 0, 2), (3, 0, 2), (0, 4, 2), (0, 0, 0), (0, 0, 4), (0, 0, 5), (5, 2, 0), (4, 5, 4), (3, 0, 4), (3, 3, 2), (4, 4, 3), (4, 2, 4), (4, 3, 2), (0, 0, 0), (2, 3, 3), (3, 0, 0), (3, 3, 0), (5, 0, 4), (5, 3, 3), (5, 3, 2), (3, 4, 2), (1, 1, 3), (1, 4, 2), (5, 4, 5), (0, 5, 4), (3, 3, 1), (2, 2, 4), (2, 3, 5), (2, 5, 4), (1, 3, 4), (4, 4, 5), (2, 3, 3), (0, 2, 4), (5, 0, 3), (4, 3, 3), (5, 3, 0), (3, 5, 2), (5, 2, 1), (5, 3, 5), (3, 2, 0), (1, 1, 4), (0, 0, 4), (1, 1, 5), (1, 3, 2), (2, 2, 5), (0, 5, 2), (5, 4, 4), (2, 2, 4), (3, 5, 3), (4, 2, 2), (4, 2, 1), (0, 3, 2), (5, 3, 1), (1, 3, 1), (1, 4, 4), (3, 0, 4), (2, 5, 2), (1, 1, 3), (0, 0, 2), (3, 2, 3), (0, 3, 5), (0, 4, 5), (3, 4, 4), (2, 3, 0), (3, 3, 2), (0, 0, 5), (0, 5, 0), (1, 1, 4), (3, 0, 3), (2, 2, 0), (0, 5, 2), (3, 4, 2), (4, 2, 3), (2, 1, 4), (2, 0, 2), (2, 0, 3), (2, 3, 4), (4, 5, 4), (2, 1, 2), (0, 3, 5), (0, 0, 4), (3, 0, 0)]\n",
      "\n",
      "Samples of PUB 2:\n",
      "[(0, 5, 5), (0, 0, 0), (3, 0, 2), (4, 3, 5), (4, 0, 3), (0, 5, 3), (3, 0, 2), (3, 2, 4), (4, 4, 2), (3, 0, 2), (3, 2, 5), (0, 2, 5), (2, 4, 5), (2, 4, 4), (3, 2, 3), (2, 5, 3), (0, 2, 0), (2, 4, 3), (3, 2, 4), (0, 0, 2), (2, 2, 0), (0, 3, 4), (2, 0, 2), (0, 4, 4), (2, 0, 4), (4, 5, 2), (2, 2, 0), (3, 0, 2), (5, 3, 3), (0, 5, 2), (0, 5, 0), (3, 5, 4), (0, 0, 0), (0, 5, 0), (4, 4, 4), (0, 4, 3), (2, 0, 0), (3, 4, 4), (3, 2, 4), (5, 4, 4), (4, 4, 2), (0, 2, 2), (0, 5, 2), (5, 0, 0), (0, 0, 5), (0, 0, 3), (0, 2, 0), (3, 3, 2), (5, 0, 2), (0, 0, 0), (5, 0, 3), (0, 0, 0), (0, 0, 4), (0, 3, 0), (4, 3, 0), (2, 0, 0), (5, 3, 0), (0, 2, 5), (3, 5, 0), (3, 4, 0), (3, 2, 4), (0, 2, 2), (0, 0, 0), (3, 3, 2), (0, 3, 2), (0, 0, 4), (2, 1, 3), (4, 3, 3), (3, 4, 3), (0, 0, 5), (1, 1, 4), (2, 1, 3), (2, 1, 1), (4, 0, 0), (5, 4, 1), (5, 1, 4), (0, 0, 2), (2, 5, 0), (1, 5, 1), (3, 1, 2), (5, 5, 3), (5, 4, 5), (3, 5, 5), (1, 2, 3), (2, 5, 4), (0, 0, 5), (2, 3, 4), (0, 3, 5), (4, 4, 0), (3, 4, 0), (2, 2, 5), (0, 3, 2), (4, 5, 2), (1, 4, 1), (1, 1, 4), (0, 5, 4), (1, 2, 1), (2, 3, 0), (4, 5, 2), (5, 3, 2), (1, 3, 3), (2, 3, 1), (2, 5, 2), (0, 0, 5), (2, 5, 0), (1, 4, 2), (3, 2, 3), (2, 3, 3), (1, 5, 4), (1, 5, 4), (1, 3, 3), (0, 5, 0), (3, 5, 3), (3, 4, 0), (2, 5, 0), (2, 0, 5), (1, 1, 5), (3, 5, 2), (4, 2, 5), (5, 3, 5), (5, 5, 0), (0, 0, 0), (2, 4, 2), (1, 4, 4), (0, 0, 4), (3, 5, 5), (5, 3, 5), (3, 4, 1), (3, 0, 5), (2, 2, 0), (3, 0, 2), (4, 0, 3), (0, 3, 0), (3, 2, 3), (0, 5, 0), (0, 2, 4), (3, 0, 0), (0, 5, 4), (3, 0, 5), (0, 5, 0), (3, 0, 2), (4, 0, 0), (5, 5, 0), (3, 3, 0), (0, 0, 3), (0, 5, 4), (2, 5, 0), (4, 4, 2), (0, 3, 3), (3, 5, 2), (0, 2, 3), (0, 0, 2), (0, 3, 5), (5, 0, 4), (2, 5, 3), (5, 0, 5), (2, 4, 2), (3, 5, 0), (2, 5, 3), (0, 3, 5), (5, 5, 5), (0, 5, 2), (5, 3, 5), (0, 5, 3), (2, 2, 4), (0, 2, 3), (4, 5, 5), (2, 4, 5), (3, 5, 0), (0, 3, 2), (3, 3, 0), (0, 4, 3), (0, 3, 4), (0, 4, 4), (3, 5, 0), (5, 0, 2), (3, 0, 3), (2, 5, 4), (3, 3, 5), (0, 2, 0), (2, 0, 3), (3, 0, 0), (0, 5, 2), (3, 4, 0), (4, 0, 2), (0, 0, 5), (2, 5, 0), (2, 3, 5), (5, 5, 0), (0, 0, 5), (2, 2, 2), (0, 3, 0), (3, 3, 4), (2, 1, 1), (3, 2, 5), (0, 0, 2), (2, 3, 5), (0, 2, 0), (3, 1, 1), (2, 3, 3), (2, 2, 2), (2, 3, 5), (5, 0, 2), (0, 0, 5), (5, 2, 1), (4, 4, 5), (5, 3, 2), (4, 0, 2), (2, 4, 5), (4, 3, 4), (2, 5, 4), (3, 0, 3), (5, 5, 3), (0, 0, 5), (3, 1, 4), (2, 2, 2), (0, 2, 5), (3, 0, 5), (0, 0, 3), (3, 0, 0), (1, 3, 3), (4, 5, 2), (2, 5, 4), (1, 1, 4), (1, 2, 1), (3, 0, 2), (2, 0, 0), (5, 4, 4), (4, 1, 3), (3, 3, 2), (0, 0, 2), (0, 5, 0), (0, 0, 3), (2, 0, 2), (4, 4, 3), (1, 4, 5), (5, 5, 3), (1, 1, 5), (3, 2, 0), (2, 5, 2), (3, 4, 4), (1, 2, 1), (1, 3, 3), (1, 4, 4), (0, 4, 0), (2, 5, 4), (2, 0, 4), (0, 0, 4), (4, 2, 3), (0, 0, 0), (0, 4, 2), (1, 5, 1), (1, 1, 5), (5, 0, 2), (3, 3, 1), (1, 1, 1), (3, 4, 5), (5, 5, 0), (4, 4, 4), (0, 2, 3), (5, 5, 2), (4, 0, 0), (0, 2, 0), (5, 0, 2), (5, 0, 2), (4, 4, 0), (2, 4, 0), (5, 2, 4), (2, 2, 0), (3, 0, 2), (2, 5, 0), (4, 2, 5), (3, 1, 1), (4, 5, 3), (0, 3, 0), (2, 4, 5), (4, 3, 0), (3, 0, 0), (0, 2, 2), (5, 0, 0), (3, 2, 4), (4, 0, 2), (5, 0, 0), (4, 0, 5), (5, 0, 4), (4, 0, 2), (0, 0, 5), (3, 0, 3), (5, 4, 5), (3, 3, 4), (4, 3, 5), (0, 4, 5), (5, 0, 2), (0, 4, 0), (4, 2, 2), (3, 0, 5), (2, 0, 0), (0, 5, 2), (3, 5, 5), (2, 5, 5), (0, 0, 5), (0, 2, 0), (0, 0, 0), (0, 4, 4), (3, 5, 5), (0, 0, 0), (4, 4, 5), (0, 5, 2), (5, 0, 2), (2, 4, 5), (4, 0, 5), (0, 4, 3), (2, 0, 3), (3, 5, 0), (3, 0, 3), (4, 2, 5), (3, 0, 2), (3, 5, 5), (0, 0, 5), (4, 0, 0), (1, 1, 4), (1, 3, 4), (1, 3, 2), (5, 0, 5), (1, 1, 3), (2, 3, 3), (4, 2, 1), (0, 0, 0), (3, 5, 3), (5, 2, 1), (1, 1, 2), (4, 1, 3), (3, 5, 1), (5, 3, 1), (4, 3, 2), (3, 0, 0), (5, 0, 4), (0, 5, 4), (1, 3, 5), (2, 5, 4), (5, 5, 3), (5, 4, 1), (5, 2, 2), (0, 5, 4), (5, 3, 3), (4, 5, 1), (1, 5, 1), (0, 3, 2), (1, 2, 4), (2, 1, 2), (5, 0, 2), (0, 3, 2), (2, 4, 5), (0, 3, 2), (4, 3, 4), (5, 4, 1), (2, 1, 5), (3, 3, 1), (0, 4, 5), (5, 2, 0), (3, 5, 5), (4, 1, 2), (5, 5, 3), (1, 1, 4), (0, 2, 5), (3, 1, 5), (0, 0, 3), (0, 4, 0), (5, 3, 2), (0, 2, 0), (5, 4, 1), (5, 0, 2), (1, 1, 3), (2, 5, 1), (1, 4, 5), (4, 2, 1), (3, 4, 3), (4, 1, 5), (2, 4, 3), (0, 0, 3), (3, 2, 3), (0, 4, 0), (5, 5, 3), (4, 2, 1)]\n",
      "\n"
     ]
    }
   ],
   "source": [
    "for i, povm_pub_result in enumerate(primitive_result):\n",
    "    print(f\"Samples of PUB {i}:\")\n",
    "    samples = povm_pub_result.get_samples()  # equivalent to `.get_counts(loc=None)`\n",
    "    print(samples, end=\"\\n\\n\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bf3f3d19",
   "metadata": {},
   "source": [
    "### Keep the counts separated"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5411c95e",
   "metadata": {},
   "source": [
    "Instead of aggregating all the counts together, one can request all the counts separately via the argument `loc=...` of the `POVMPubResult.get_counts` method.\n",
    "It will return an array of counter objects, whose shape will match the binding array provided in the corresponding PUB."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "36d80fd4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Counts of PUB 0:\n",
      "[Counter({(4, 1, 1): 3, (1, 2, 4): 3, (0, 0, 0): 2, (5, 3, 0): 2, (2, 1, 5): 2, (3, 3, 0): 2, (3, 1, 5): 2, (2, 0, 2): 2, (5, 1, 3): 2, (1, 1, 1): 2, (2, 1, 1): 2, (0, 2, 2): 2, (0, 3, 2): 1, (0, 2, 0): 1, (2, 3, 3): 1, (4, 4, 3): 1, (5, 5, 3): 1, (4, 3, 0): 1, (5, 2, 0): 1, (4, 2, 5): 1, (2, 5, 2): 1, (1, 1, 5): 1, (5, 1, 5): 1, (0, 2, 3): 1, (2, 1, 3): 1, (0, 3, 3): 1, (4, 0, 0): 1, (3, 4, 0): 1, (5, 4, 2): 1, (1, 2, 1): 1, (5, 2, 3): 1, (0, 5, 0): 1, (5, 2, 2): 1, (0, 3, 4): 1, (3, 4, 1): 1, (1, 1, 4): 1, (3, 0, 5): 1, (1, 3, 2): 1, (0, 0, 5): 1, (3, 1, 3): 1, (2, 3, 1): 1, (0, 0, 2): 1, (4, 3, 4): 1, (2, 1, 4): 1, (5, 0, 5): 1, (5, 2, 4): 1, (5, 2, 1): 1, (2, 0, 0): 1, (3, 5, 0): 1, (4, 1, 2): 1})]\n",
      "Shape: (1,)\n",
      "\n",
      "Counts of PUB 1:\n",
      "[Counter({(0, 0, 0): 4, (2, 0, 0): 3, (0, 3, 5): 2, (0, 0, 4): 2, (3, 0, 4): 2, (5, 5, 2): 2, (5, 4, 0): 2, (3, 0, 0): 2, (2, 2, 2): 2, (5, 3, 2): 2, (5, 2, 2): 2, (4, 4, 3): 2, (4, 3, 2): 2, (0, 4, 3): 1, (3, 2, 3): 1, (2, 4, 5): 1, (2, 3, 5): 1, (0, 0, 2): 1, (2, 3, 4): 1, (0, 2, 3): 1, (3, 4, 3): 1, (0, 3, 0): 1, (3, 4, 2): 1, (5, 0, 5): 1, (4, 4, 2): 1, (0, 2, 2): 1, (4, 0, 5): 1, (4, 5, 5): 1, (0, 5, 2): 1, (4, 4, 5): 1, (0, 4, 4): 1, (5, 0, 0): 1, (4, 3, 3): 1, (2, 5, 5): 1, (2, 3, 0): 1, (5, 0, 3): 1, (0, 3, 3): 1, (2, 0, 2): 1, (3, 0, 2): 1, (0, 4, 2): 1, (0, 0, 5): 1, (5, 2, 0): 1, (4, 5, 4): 1, (3, 3, 2): 1, (4, 2, 4): 1, (2, 3, 3): 1, (3, 3, 0): 1, (5, 0, 4): 1})\n",
      " Counter({(3, 4, 2): 2, (1, 1, 3): 2, (2, 2, 4): 2, (1, 1, 4): 2, (0, 0, 4): 2, (0, 5, 2): 2, (0, 3, 5): 2, (5, 3, 3): 1, (5, 3, 2): 1, (1, 4, 2): 1, (5, 4, 5): 1, (0, 5, 4): 1, (3, 3, 1): 1, (2, 3, 5): 1, (2, 5, 4): 1, (1, 3, 4): 1, (4, 4, 5): 1, (2, 3, 3): 1, (0, 2, 4): 1, (5, 0, 3): 1, (4, 3, 3): 1, (5, 3, 0): 1, (3, 5, 2): 1, (5, 2, 1): 1, (5, 3, 5): 1, (3, 2, 0): 1, (1, 1, 5): 1, (1, 3, 2): 1, (2, 2, 5): 1, (5, 4, 4): 1, (3, 5, 3): 1, (4, 2, 2): 1, (4, 2, 1): 1, (0, 3, 2): 1, (5, 3, 1): 1, (1, 3, 1): 1, (1, 4, 4): 1, (3, 0, 4): 1, (2, 5, 2): 1, (0, 0, 2): 1, (3, 2, 3): 1, (0, 4, 5): 1, (3, 4, 4): 1, (2, 3, 0): 1, (3, 3, 2): 1, (0, 0, 5): 1, (0, 5, 0): 1, (3, 0, 3): 1, (2, 2, 0): 1, (4, 2, 3): 1, (2, 1, 4): 1, (2, 0, 2): 1, (2, 0, 3): 1, (2, 3, 4): 1, (4, 5, 4): 1, (2, 1, 2): 1, (3, 0, 0): 1})]\n",
      "Shape: (2,)\n",
      "\n",
      "Counts of PUB 2:\n",
      "[[Counter({(0, 0, 0): 5, (3, 0, 2): 4, (3, 2, 4): 4, (4, 4, 2): 2, (0, 2, 5): 2, (0, 2, 0): 2, (2, 2, 0): 2, (0, 5, 2): 2, (0, 5, 0): 2, (2, 0, 0): 2, (0, 2, 2): 2, (3, 3, 2): 2, (0, 5, 5): 1, (4, 3, 5): 1, (4, 0, 3): 1, (0, 5, 3): 1, (3, 2, 5): 1, (2, 4, 5): 1, (2, 4, 4): 1, (3, 2, 3): 1, (2, 5, 3): 1, (2, 4, 3): 1, (0, 0, 2): 1, (0, 3, 4): 1, (2, 0, 2): 1, (0, 4, 4): 1, (2, 0, 4): 1, (4, 5, 2): 1, (5, 3, 3): 1, (3, 5, 4): 1, (4, 4, 4): 1, (0, 4, 3): 1, (3, 4, 4): 1, (5, 4, 4): 1, (5, 0, 0): 1, (0, 0, 5): 1, (0, 0, 3): 1, (5, 0, 2): 1, (5, 0, 3): 1, (0, 0, 4): 1, (0, 3, 0): 1, (4, 3, 0): 1, (5, 3, 0): 1, (3, 5, 0): 1, (3, 4, 0): 1})\n",
      "  Counter({(0, 0, 5): 3, (2, 5, 0): 3, (0, 3, 2): 2, (0, 0, 4): 2, (2, 1, 3): 2, (1, 1, 4): 2, (3, 5, 5): 2, (3, 4, 0): 2, (4, 5, 2): 2, (1, 3, 3): 2, (1, 5, 4): 2, (5, 3, 5): 2, (4, 3, 3): 1, (3, 4, 3): 1, (2, 1, 1): 1, (4, 0, 0): 1, (5, 4, 1): 1, (5, 1, 4): 1, (0, 0, 2): 1, (1, 5, 1): 1, (3, 1, 2): 1, (5, 5, 3): 1, (5, 4, 5): 1, (1, 2, 3): 1, (2, 5, 4): 1, (2, 3, 4): 1, (0, 3, 5): 1, (4, 4, 0): 1, (2, 2, 5): 1, (1, 4, 1): 1, (0, 5, 4): 1, (1, 2, 1): 1, (2, 3, 0): 1, (5, 3, 2): 1, (2, 3, 1): 1, (2, 5, 2): 1, (1, 4, 2): 1, (3, 2, 3): 1, (2, 3, 3): 1, (0, 5, 0): 1, (3, 5, 3): 1, (2, 0, 5): 1, (1, 1, 5): 1, (3, 5, 2): 1, (4, 2, 5): 1, (5, 5, 0): 1, (0, 0, 0): 1, (2, 4, 2): 1, (1, 4, 4): 1, (3, 4, 1): 1})]\n",
      " [Counter({(3, 5, 0): 3, (3, 0, 5): 2, (3, 0, 2): 2, (0, 3, 0): 2, (0, 5, 0): 2, (3, 0, 0): 2, (0, 5, 4): 2, (5, 5, 0): 2, (3, 3, 0): 2, (2, 5, 0): 2, (0, 2, 3): 2, (0, 3, 5): 2, (2, 5, 3): 2, (0, 5, 2): 2, (0, 0, 5): 2, (2, 2, 0): 1, (4, 0, 3): 1, (3, 2, 3): 1, (0, 2, 4): 1, (4, 0, 0): 1, (0, 0, 3): 1, (4, 4, 2): 1, (0, 3, 3): 1, (3, 5, 2): 1, (0, 0, 2): 1, (5, 0, 4): 1, (5, 0, 5): 1, (2, 4, 2): 1, (5, 5, 5): 1, (5, 3, 5): 1, (0, 5, 3): 1, (2, 2, 4): 1, (4, 5, 5): 1, (2, 4, 5): 1, (0, 3, 2): 1, (0, 4, 3): 1, (0, 3, 4): 1, (0, 4, 4): 1, (5, 0, 2): 1, (3, 0, 3): 1, (2, 5, 4): 1, (3, 3, 5): 1, (0, 2, 0): 1, (2, 0, 3): 1, (3, 4, 0): 1, (4, 0, 2): 1, (2, 3, 5): 1, (2, 2, 2): 1})\n",
      "  Counter({(2, 5, 4): 3, (0, 0, 2): 2, (2, 3, 5): 2, (2, 2, 2): 2, (5, 0, 2): 2, (0, 0, 5): 2, (5, 5, 3): 2, (0, 0, 3): 2, (1, 3, 3): 2, (1, 2, 1): 2, (1, 1, 5): 2, (3, 3, 4): 1, (2, 1, 1): 1, (3, 2, 5): 1, (0, 2, 0): 1, (3, 1, 1): 1, (2, 3, 3): 1, (5, 2, 1): 1, (4, 4, 5): 1, (5, 3, 2): 1, (4, 0, 2): 1, (2, 4, 5): 1, (4, 3, 4): 1, (3, 0, 3): 1, (3, 1, 4): 1, (0, 2, 5): 1, (3, 0, 5): 1, (3, 0, 0): 1, (4, 5, 2): 1, (1, 1, 4): 1, (3, 0, 2): 1, (2, 0, 0): 1, (5, 4, 4): 1, (4, 1, 3): 1, (3, 3, 2): 1, (0, 5, 0): 1, (2, 0, 2): 1, (4, 4, 3): 1, (1, 4, 5): 1, (3, 2, 0): 1, (2, 5, 2): 1, (3, 4, 4): 1, (1, 4, 4): 1, (0, 4, 0): 1, (2, 0, 4): 1, (0, 0, 4): 1, (4, 2, 3): 1, (0, 0, 0): 1, (0, 4, 2): 1, (1, 5, 1): 1, (3, 3, 1): 1, (1, 1, 1): 1})]\n",
      " [Counter({(5, 0, 2): 4, (0, 0, 5): 3, (3, 5, 5): 3, (4, 0, 0): 2, (0, 2, 0): 2, (3, 0, 2): 2, (4, 2, 5): 2, (2, 4, 5): 2, (5, 0, 0): 2, (4, 0, 2): 2, (4, 0, 5): 2, (3, 0, 3): 2, (0, 5, 2): 2, (0, 0, 0): 2, (3, 4, 5): 1, (5, 5, 0): 1, (4, 4, 4): 1, (0, 2, 3): 1, (5, 5, 2): 1, (4, 4, 0): 1, (2, 4, 0): 1, (5, 2, 4): 1, (2, 2, 0): 1, (2, 5, 0): 1, (3, 1, 1): 1, (4, 5, 3): 1, (0, 3, 0): 1, (4, 3, 0): 1, (3, 0, 0): 1, (0, 2, 2): 1, (3, 2, 4): 1, (5, 0, 4): 1, (5, 4, 5): 1, (3, 3, 4): 1, (4, 3, 5): 1, (0, 4, 5): 1, (0, 4, 0): 1, (4, 2, 2): 1, (3, 0, 5): 1, (2, 0, 0): 1, (2, 5, 5): 1, (0, 4, 4): 1, (4, 4, 5): 1, (0, 4, 3): 1, (2, 0, 3): 1, (3, 5, 0): 1})\n",
      "  Counter({(4, 2, 1): 3, (5, 5, 3): 3, (5, 4, 1): 3, (0, 3, 2): 3, (1, 1, 4): 2, (1, 1, 3): 2, (0, 5, 4): 2, (5, 0, 2): 2, (0, 0, 3): 2, (0, 4, 0): 2, (1, 3, 4): 1, (1, 3, 2): 1, (5, 0, 5): 1, (2, 3, 3): 1, (0, 0, 0): 1, (3, 5, 3): 1, (5, 2, 1): 1, (1, 1, 2): 1, (4, 1, 3): 1, (3, 5, 1): 1, (5, 3, 1): 1, (4, 3, 2): 1, (3, 0, 0): 1, (5, 0, 4): 1, (1, 3, 5): 1, (2, 5, 4): 1, (5, 2, 2): 1, (5, 3, 3): 1, (4, 5, 1): 1, (1, 5, 1): 1, (1, 2, 4): 1, (2, 1, 2): 1, (2, 4, 5): 1, (4, 3, 4): 1, (2, 1, 5): 1, (3, 3, 1): 1, (0, 4, 5): 1, (5, 2, 0): 1, (3, 5, 5): 1, (4, 1, 2): 1, (0, 2, 5): 1, (3, 1, 5): 1, (5, 3, 2): 1, (0, 2, 0): 1, (2, 5, 1): 1, (1, 4, 5): 1, (3, 4, 3): 1, (4, 1, 5): 1, (2, 4, 3): 1, (3, 2, 3): 1})]]\n",
      "Shape: (3, 2)\n",
      "\n"
     ]
    }
   ],
   "source": [
    "for i, povm_pub_result in enumerate(primitive_result):\n",
    "    print(f\"Counts of PUB {i}:\")\n",
    "    counts = povm_pub_result.get_counts(loc=...)\n",
    "    print(counts)\n",
    "    print(f\"Shape: {counts.shape}\", end=\"\\n\\n\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e8fe85b9",
   "metadata": {},
   "source": [
    "The same applies for the `POVMPubResult.get_samples` method:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "c0b5f192",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Samples of PUB 0:\n",
      "[list([(0, 3, 2), (0, 0, 0), (0, 2, 0), (2, 3, 3), (0, 0, 0), (4, 1, 1), (4, 4, 3), (5, 5, 3), (5, 3, 0), (1, 2, 4), (2, 1, 5), (4, 3, 0), (5, 2, 0), (3, 3, 0), (4, 1, 1), (3, 1, 5), (2, 0, 2), (4, 2, 5), (2, 5, 2), (1, 1, 5), (5, 1, 5), (0, 2, 3), (1, 2, 4), (3, 3, 0), (2, 1, 3), (1, 2, 4), (0, 3, 3), (4, 0, 0), (5, 1, 3), (4, 1, 1), (3, 4, 0), (5, 4, 2), (1, 2, 1), (1, 1, 1), (5, 2, 3), (2, 1, 5), (0, 5, 0), (5, 2, 2), (0, 3, 4), (1, 1, 1), (2, 1, 1), (0, 2, 2), (2, 1, 1), (3, 4, 1), (1, 1, 4), (5, 1, 3), (3, 0, 5), (1, 3, 2), (0, 0, 5), (3, 1, 5), (3, 1, 3), (2, 3, 1), (0, 0, 2), (4, 3, 4), (2, 1, 4), (5, 0, 5), (5, 2, 4), (5, 2, 1), (0, 2, 2), (2, 0, 0), (2, 0, 2), (5, 3, 0), (3, 5, 0), (4, 1, 2)])]\n",
      "Shape: (1,)\n",
      "\n",
      "Samples of PUB 1:\n",
      "[list([(0, 4, 3), (2, 0, 0), (0, 0, 0), (3, 2, 3), (0, 3, 5), (2, 4, 5), (0, 3, 5), (2, 3, 5), (0, 0, 2), (2, 3, 4), (0, 2, 3), (3, 4, 3), (0, 3, 0), (0, 0, 4), (3, 4, 2), (3, 0, 4), (5, 5, 2), (5, 4, 0), (5, 0, 5), (4, 4, 2), (0, 2, 2), (4, 0, 5), (4, 5, 5), (0, 5, 2), (4, 4, 5), (3, 0, 0), (2, 2, 2), (0, 0, 0), (5, 5, 2), (0, 4, 4), (5, 4, 0), (5, 3, 2), (5, 0, 0), (5, 2, 2), (4, 4, 3), (2, 0, 0), (4, 3, 3), (5, 2, 2), (2, 0, 0), (5, 3, 2), (2, 5, 5), (2, 3, 0), (2, 2, 2), (4, 3, 2), (5, 0, 3), (0, 3, 3), (2, 0, 2), (3, 0, 2), (0, 4, 2), (0, 0, 0), (0, 0, 4), (0, 0, 5), (5, 2, 0), (4, 5, 4), (3, 0, 4), (3, 3, 2), (4, 4, 3), (4, 2, 4), (4, 3, 2), (0, 0, 0), (2, 3, 3), (3, 0, 0), (3, 3, 0), (5, 0, 4)])\n",
      " list([(5, 3, 3), (5, 3, 2), (3, 4, 2), (1, 1, 3), (1, 4, 2), (5, 4, 5), (0, 5, 4), (3, 3, 1), (2, 2, 4), (2, 3, 5), (2, 5, 4), (1, 3, 4), (4, 4, 5), (2, 3, 3), (0, 2, 4), (5, 0, 3), (4, 3, 3), (5, 3, 0), (3, 5, 2), (5, 2, 1), (5, 3, 5), (3, 2, 0), (1, 1, 4), (0, 0, 4), (1, 1, 5), (1, 3, 2), (2, 2, 5), (0, 5, 2), (5, 4, 4), (2, 2, 4), (3, 5, 3), (4, 2, 2), (4, 2, 1), (0, 3, 2), (5, 3, 1), (1, 3, 1), (1, 4, 4), (3, 0, 4), (2, 5, 2), (1, 1, 3), (0, 0, 2), (3, 2, 3), (0, 3, 5), (0, 4, 5), (3, 4, 4), (2, 3, 0), (3, 3, 2), (0, 0, 5), (0, 5, 0), (1, 1, 4), (3, 0, 3), (2, 2, 0), (0, 5, 2), (3, 4, 2), (4, 2, 3), (2, 1, 4), (2, 0, 2), (2, 0, 3), (2, 3, 4), (4, 5, 4), (2, 1, 2), (0, 3, 5), (0, 0, 4), (3, 0, 0)])]\n",
      "Shape: (2,)\n",
      "\n",
      "Samples of PUB 2:\n",
      "[[list([(0, 5, 5), (0, 0, 0), (3, 0, 2), (4, 3, 5), (4, 0, 3), (0, 5, 3), (3, 0, 2), (3, 2, 4), (4, 4, 2), (3, 0, 2), (3, 2, 5), (0, 2, 5), (2, 4, 5), (2, 4, 4), (3, 2, 3), (2, 5, 3), (0, 2, 0), (2, 4, 3), (3, 2, 4), (0, 0, 2), (2, 2, 0), (0, 3, 4), (2, 0, 2), (0, 4, 4), (2, 0, 4), (4, 5, 2), (2, 2, 0), (3, 0, 2), (5, 3, 3), (0, 5, 2), (0, 5, 0), (3, 5, 4), (0, 0, 0), (0, 5, 0), (4, 4, 4), (0, 4, 3), (2, 0, 0), (3, 4, 4), (3, 2, 4), (5, 4, 4), (4, 4, 2), (0, 2, 2), (0, 5, 2), (5, 0, 0), (0, 0, 5), (0, 0, 3), (0, 2, 0), (3, 3, 2), (5, 0, 2), (0, 0, 0), (5, 0, 3), (0, 0, 0), (0, 0, 4), (0, 3, 0), (4, 3, 0), (2, 0, 0), (5, 3, 0), (0, 2, 5), (3, 5, 0), (3, 4, 0), (3, 2, 4), (0, 2, 2), (0, 0, 0), (3, 3, 2)])\n",
      "  list([(0, 3, 2), (0, 0, 4), (2, 1, 3), (4, 3, 3), (3, 4, 3), (0, 0, 5), (1, 1, 4), (2, 1, 3), (2, 1, 1), (4, 0, 0), (5, 4, 1), (5, 1, 4), (0, 0, 2), (2, 5, 0), (1, 5, 1), (3, 1, 2), (5, 5, 3), (5, 4, 5), (3, 5, 5), (1, 2, 3), (2, 5, 4), (0, 0, 5), (2, 3, 4), (0, 3, 5), (4, 4, 0), (3, 4, 0), (2, 2, 5), (0, 3, 2), (4, 5, 2), (1, 4, 1), (1, 1, 4), (0, 5, 4), (1, 2, 1), (2, 3, 0), (4, 5, 2), (5, 3, 2), (1, 3, 3), (2, 3, 1), (2, 5, 2), (0, 0, 5), (2, 5, 0), (1, 4, 2), (3, 2, 3), (2, 3, 3), (1, 5, 4), (1, 5, 4), (1, 3, 3), (0, 5, 0), (3, 5, 3), (3, 4, 0), (2, 5, 0), (2, 0, 5), (1, 1, 5), (3, 5, 2), (4, 2, 5), (5, 3, 5), (5, 5, 0), (0, 0, 0), (2, 4, 2), (1, 4, 4), (0, 0, 4), (3, 5, 5), (5, 3, 5), (3, 4, 1)])]\n",
      " [list([(3, 0, 5), (2, 2, 0), (3, 0, 2), (4, 0, 3), (0, 3, 0), (3, 2, 3), (0, 5, 0), (0, 2, 4), (3, 0, 0), (0, 5, 4), (3, 0, 5), (0, 5, 0), (3, 0, 2), (4, 0, 0), (5, 5, 0), (3, 3, 0), (0, 0, 3), (0, 5, 4), (2, 5, 0), (4, 4, 2), (0, 3, 3), (3, 5, 2), (0, 2, 3), (0, 0, 2), (0, 3, 5), (5, 0, 4), (2, 5, 3), (5, 0, 5), (2, 4, 2), (3, 5, 0), (2, 5, 3), (0, 3, 5), (5, 5, 5), (0, 5, 2), (5, 3, 5), (0, 5, 3), (2, 2, 4), (0, 2, 3), (4, 5, 5), (2, 4, 5), (3, 5, 0), (0, 3, 2), (3, 3, 0), (0, 4, 3), (0, 3, 4), (0, 4, 4), (3, 5, 0), (5, 0, 2), (3, 0, 3), (2, 5, 4), (3, 3, 5), (0, 2, 0), (2, 0, 3), (3, 0, 0), (0, 5, 2), (3, 4, 0), (4, 0, 2), (0, 0, 5), (2, 5, 0), (2, 3, 5), (5, 5, 0), (0, 0, 5), (2, 2, 2), (0, 3, 0)])\n",
      "  list([(3, 3, 4), (2, 1, 1), (3, 2, 5), (0, 0, 2), (2, 3, 5), (0, 2, 0), (3, 1, 1), (2, 3, 3), (2, 2, 2), (2, 3, 5), (5, 0, 2), (0, 0, 5), (5, 2, 1), (4, 4, 5), (5, 3, 2), (4, 0, 2), (2, 4, 5), (4, 3, 4), (2, 5, 4), (3, 0, 3), (5, 5, 3), (0, 0, 5), (3, 1, 4), (2, 2, 2), (0, 2, 5), (3, 0, 5), (0, 0, 3), (3, 0, 0), (1, 3, 3), (4, 5, 2), (2, 5, 4), (1, 1, 4), (1, 2, 1), (3, 0, 2), (2, 0, 0), (5, 4, 4), (4, 1, 3), (3, 3, 2), (0, 0, 2), (0, 5, 0), (0, 0, 3), (2, 0, 2), (4, 4, 3), (1, 4, 5), (5, 5, 3), (1, 1, 5), (3, 2, 0), (2, 5, 2), (3, 4, 4), (1, 2, 1), (1, 3, 3), (1, 4, 4), (0, 4, 0), (2, 5, 4), (2, 0, 4), (0, 0, 4), (4, 2, 3), (0, 0, 0), (0, 4, 2), (1, 5, 1), (1, 1, 5), (5, 0, 2), (3, 3, 1), (1, 1, 1)])]\n",
      " [list([(3, 4, 5), (5, 5, 0), (4, 4, 4), (0, 2, 3), (5, 5, 2), (4, 0, 0), (0, 2, 0), (5, 0, 2), (5, 0, 2), (4, 4, 0), (2, 4, 0), (5, 2, 4), (2, 2, 0), (3, 0, 2), (2, 5, 0), (4, 2, 5), (3, 1, 1), (4, 5, 3), (0, 3, 0), (2, 4, 5), (4, 3, 0), (3, 0, 0), (0, 2, 2), (5, 0, 0), (3, 2, 4), (4, 0, 2), (5, 0, 0), (4, 0, 5), (5, 0, 4), (4, 0, 2), (0, 0, 5), (3, 0, 3), (5, 4, 5), (3, 3, 4), (4, 3, 5), (0, 4, 5), (5, 0, 2), (0, 4, 0), (4, 2, 2), (3, 0, 5), (2, 0, 0), (0, 5, 2), (3, 5, 5), (2, 5, 5), (0, 0, 5), (0, 2, 0), (0, 0, 0), (0, 4, 4), (3, 5, 5), (0, 0, 0), (4, 4, 5), (0, 5, 2), (5, 0, 2), (2, 4, 5), (4, 0, 5), (0, 4, 3), (2, 0, 3), (3, 5, 0), (3, 0, 3), (4, 2, 5), (3, 0, 2), (3, 5, 5), (0, 0, 5), (4, 0, 0)])\n",
      "  list([(1, 1, 4), (1, 3, 4), (1, 3, 2), (5, 0, 5), (1, 1, 3), (2, 3, 3), (4, 2, 1), (0, 0, 0), (3, 5, 3), (5, 2, 1), (1, 1, 2), (4, 1, 3), (3, 5, 1), (5, 3, 1), (4, 3, 2), (3, 0, 0), (5, 0, 4), (0, 5, 4), (1, 3, 5), (2, 5, 4), (5, 5, 3), (5, 4, 1), (5, 2, 2), (0, 5, 4), (5, 3, 3), (4, 5, 1), (1, 5, 1), (0, 3, 2), (1, 2, 4), (2, 1, 2), (5, 0, 2), (0, 3, 2), (2, 4, 5), (0, 3, 2), (4, 3, 4), (5, 4, 1), (2, 1, 5), (3, 3, 1), (0, 4, 5), (5, 2, 0), (3, 5, 5), (4, 1, 2), (5, 5, 3), (1, 1, 4), (0, 2, 5), (3, 1, 5), (0, 0, 3), (0, 4, 0), (5, 3, 2), (0, 2, 0), (5, 4, 1), (5, 0, 2), (1, 1, 3), (2, 5, 1), (1, 4, 5), (4, 2, 1), (3, 4, 3), (4, 1, 5), (2, 4, 3), (0, 0, 3), (3, 2, 3), (0, 4, 0), (5, 5, 3), (4, 2, 1)])]]\n",
      "Shape: (3, 2)\n",
      "\n"
     ]
    }
   ],
   "source": [
    "for i, povm_pub_result in enumerate(primitive_result):\n",
    "    print(f\"Samples of PUB {i}:\")\n",
    "    samples = povm_pub_result.get_samples(loc=...)\n",
    "    print(samples)\n",
    "    print(f\"Shape: {samples.shape}\", end=\"\\n\\n\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4de1bb2a",
   "metadata": {},
   "source": [
    "### Advanced : specific `loc``\n",
    "\n",
    "One can also request the counts for a specific parameter set of the binding array via the argument `loc`, which is a multi-index given as a tuple of integers."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "1b517337",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Counter of PUB 0 at `loc=(,)`: Counter({(4, 1, 1): 3, (1, 2, 4): 3, (0, 0, 0): 2, (5, 3, 0): 2, (2, 1, 5): 2, (3, 3, 0): 2, (3, 1, 5): 2, (2, 0, 2): 2, (5, 1, 3): 2, (1, 1, 1): 2, (2, 1, 1): 2, (0, 2, 2): 2, (0, 3, 2): 1, (0, 2, 0): 1, (2, 3, 3): 1, (4, 4, 3): 1, (5, 5, 3): 1, (4, 3, 0): 1, (5, 2, 0): 1, (4, 2, 5): 1, (2, 5, 2): 1, (1, 1, 5): 1, (5, 1, 5): 1, (0, 2, 3): 1, (2, 1, 3): 1, (0, 3, 3): 1, (4, 0, 0): 1, (3, 4, 0): 1, (5, 4, 2): 1, (1, 2, 1): 1, (5, 2, 3): 1, (0, 5, 0): 1, (5, 2, 2): 1, (0, 3, 4): 1, (3, 4, 1): 1, (1, 1, 4): 1, (3, 0, 5): 1, (1, 3, 2): 1, (0, 0, 5): 1, (3, 1, 3): 1, (2, 3, 1): 1, (0, 0, 2): 1, (4, 3, 4): 1, (2, 1, 4): 1, (5, 0, 5): 1, (5, 2, 4): 1, (5, 2, 1): 1, (2, 0, 0): 1, (3, 5, 0): 1, (4, 1, 2): 1})\n",
      "Counter of PUB 1 at `loc=(0,)`: Counter({(0, 0, 0): 4, (2, 0, 0): 3, (0, 3, 5): 2, (0, 0, 4): 2, (3, 0, 4): 2, (5, 5, 2): 2, (5, 4, 0): 2, (3, 0, 0): 2, (2, 2, 2): 2, (5, 3, 2): 2, (5, 2, 2): 2, (4, 4, 3): 2, (4, 3, 2): 2, (0, 4, 3): 1, (3, 2, 3): 1, (2, 4, 5): 1, (2, 3, 5): 1, (0, 0, 2): 1, (2, 3, 4): 1, (0, 2, 3): 1, (3, 4, 3): 1, (0, 3, 0): 1, (3, 4, 2): 1, (5, 0, 5): 1, (4, 4, 2): 1, (0, 2, 2): 1, (4, 0, 5): 1, (4, 5, 5): 1, (0, 5, 2): 1, (4, 4, 5): 1, (0, 4, 4): 1, (5, 0, 0): 1, (4, 3, 3): 1, (2, 5, 5): 1, (2, 3, 0): 1, (5, 0, 3): 1, (0, 3, 3): 1, (2, 0, 2): 1, (3, 0, 2): 1, (0, 4, 2): 1, (0, 0, 5): 1, (5, 2, 0): 1, (4, 5, 4): 1, (3, 3, 2): 1, (4, 2, 4): 1, (2, 3, 3): 1, (3, 3, 0): 1, (5, 0, 4): 1})\n",
      "Counter of PUB 2 at `loc=(2,0)`: Counter({(5, 0, 2): 4, (0, 0, 5): 3, (3, 5, 5): 3, (4, 0, 0): 2, (0, 2, 0): 2, (3, 0, 2): 2, (4, 2, 5): 2, (2, 4, 5): 2, (5, 0, 0): 2, (4, 0, 2): 2, (4, 0, 5): 2, (3, 0, 3): 2, (0, 5, 2): 2, (0, 0, 0): 2, (3, 4, 5): 1, (5, 5, 0): 1, (4, 4, 4): 1, (0, 2, 3): 1, (5, 5, 2): 1, (4, 4, 0): 1, (2, 4, 0): 1, (5, 2, 4): 1, (2, 2, 0): 1, (2, 5, 0): 1, (3, 1, 1): 1, (4, 5, 3): 1, (0, 3, 0): 1, (4, 3, 0): 1, (3, 0, 0): 1, (0, 2, 2): 1, (3, 2, 4): 1, (5, 0, 4): 1, (5, 4, 5): 1, (3, 3, 4): 1, (4, 3, 5): 1, (0, 4, 5): 1, (0, 4, 0): 1, (4, 2, 2): 1, (3, 0, 5): 1, (2, 0, 0): 1, (2, 5, 5): 1, (0, 4, 4): 1, (4, 4, 5): 1, (0, 4, 3): 1, (2, 0, 3): 1, (3, 5, 0): 1})\n"
     ]
    }
   ],
   "source": [
    "counts = primitive_result[0].get_counts(loc=tuple())  # shortcut : `loc=None` (default)\n",
    "print(f\"Counter of PUB 0 at `loc=(,)`: {counts}\")\n",
    "\n",
    "counts = primitive_result[1].get_counts(\n",
    "    loc=(0,)\n",
    ")  # shortcut : `loc=0` transformed internally to the tuple (0,)\n",
    "print(f\"Counter of PUB 1 at `loc=(0,)`: {counts}\")\n",
    "\n",
    "counts = primitive_result[2].get_counts(loc=(2, 0))\n",
    "print(f\"Counter of PUB 2 at `loc=(2,0)`: {counts}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8eb43516",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}