graphinvent/GraphGenerator.py
def build_graphs(self) ->  int:
        """
        Builds molecular graphs in batches, starting from empty graphs.

        Returns:
        -------
            n_generated_so_far (int) : Number molecules built (may be >
                                       `self.batch_size` due to buffer).
        """
        softmax = torch.nn.Softmax(dim=1)

        # keep track of a few things...
        n_generated_so_far = 0
        t_bar = tqdm(total=self.batch_size)
        generation_round = 0

        # generate graphs in a batch, saving graphs when either the terminate
        # action or an invalid action is sampled, until `self.batch_size` number
        # of graphs have been generated
        while n_generated_so_far < self.batch_size:

            # predict the APDs for this batch of graphs
            apd = softmax(self.model(self.nodes, self.edges))

            # sample the actions from the predicted APDs
            add, conn, term, invalid, likelihoods_just_sampled = self.get_actions(apd)

            # indicate (with a 1) the structures which have been properly terminated
            self.properly_terminated[n_generated_so_far:(n_generated_so_far + len(term))] = 1

            # collect the indices for all structures to write (and reset) this round
            termination_idc = torch.cat((term, invalid))

            # never write out the dummy graph at index 0
            termination_idc = termination_idc[termination_idc != 0]

            # copy the graphs indicated by `terminated_idc` to the tensors for
            # finished graphs (i.e. `generated_{nodes/edges}`)
            n_generated_so_far = self.copy_terminated_graphs(
                termination_idc,
                n_generated_so_far,
                generation_round,
                likelihoods_just_sampled
            )

            # apply actions to all graphs (note: applies dummy actions to
            # terminated graphs, since output will be reset anyways)
            self.apply_actions(add,
                               conn,
                               generation_round,
                               likelihoods_just_sampled)

            # after actions are applied, reset graphs which were set to
            # terminate this round
            self.reset_graphs(termination_idc)

            # update variables for tracking the progress
            t_bar.update(len(termination_idc))
            generation_round += 1

        t_bar.close()  # done sampling

        return n_generated_so_far

        Builds molecular graphs in batches, starting from empty graphs.

        Returns:
        -------
            n_generated_so_far (int) : Number molecules built (may be >
                                       `self.batch_size` due to buffer).
        
Builds molecular graphs in batches, starting from empty graphs.
Builds molecular graphs in batches starting from empty graphs .
def build_graphs(self) ->  int:
        softmax = torch.nn.Softmax(dim=1)
        n_generated_so_far = 0
        t_bar = tqdm(total=self.batch_size)
        generation_round = 0
        while n_generated_so_far < self.batch_size:
            apd = softmax(self.model(self.nodes, self.edges))
            add, conn, term, invalid, likelihoods_just_sampled = self.get_actions(apd)
            self.properly_terminated[n_generated_so_far:(n_generated_so_far + len(term))] = 1
            termination_idc = torch.cat((term, invalid))
            termination_idc = termination_idc[termination_idc != 0]
            n_generated_so_far = self.copy_terminated_graphs(
                termination_idc,
                n_generated_so_far,
                generation_round,
                likelihoods_just_sampled
            )
            self.apply_actions(add,
                               conn,
                               generation_round,
                               likelihoods_just_sampled)
            self.reset_graphs(termination_idc)
            t_bar.update(len(termination_idc))
            generation_round += 1
        t_bar.close()  
        return n_generated_so_far
def build_graphs ( self ) -> int : softmax = torch . nn . Softmax ( dim = 1 ) n_generated_so_far = 0 t_bar = tqdm ( total = self . batch_size ) generation_round = 0 while n_generated_so_far < self . batch_size : apd = softmax ( self . model ( self . nodes , self . edges ) ) add , conn , term , invalid , likelihoods_just_sampled = self . get_actions ( apd ) self . properly_terminated [ n_generated_so_far : ( n_generated_so_far + len ( term ) ) ] = 1 termination_idc = torch . cat ( ( term , invalid ) ) termination_idc = termination_idc [ termination_idc != 0 ] n_generated_so_far = self . copy_terminated_graphs ( termination_idc , n_generated_so_far , generation_round , likelihoods_just_sampled ) self . apply_actions ( add , conn , generation_round , likelihoods_just_sampled ) self . reset_graphs ( termination_idc ) t_bar . update ( len ( termination_idc ) ) generation_round += 1 t_bar . close ( ) return n_generated_so_far
Builds molecular graphs in batches, starting from empty graphs.
Builds molecular graphs in batches starting from empty graphs .
"""
        Builds molecular graphs in batches, starting from empty graphs.

        Returns:
        -------
            n_generated_so_far (int) : Number molecules built (may be >
                                       `self.batch_size` due to buffer).
        """ # keep track of a few things... # generate graphs in a batch, saving graphs when either the terminate # action or an invalid action is sampled, until `self.batch_size` number # of graphs have been generated # predict the APDs for this batch of graphs # sample the actions from the predicted APDs # indicate (with a 1) the structures which have been properly terminated # collect the indices for all structures to write (and reset) this round # never write out the dummy graph at index 0 # copy the graphs indicated by `terminated_idc` to the tensors for # finished graphs (i.e. `generated_{nodes/edges}`) # apply actions to all graphs (note: applies dummy actions to # terminated graphs, since output will be reset anyways) # after actions are applied, reset graphs which were set to # terminate this round # update variables for tracking the progress # done sampling
n_generated_so_far (int) : Number molecules built (may be >
`self.batch_size` due to buffer).
n_generated_so_far ( int ) : Number molecules built ( may be > ` self . batch_size ` due to buffer ) .
self