Skip to content

Commit

Permalink
essential quantities for Qobj static attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
EBB2675 committed Feb 10, 2025
1 parent abe57ff commit fd8e2a1
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 25 deletions.
21 changes: 9 additions & 12 deletions src/nomad_parser_qutip/parsers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@
from pydantic import Field


class NewParserEntryPoint(ParserEntryPoint):
parameter: int = Field(0, description='Custom configuration parameter')

class QutipEntryPoint(ParserEntryPoint):
def load(self):
from nomad_parser_qutip.parsers.parser import NewParser

return NewParser(**self.dict())


parser_entry_point = NewParserEntryPoint(
name='NewParser',
description='New parser entry point configuration.',
mainfile_name_re='.*\.newmainfilename',
from nomad_parser_qutip.parsers.parser import QutipParser
return QutipParser(**self.dict())

parser_entry_point = QutipEntryPoint(
name='QuTiP Parser',
description='Parser for QuTiP outputs in text format.',
mainfile_name_re='.*\.out.*',
mainfile_contents_re=r'EBB2675 Version [\d\.]*', # to be fixed later on with real vals
)
11 changes: 7 additions & 4 deletions src/nomad_parser_qutip/parsers/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,25 @@
)

from nomad.config import config
from nomad.datamodel.metainfo.workflow import Workflow
from nomad.units import ureg
from nomad.parsing.parser import MatchingParser

from nomad_simulations.schema_packages.general import Program, Simulation

configuration = config.get_plugin_entry_point(
'nomad_parser_qutip.parsers:parser_entry_point'
)


class NewParser(MatchingParser):
class QutipParser(MatchingParser):
def parse(
self,
mainfile: str,
archive: 'EntryArchive',
logger: 'BoundLogger',
child_archives: dict[str, 'EntryArchive'] = None,
) -> None:
logger.info('NewParser.parse', parameter=configuration.parameter)
simulation = Simulation()
simulation.program = Program(name='QuTiP')
archive.data = simulation

archive.workflow2 = Workflow(name='test')
92 changes: 83 additions & 9 deletions src/nomad_parser_qutip/schema_packages/schema_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@
from nomad.config import config
from nomad.datamodel.data import Schema
from nomad.datamodel.metainfo.annotations import ELNAnnotation, ELNComponentEnum
from nomad.metainfo import Quantity, SchemaPackage
from nomad.metainfo import (Quantity,
SchemaPackage,
SubSection,
MEnum,
Section)
from nomad.datamodel.data import ArchiveSection


configuration = config.get_plugin_entry_point(
'nomad_parser_qutip.schema_packages:schema_package_entry_point'
Expand All @@ -22,17 +28,85 @@
m_package = SchemaPackage()


class NewSchemaPackage(Schema):
name = Quantity(
type=str, a_eln=ELNAnnotation(component=ELNComponentEnum.StringEditQuantity)
class Qobj(ArchiveSection):
"""
A section to semantically represent a QuTiP Qobj.
The main quantities are:
dims : The Hilbert space dimensions as a nested list (e.g. [[2], [1]] for a ket).
shape : The shape of the underlying data matrix (e.g. [2, 1] for a column vector).
type : A string (enumerated) to label the Qobj (e.g. 'ket', 'bra', 'oper', 'super').
dtype : The data type indicator (for example, 'Dense' or 'csr') showing the
numerical storage format.
isherm : A Boolean flag indicating whether an operator is Hermitian.
(For state vectors, this property is typically not meaningful.)
data : The numerical data stored as a 2D array (matrix) containing the Qobj values.
"""

dims = Quantity(
type=list,
shape=['*', '*'],
description=(
"""Hilbert space dimensions of the quantum object. For example, a ket
state in a 2-dimensional space may have dims=[[2], [1]]."""
),
)
message = Quantity(type=str)

def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None:
super().normalize(archive, logger)
shape = Quantity(
type=list,
shape=['*'],
description=(
"""Shape of the underlying data matrix. For example, a state vector (ket)
might have shape=[2, 1]."""
),
)

type = Quantity(
type=MEnum('ket', 'bra', 'oper', 'super'),
description=(
"""Type of the quantum object. Examples include 'ket' for state vectors,
'bra' for dual vectors, 'oper' for operators, and 'super' for superoperators."""
),
)

logger.info('NewSchema.normalize', parameter=configuration.parameter)
self.message = f'Hello {self.name}!'
dtype = Quantity(
type=str,
description=(
"""Numerical storage format of the Qobj's data. For example, 'Dense' for a
full matrix or 'csr' for a compressed sparse row representation."""
),
)

isherm = Quantity(
type=bool,
description=(
"""Flag indicating whether the operator is Hermitian."""
),
)

data = Quantity(
type=np.ndarray,
shape=['*', '*'],
description=(
"""The numerical matrix data of the quantum object.
It is stored as a 2D array."""
),
)

def normalize(self, archive, logger) -> None:
"""
Normalization method to check consistency of the Qobj.
For instance, one could verify that the provided `shape` matches the shape of `data`
or that the product of the dimensions implied by `dims` is consistent with `data.shape`.
"""
super().normalize(archive, logger)
# this is just a placeholder, will take care of it later.
if self.data is not None:
data_shape = list(self.data.shape)
if self.shape != data_shape:
logger.warning(
f"Inconsistent shape: quantity 'shape' is {self.shape} but data.shape is {data_shape}."
)

m_package.__init_metainfo__()
1 change: 1 addition & 0 deletions tests/data/example.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
EBB2675 Version 0.0.1

0 comments on commit fd8e2a1

Please sign in to comment.