Skip to content

Combine multiple stream output and maintain spacing like in Jupyter lab #690

@bpuchala

Description

@bpuchala

Context

I may be overlooking a configuration option, but it seems like there is no way to configure formatting output like the following to appear in a single output cell like in Jupyter lab:

{
   "cell_type": "code",
   "execution_count": 4,
   "id": "0d81eb38-8ea4-4856-be7e-1c2d335b81a8",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-- Begin: Enumerating occupations by supercell --\n",
      "\n",
      "Enumerate configurations for: SCEL1_1_1_1_0_0_0\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3 configurations (0 new, 0 excluded by filter)\n",
      "\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Enumerate configurations for: SCEL2_2_1_1_0_1_1\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4 configurations (0 new, 0 excluded by filter)\n",
      "\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Enumerate configurations for: SCEL2_2_1_1_0_0_1\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3 configurations (0 new, 0 excluded by filter)\n",
      "\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Enumerate configurations for: SCEL3_3_1_1_0_2_2\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "13 configurations (0 new, 0 excluded by filter)\n",
      "\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Enumerate configurations for: SCEL3_3_1_1_0_2_1\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10 configurations (0 new, 0 excluded by filter)\n",
      "\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Enumerate configurations for: SCEL3_3_1_1_0_0_2\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10 configurations (0 new, 0 excluded by filter)\n",
      "\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Enumerate configurations for: SCEL4_4_1_1_0_0_0\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "36 configurations (0 new, 0 excluded by filter)\n",
      "\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Enumerate configurations for: SCEL4_4_1_1_0_1_0\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "27 configurations (0 new, 0 excluded by filter)\n",
      "\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Enumerate configurations for: SCEL4_4_1_1_0_0_2\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "36 configurations (0 new, 0 excluded by filter)\n",
      "\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Enumerate configurations for: SCEL4_4_1_1_0_0_3\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "24 configurations (0 new, 0 excluded by filter)\n",
      "\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Enumerate configurations for: SCEL4_4_1_1_0_2_1\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "15 configurations (0 new, 0 excluded by filter)\n",
      "\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Enumerate configurations for: SCEL4_2_2_1_0_1_0\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "23 configurations (0 new, 0 excluded by filter)\n",
      "\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Enumerate configurations for: SCEL4_2_2_1_1_1_0\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10 configurations (0 new, 0 excluded by filter)\n",
      "\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  DONE\n",
      "\n",
      "-- Summary --\n",
      "\n",
      "  Initial number of configurations: 214\n",
      "  Final number of configurations: 214\n",
      "\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Committing...\n",
      "\n",
      "EnumData:\n",
      "- id: main\n",
      "- supercell_set: 13 supercells\n",
      "- configuration_set: 214 configurations\n",
      "\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "overwrite: SiGe_occ/enumerations/enum.main/scel_set.json\n",
      "overwrite: SiGe_occ/enumerations/enum.main/config_set.json\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# Enumerate configurations in supercells with volume 1 to 4\n",
    "# - Configurations are stored in the enumeration's ConfigurationSet\n",
    "enum = project.enum.get(id=\"main\")\n",
    "enum.occ_by_supercell(max=4, min=1)"
   ]
  },

I either get multiple outputs like this:

Image

Or, with nb_merge_streams = True I get a single output with missing newlines like this:

Image

What I want is like this from Jupyter lab:

Image

Proposal

No response

Tasks and updates

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions