queredity issue

5 views
Skip to first unread message

Otto Kohulák

unread,
Sep 9, 2021, 10:40:19 AM9/9/21
to aiida...@googlegroups.com
Dear AiiDA users,

I just encountered some strange AiiDA behaviour. Here is a sample of my code:

from aiida.orm import Data

class P(Data):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

class P1(P):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

class P2(P):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

As you can see, P<class> is a subclass of Data<class>, and P1 and P2 are subclasses of  P. I assume when I build a query searching for all Data node I should find all of them, and that's true:

P().store()
P1().store()

qb = QueryBuilder()
qb.append(Data)
for x in qb.iterall(): print(x)

results in:

[<P: uuid: 61b02ab5-1049-4430-814f-c2d273f8bb81 (pk: 18)>]
[<P1: uuid: 44fd554d-bee1-4cd3-8aaf-d8e29acf46ca (pk: 19)>]

This is expected behaviour for me. But when I querry for P class its subclasses are missing:

qb = QueryBuilder()
qb.append(P)
for x in qb.iterall(): print(x)

[<P: uuid: 61b02ab5-1049-4430-814f-c2d273f8bb81 (pk: 18)>]

This is not What I expected. So what am I missing?

cheers

Otto


Chris Sewell

unread,
Sep 9, 2021, 11:15:37 AM9/9/21
to aiida...@googlegroups.com
Heya,

What entry point names have you given these classes?
I think you will also need to give P1/P2 “subclassed” names, e.g. something like `myplugin.p`, `myplugin.p.p1`, `myplugin.p.p2`

Take for example, `Data` and `Dict`:


In [10]: QueryBuilder().append(Data).queryhelp
Out[10]: 
{'path': [{'entity_type': 'data.Data.',
   'orm_base': 'node',
   'tag': 'Data_1',
   'joining_keyword': None,
   'joining_value': None,
   'edge_tag': None,
   'outerjoin': False}],
 'filters': {'Data_1': {'node_type': {'like': 'data.%'}}},
 'project': {'Data_1': []},
 'order_by': [],
 'limit': None,
 'offset': None,
 'distinct': False}

In [9]: QueryBuilder().append(Dict).queryhelp
Out[9]: 
{'path': [{'entity_type': 'data.core.dict.Dict.',
   'orm_base': 'node',
   'tag': 'Dict_1',
   'joining_keyword': None,
   'joining_value': None,
   'edge_tag': None,
   'outerjoin': False}],
 'filters': {'Dict_1': {'node_type': {'like': 'data.core.dict.%'}}},
 'project': {'Dict_1': []},
 'order_by': [],
 'limit': None,
 'offset': None,
 'distinct': False}

You’ll see that we are filtering, with Data, for all entry points (% is a wildcard),
Whereas for Dict, it is for all entry points starting with “core.dict"

Cheers,
Chris

--
AiiDA is supported by the NCCR MARVEL (http://nccr-marvel.ch/), funded by the Swiss National Science Foundation, and by the European H2020 MaX Centre of Excellence (http://www.max-centre.eu/).
 
Before posting your first question, please see the posting guidelines at http://www.aiida.net/?page_id=356 .
---
You received this message because you are subscribed to the Google Groups "aiidausers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to aiidausers+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/aiidausers/CAK%3DGx5i2QZ5ke%2Buxhd3V3-TU%3Dc8jeGFU%3DsQMxj1tjEUy1cwtLQ%40mail.gmail.com.

Reply all
Reply to author
Forward
0 new messages