Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Improve string and HTML representations.#856

Open
pfebrer wants to merge 2 commits intometatensor:mainfrom
pfebrer:reprs
Open

Improve string and HTML representations.#856
pfebrer wants to merge 2 commits intometatensor:mainfrom
pfebrer:reprs

Conversation

@pfebrer
Copy link
Contributor

@pfebrer pfebrer commented Feb 13, 2025

Addresses #847 and #848 by modifying slightly the string representation of TensorMap and TensorBlock and introducing a new HTML representation.

If you agree with the way it looks I'll finish some details and then we would need to port the string representations to the C++ api as well (which I don't know exactly how to test yet 😅 )

This is how it looks with the tensormap from the tutorials:

import metatensor

tensor = metatensor.load("spherical-expansion.mts")

TensorBlock html:

Screenshot from 2025-02-13 14-29-48

TensorBlock str:

Screenshot from 2025-02-13 14-37-18

TensorMap html (blocks expand by clicking):

Screenshot from 2025-02-13 14-30-06

TensorMap str:

Screenshot from 2025-02-13 14-37-21

Copy link
Member

@Luthaf Luthaf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also handle Labels in a similar ways. Here are a couple of tweak suggestions:

  • TensorBlock str should remove the <> and maybe be simplified like this:
metatensor.TensorBlock:
    values shape: (...)
    samples: [system, atom]
    components: [xyz, o3_mu]
    properties: [n1, n2, ...]
  • TensorMap str: I would also remove <>, and remove the 4 in 4 keys: (names). Just having keys: (names) like we do for samples/components/properties would be enough

Finally, all of them needs to check what happen when you have 100+ entries in Labels (key/samples/properties). We will likely want to truncate the representation at some point and/or add scroll bars.

@@ -0,0 +1,167 @@
# CSS styles for the HTML representation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be in a separate file if we want to make it easy to use from C++ as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants