# Assertion Error running Dustin's Coin Flipping Toy Example

**URL:** <https://discourse.edwardlib.org/t/assertion-error-running-dustins-coin-flipping-toy-example/831>\
**Category:** General\
**Created:** [June 26, 2018, 6:21pm UTC](https://discourse.edwardlib.org/t/assertion-error-running-dustins-coin-flipping-toy-example/831 "2018-06-26T18:21:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ikibkilam](https://avatars.discourse-cdn.com/v4/letter/i/73ab20/32.png) [@ikibkilam](https://discourse.edwardlib.org/u/ikibkilam)\
**Post date:** [June 26, 2018, 6:21pm UTC](https://discourse.edwardlib.org/t/assertion-error-running-dustins-coin-flipping-toy-example/831/1 "2018-06-26T18:21:29Z")

</div>

Hello, I am new to Edward. I tried running Dustin’s sample coin flipping example, and keep running into an Assertion Error with ed.complete\_conditional§. I also run into the same error in completely separate code. What am I doing wrong? Thanks for any guidance. Ikib

from **future** import absolute\_import  
from **future** import division  
from **future** import print\_function

import edward as ed  
import numpy as np  
import six  
import tensorflow as tf

from edward.models import Bernoulli, Beta  
tf.reset\_default\_graph()  
ed.set\_seed(42)

def main(\_):

# DATA

x\_data = np.array([0, 1, 0, 0, 0, 0, 0, 0, 0, 1])

# MODEL

p = Beta(1.0, 1.0)  
x = Bernoulli(probs=p, sample\_shape=10)

# COMPLETE CONDITIONAL

p\_cond = ed.complete\_conditional§

sess = ed.get\_session()

print(‘p(probs | x) type:’, p\_cond.parameters[‘name’])  
param\_vals = sess.run({key: val for  
key, val in six.iteritems(p\_cond.parameters)  
if isinstance(val, tf.Tensor)}, {x: x\_data})  
print(‘parameters:’)  
for key, val in six.iteritems(param\_vals):  
print(’%s:\t%.3f’ % (key, val))

if **name** == “ **main** ”:  
tf.app.run()

AssertionError Traceback (most recent call last)  
 in ()  
23  
24 if **name** == “ **main** ”:  
—\> 25 tf.app.run()

c:\users\bikim\appdata\local\conda\conda\envs\tensorflow\lib\site-packages\tensorflow\python\platform\app.py in run(main, argv)  
124 # Call the main function, passing through any arguments  
125 # to the final program.  
–\> 126 \_sys.exit(main(argv))  
127  
128

in main(\_)  
10  
11 # COMPLETE CONDITIONAL  
—\> 12 p\_cond = ed.complete\_conditional§  
13  
14 sess = ed.get\_session()

c:\users\bikim\appdata\local\conda\conda\envs\tensorflow\lib\site-packages\edward\inferences\conjugacy\conjugacy.py in complete\_conditional(rv, cond\_set)  
156  
157 scope\_name = scope + str(time.time()) # ensure unique scope when copying  
–\> 158 log\_joint\_copy = copy(log\_joint, swap\_dict, scope=scope\_name + ‘swap’)  
159 nat\_params = tf.gradients(log\_joint\_copy, s\_stat\_placeholders)  
160

c:\users\bikim\appdata\local\conda\conda\envs\tensorflow\lib\site-packages\edward\util\random\_variables.py in copy(org\_instance, dict\_swap, scope, replace\_itself, copy\_q, copy\_parent\_rvs)  
268 # op. Therefore copy the op itself.  
269 op = tensor.op  
–\> 270 new\_op = copy(op, dict\_swap, scope, True, copy\_q, False)  
271  
272 output\_index = op.outputs.index(tensor)

c:\users\bikim\appdata\local\conda\conda\envs\tensorflow\lib\site-packages\edward\util\random\_variables.py in copy(org\_instance, dict\_swap, scope, replace\_itself, copy\_q, copy\_parent\_rvs)  
314 [], # input types; will add them afterwards  
315 original\_op,  
–\> 316 op\_def)  
317  
318 # advertise op early to break recursions

c:\users\bikim\appdata\local\conda\conda\envs\tensorflow\lib\site-packages\tensorflow\python\framework\ops.py in **init** (self, node\_def, g, inputs, output\_types, control\_inputs, input\_types, original\_op, op\_def)  
1730 # Refactor so we don’t have to do this here.  
1731 grouped\_inputs = self.\_reconstruct\_sequence\_inputs(  
-\> 1732 op\_def, inputs, node\_def.attr)  
1733 self.\_c\_op = \_create\_c\_op(self.\_graph, node\_def, grouped\_inputs,  
1734 control\_input\_ops)

c:\users\bikim\appdata\local\conda\conda\envs\tensorflow\lib\site-packages\tensorflow\python\framework\ops.py in \_reconstruct\_sequence\_inputs(self, op\_def, inputs, attrs)  
1804 i += input\_len  
1805  
-\> 1806 assert i == len(inputs)  
1807 return grouped\_inputs  
1808

AssertionError:

---

<div class="post-metadata">

**Author:** ![richardk53](https://avatars.discourse-cdn.com/v4/letter/r/ed655f/32.png) [@richardk53](https://discourse.edwardlib.org/u/richardk53)\
**Post date:** [July 9, 2018, 9:14am UTC](https://discourse.edwardlib.org/t/assertion-error-running-dustins-coin-flipping-toy-example/831/2 "2018-07-09T09:14:24Z")

</div>

Hi, I encountered this bug today aswell and was able to bypass it in tensorflow 1.8.  
The error is actually not specific to the Coin Flipping example, indeed you get this error when you try to use edward’s copy function in tensorflow\>=1.8.

There are currently at least 2 tensorflow-1.8 related bugs in edward, which are related to tensorflow switching to the C-API for graphs by default since tf 1.8.  
e.g. tf.Session().graph.\_c\_graph is None in tf 1.7 but not in 1.8.  
The first bug and a fix is described [here](https://github.com/blei-lab/edward/issues/893#issuecomment-388792874).

The second bug, which you are seeing, is because [edwards’ copy function](https://github.com/blei-lab/edward/blob/master/edward/util/random_variables.py) creates a tf.Operation with the argument inputs=[] with the comment that the inputs are added later.  
However, using the C-API in the backend for the graph, tf.Operation apparently requires non-empty inputs.  
In tensorflow 1.8, you may bypass this bug by setting the environment variable TF\_C\_API\_GRAPH\_CONSTRUCTION=0. I don’t think it works for current tf 1.9 though, as the constructor of the Operation class changed and does not check for self.graph.\_c\_graph anymore.
