title: How to use custom/non-default tf.Graph in Tensorflow the correct way?
body: <p>I'm very new to <code>Tensorflow</code> and I am reading <a href="https://rads.stackoverflow.com/amzn/click/com/1786462168" rel="nofollow noreferrer" rel="nofollow noreferrer">https://www.amazon.com/TensorFlow-Machine-Learning-Cookbook-McClure/dp/1786462168</a>. One argument that I have noticed in <code>tf.Session</code> is <code>graph</code>.  I like having full control of the flow and I was wondering <strong>how to properly use the <code>tf.Graph</code> with <code>tf.Session</code> and how to add computations to a specific graph?</strong> Also, what is the canonical syntax, if any, in which people add operations to a specific graph in <code>Tensorflow</code>? </p>
  
  <p>Analogous to the below: </p>
  
  <pre><code>t = np.linspace(0,2*np.pi)
  fig, ax = plt.subplots()
  ax.scatter(x=t, y=np.sin(t))
  </code></pre>
  
  <p>compared to: </p>
  
  <pre><code>plt.scatter(x=t, y=np.sin(t))
  </code></pre>
  
  <p>How can I have this same flexibility with <code>tf.Graph()</code>? </p>
  
  <pre><code>G = tf.Graph()
  
  t_query = np.linspace(0,2*np.pi,50)
  pH_t = tf.placeholder(tf.float32, shape=t_query.shape)
  
  def simple_sinewave(t, name=None):
      return tf.sin(t, name=name)
  
  with tf.Session() as sess:
      r = sess.run(simple_sinewave(pH_t), feed_dict={pH_t:t_query})
  # array([  0.00000000e+00,   1.27877161e-01,   2.53654599e-01,
  # ...
  #         -1.27877384e-01,   1.74845553e-07], dtype=float32)
  </code></pre>
  
  <p>Now trying it with specifying a <code>graph</code> argument:</p>
  
  <pre><code>with tf.Session(graph=G) as sess:
      r = sess.run(simple_sinewave(pH_t), feed_dict={pH_t:t_query})
  ---------------------------------------------------------------------------
  RuntimeError                              Traceback (most recent call last)
  &lt;ipython-input-51-d73a1f0963e3&gt; in &lt;module&gt;()
       26 #         -1.27877384e-01,   1.74845553e-07], dtype=float32)
       27 with tf.Session(graph=G) as sess:
  ---&gt; 28     r = sess.run(simple_sinewave(pH_t), feed_dict={pH_t:t_query})
  </code></pre>
  
  <p>...
      RuntimeError: The Session graph is empty.  Add operations to the graph before calling run().</p>
  
  <h2>Update using <a href="https://stackoverflow.com/users/4790871/david-parks">David Parks</a> answer with this problem:</h2>
  
  <pre><code># Custom Function
  def simple_sinewave(t, name=None):
      return tf.sin(t, name=name)
  
  # Synth graph
  G = tf.Graph()
  
  # Build Graph
  with G.as_default():
      t_query = np.linspace(0,2*np.pi,50)
      pH_t = tf.placeholder(tf.float32, shape=t_query.shape)
  
  # Run session using Graph
  with tf.Session(graph=G) as sess:
      r = sess.run(simple_sinewave(pH_t), feed_dict={pH_t:t_query})
  r
  # array([  0.00000000e+00,   1.27877161e-01,   2.53654599e-01,
  #          3.75266999e-01,   4.90717560e-01,   5.98110557e-01,
  # ...
  #         -4.90717530e-01,  -3.75267059e-01,  -2.53654718e-01,
  #         -1.27877384e-01,   1.74845553e-07], dtype=float32)
  </code></pre>
  
  <p><strong>Bonus: Is there a specific nomenclature for naming placeholder variables in Tensorflow? Like <code>pd.DataFrame</code> as <code>df_data</code>.</strong></p>