Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graph created from a Design is empty #23

Closed
audreyseo opened this issue Jul 30, 2021 · 2 comments
Closed

Graph created from a Design is empty #23

audreyseo opened this issue Jul 30, 2021 · 2 comments
Assignees
Labels
bug Something isn't working fixed

Comments

@audreyseo
Copy link
Collaborator

For example, if we take the following code:

    def test_more_complex(self):
        student = ts.Unit(
            "Student", attributes=[]
        )  # object type, specify data types through object type
        race = student.nominal("Race", cardinality=5, exactly=1)  # proper OOP
        ses = student.numeric("SES")
        test_score = student.nominal("Test score")
        tutoring = student.nominal("treatment")
        race.associates_with(test_score)
        student.associates_with(test_score)
        race.moderate(ses, on=test_score)
        design = ts.Design(dv=test_score, ivs=[race, ses])
        gr = design.graph
        print(gr.get_nodes())
        self.assertTrue(gr.has_variable(test_score))

the print will print an empty list, and the assertion will fail. This seems to be because graph.py requires relationships from tisane.og_variable instead of from tisane.variable, and tisane.design calls tisane.graph.Graph.add_relationship to add edges:

# from tisane/graph.py
    def add_relationship(
        self, relationship: Union[Has, Treatment, Nest, Associate, Cause, Moderate]
    ):
        if isinstance(relationship, Has):
            identifier = relationship.variable
            measure = relationship.measure
            repetitions = relationship.repetitions
            self.has(identifier, measure, relationship, repetitions)
        elif isinstance(relationship, Treatment):
            identifier = relationship.unit
            treatment = relationship.treatment
            repetitions = relationship.num_assignments
            self.treat(unit=identifier, treatment=treatment, treatment_obj=relationship)
        # ...

The types for relationship are imported from tisane.og_variable, which means that none of the relationships are added as edges.

@audreyseo audreyseo added the bug Something isn't working label Jul 30, 2021
@audreyseo
Copy link
Collaborator Author

Changing the imports on tisane/graph.py has helped, like so:

from tisane.og_variable import (
    # AbstractVariable,
    Nominal,
    Ordinal,
    Numeric,
    # Unit,
    Treatment,
    # Nest,
    RepeatedMeasure,
    # Has,
    # Associate,
    # Cause,
    # Moderate,
    GreaterThanOne,
)
from tisane.variable import (
    Measure,
    Unit,
    AbstractVariable,
    Has,
    Associates,
    Causes,
    Moderates,
    Nests
)

I'm just not sure if I'm breaking anything by doing so.

@emjun
Copy link
Owner

emjun commented Aug 2, 2021

ts.og_variable was a temporary hack I had used to test a few tests for API changes.

Since commit, this is no longer a bug. The graph has all the expected variables and edges. This means that this program:

        student = ts.Unit("Student")
        # Variables instantiated through Units
        race = student.nominal("Race", cardinality=5)
        ses = student.numeric("SES")
        test_score = student.numeric("Test score")
        tutoring = student.nominal("treatment", cardinality=3)

has the following nodes/passes the below tests that were failing before:

        self.assertTrue(gr.has_variable(student))
        self.assertTrue(gr.has_variable(race))
        self.assertTrue(gr.has_variable(ses))
        self.assertTrue(gr.has_variable(test_score))
        self.assertFalse(gr.has_variable(tutoring))

See test_graph.py for the above test case.

@emjun emjun closed this as completed Aug 2, 2021
@emjun emjun added the fixed label Aug 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed
Projects
None yet
Development

No branches or pull requests

2 participants