class_docstr: This is an inference class for performing Causal Inference over Bayesian
  Networks or Structural Equation Models.
  
  Parameters
  ----------
  model: pgmpy.base.DAG | pgmpy.models.BayesianNetwork
      The model that we'll perform inference over.
  
  set_nodes: list[node:str] or None
      A list (or set/tuple) of nodes in the Bayesian Network which have been
      set to a specific value per the do-operator.
  
  Examples
  --------
  Create a small Bayesian Network.
  
  >>> from pgmpy.models import BayesianNetwork
  >>> game = BayesianNetwork([('X', 'A'),
  ...                         ('A', 'Y'),
  ...                         ('A', 'B')])
  
  Load the graph into the CausalInference object to make causal queries.
  
  >>> from pgmpy.inference.CausalInference import CausalInference
  >>> inference = CausalInference(game)
  >>> inference.get_all_backdoor_adjustment_sets(X="X", Y="Y")
  >>> inference.get_all_frontdoor_adjustment_sets(X="X", Y="Y")
  
  References
  ----------
  'Causality: Models, Reasoning, and Inference' - Judea Pearl (2000)
class_docstr_tok: ["This","is","an","inference","class","for","performing","Causal","Inference","over","Bayesian","Networks","or","Structural","Equation","Models",".","Parameters","--","--","--","--","--","model",":","pgmpy.base.DAG","|","pgmpy.models.BayesianNetwork","The","model","that","we","'ll","perform","inference","over",".","set_nodes",":","list","[","node",":","str","]","or","None","A","list","(","or","set\/tuple",")","of","nodes","in","the","Bayesian","Network","which","have","been","set","to","a","specific","value","per","the","do-operator",".","Examples","--","--","--","--","Create","a","small","Bayesian","Network",".",">",">",">","from","pgmpy.models","import","BayesianNetwork",">",">",">","game","=","BayesianNetwork","(","[","(","'","X","'",",","'","A","'",")",",","...","(","'","A","'",",","'","Y","'",")",",","...","(","'","A","'",",","'","B","'",")","]",")","Load","the","graph","into","the","CausalInference","object","to","make","causal","queries",".",">",">",">","from","pgmpy.inference.CausalInference","import","CausalInference",">",">",">","inference","=","CausalInference","(","game",")",">",">",">","inference.get_all_backdoor_adjustment_sets","(","X=","''","X","''",",","Y=","''","Y","''",")",">",">",">","inference.get_all_frontdoor_adjustment_sets","(","X=","''","X","''",",","Y=","''","Y","''",")","References","--","--","--","--","--","'Causality",":","Models",",","Reasoning",",","and","Inference","'","-","Judea","Pearl","(","2000",")"]
docstr: Returns a proper backdoor graph for the exposure `X` and outcome `Y`.
  A proper backdoor graph is a graph which remove the first edge of every
  proper causal path from `X` to `Y`.
  
  Parameters
  ----------
  X: list (array-like)
      A list of exposure variables.
  
  Y: list (array-like)
      A list of outcome variables
  
  inplace: boolean
      If inplace is True, modifies the object itself. Otherwise retuns
      a modified copy of self.
  
  Examples
  --------
  >>> from pgmpy.models import BayesianNetwork
  >>> from pgmpy.inference import CausalInference
  >>> model = BayesianNetwork([("x1", "y1"), ("x1", "z1"), ("z1", "z2"),
  ...                        ("z2", "x2"), ("y2", "z2")])
  >>> c_infer = CausalInference(model)
  >>> c_infer.get_proper_backdoor_graph(X=["x1", "x2"], Y=["y1", "y2"])
  <pgmpy.models.BayesianNetwork.BayesianNetwork at 0x7fba501ad940>
  
  References
  ----------
  [1] Perkovic, Emilija, et al. "Complete graphical characterization and construction of adjustment sets in Markov equivalence classes of ancestral graphs." The Journal of Machine Learning Research 18.1 (2017): 8132-8193.
docstr_tok: ["Returns","a","proper","backdoor","graph","for","the","exposure","`","X","`","and","outcome","`","Y","`",".","A","proper","backdoor","graph","is","a","graph","which","remove","the","first","edge","of","every","proper","causal","path","from","`","X","`","to","`","Y","`",".","Parameters","--","--","--","--","--","X",":","list","(","array-like",")","A","list","of","exposure","variables",".","Y",":","list","(","array-like",")","A","list","of","outcome","variables","inplace",":","boolean","If","inplace","is","True",",","modifies","the","object","itself",".","Otherwise","retuns","a","modified","copy","of","self",".","Examples","--","--","--","--",">",">",">","from","pgmpy.models","import","BayesianNetwork",">",">",">","from","pgmpy.inference","import","CausalInference",">",">",">","model","=","BayesianNetwork","(","[","(","``","x1","''",",","``","y1","''",")",",","(","``","x1","''",",","``","z1","''",")",",","(","``","z1","''",",","``","z2","''",")",",","...","(","``","z2","''",",","``","x2","''",")",",","(","``","y2","''",",","``","z2","''",")","]",")",">",">",">","c_infer","=","CausalInference","(","model",")",">",">",">","c_infer.get_proper_backdoor_graph","(","X=","[","``","x1","''",",","``","x2","''","]",",","Y=","[","``","y1","''",",","``","y2","''","]",")","<","pgmpy.models.BayesianNetwork.BayesianNetwork","at","0x7fba501ad940",">","References","--","--","--","--","--","[","1","]","Perkovic",",","Emilija",",","et","al",".","``","Complete","graphical","characterization","and","construction","of","adjustment","sets","in","Markov","equivalence","classes","of","ancestral","graphs",".","''","The","Journal","of","Machine","Learning","Research","18.1","(","2017",")",":","8132-8193","."]
code: def get_proper_backdoor_graph(self, X, Y, inplace=False):
      """
      Returns a proper backdoor graph for the exposure `X` and outcome `Y`.
      A proper backdoor graph is a graph which remove the first edge of every
      proper causal path from `X` to `Y`.
  
      Parameters
      ----------
      X: list (array-like)
          A list of exposure variables.
  
      Y: list (array-like)
          A list of outcome variables
  
      inplace: boolean
          If inplace is True, modifies the object itself. Otherwise retuns
          a modified copy of self.
  
      Examples
      --------
      >>> from pgmpy.models import BayesianNetwork
      >>> from pgmpy.inference import CausalInference
      >>> model = BayesianNetwork([("x1", "y1"), ("x1", "z1"), ("z1", "z2"),
      ...                        ("z2", "x2"), ("y2", "z2")])
      >>> c_infer = CausalInference(model)
      >>> c_infer.get_proper_backdoor_graph(X=["x1", "x2"], Y=["y1", "y2"])
      <pgmpy.models.BayesianNetwork.BayesianNetwork at 0x7fba501ad940>
  
      References
      ----------
      [1] Perkovic, Emilija, et al. "Complete graphical characterization and construction of adjustment sets in Markov equivalence classes of ancestral graphs." The Journal of Machine Learning Research 18.1 (2017): 8132-8193.
      """
      for var in chain(X, Y):
          if var not in self.model.nodes():
              raise ValueError(f"{var} not found in the model.")
  
      model = self.model if inplace else self.model.copy()
      edges_to_remove = []
      for source in X:
          paths = nx.all_simple_edge_paths(model, source, Y)
          for path in paths:
              edges_to_remove.append(path[0])
      model.remove_edges_from(edges_to_remove)
      return model
  
imports: from collections.abc import Iterable
  from itertools import chain, product
  import networkx
  import numpy
  from tqdm.auto import tqdm
  from pgmpy import config
  from pgmpy.estimators.LinearModel import LinearEstimator
  from pgmpy.factors.discrete import DiscreteFactor
  from pgmpy.models import BayesianNetwork
  from pgmpy.utils.sets import _powerset, _variable_or_iterable_to_set
label_desc: Use image node_id 9 for calling the CausalInference obj's underlying member method code with example usage: obj.get_proper_backdoor_graph(X, Y, inplace) and returns: model