Assertion Error in PyTensor

I am going through the PyTensor tutorial on the scan mechanism and am trying to run the code as given in the tutorial:

import theano
import theano.tensor as T
import numpy as np

vector1 = T.vector('vector1')
vector2 = T.vector('vector2')

output, updates = theano.scan(fn=lambda a, b : a * b, sequences=[vector1, vector2])

f = theano.function(inputs=[vector1, vector2],
                    outputs=output,
                    updates=updates)

This results in an Assertion Error that seems to come from theano:

---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
Input In [54], in <cell line: 22>()
     15 output, updates = theano.scan(fn=lambda a, b : a * b, sequences=[vector1, vector2])
     17 # The first output contains the outputs of fn from every timestep concatenated into a tensor. 
     18 # In our case, the output of a single timestep is a scalar so output is a vector where output[i] is the output of the i-th iteration.
     19 # The second output details if and how the execution of the Scan updates any shared variable in the graph. 
     20 # It should be provided as an argument when compiling the Theano function.
---> 22 f = theano.function(inputs=[vector1, vector2],
     23                     outputs=output,
     24                     updates=updates)

File ~/anaconda3/envs/vb_model_2/lib/python3.9/site-packages/theano/compile/function/__init__.py:337, in function(inputs, outputs, mode, updates, givens, no_default_updates, accept_inplace, name, rebuild_strict, allow_input_downcast, profile, on_unused_input)
    331     fn = orig_function(
    332         inputs, outputs, mode=mode, accept_inplace=accept_inplace, name=name
    333     )
    334 else:
    335     # note: pfunc will also call orig_function -- orig_function is
    336     #      a choke point that all compilation must pass through
--> 337     fn = pfunc(
    338         params=inputs,
    339         outputs=outputs,
    340         mode=mode,
    341         updates=updates,
    342         givens=givens,
    343         no_default_updates=no_default_updates,
    344         accept_inplace=accept_inplace,
    345         name=name,
    346         rebuild_strict=rebuild_strict,
    347         allow_input_downcast=allow_input_downcast,
    348         on_unused_input=on_unused_input,
    349         profile=profile,
    350         output_keys=output_keys,
    351     )
    352 return fn

File ~/anaconda3/envs/vb_model_2/lib/python3.9/site-packages/theano/compile/function/pfunc.py:524, in pfunc(params, outputs, mode, updates, givens, no_default_updates, accept_inplace, name, rebuild_strict, allow_input_downcast, profile, on_unused_input, output_keys)
    519         si = In(
    520             variable=sv, value=sv.container, mutable=False, borrow=True, shared=True
    521         )
    522     inputs.append(si)
--> 524 return orig_function(
    525     inputs,
    526     cloned_outputs,
    527     mode,
    528     accept_inplace=accept_inplace,
    529     name=name,
    530     profile=profile,
    531     on_unused_input=on_unused_input,
    532     output_keys=output_keys,
    533 )

File ~/anaconda3/envs/vb_model_2/lib/python3.9/site-packages/theano/compile/function/types.py:1981, in orig_function(inputs, outputs, mode, accept_inplace, name, profile, on_unused_input, output_keys)
   1970     m = Maker(
   1971         inputs,
   1972         outputs,
   (...)
   1978         name=name,
   1979     )
   1980     with config.change_flags(compute_test_value="off"):
-> 1981         fn = m.create(defaults)
   1982 finally:
   1983     t2 = time.time()

File ~/anaconda3/envs/vb_model_2/lib/python3.9/site-packages/theano/compile/function/types.py:1836, in FunctionMaker.create(self, input_storage, trustme, storage_map)
   1833 start_import_time = theano.link.c.cmodule.import_time
   1835 with config.change_flags(traceback__limit=config.traceback__compile_limit):
-> 1836     _fn, _i, _o = self.linker.make_thunk(
   1837         input_storage=input_storage_lists, storage_map=storage_map
   1838     )
   1840 end_linker = time.time()
   1842 linker_time = end_linker - start_linker

File ~/anaconda3/envs/vb_model_2/lib/python3.9/site-packages/theano/link/basic.py:266, in LocalLinker.make_thunk(self, input_storage, output_storage, storage_map)
    265 def make_thunk(self, input_storage=None, output_storage=None, storage_map=None):
--> 266     return self.make_all(
    267         input_storage=input_storage,
    268         output_storage=output_storage,
    269         storage_map=storage_map,
    270     )[:3]

File ~/anaconda3/envs/vb_model_2/lib/python3.9/site-packages/theano/link/vm.py:1188, in VMLinker.make_all(self, profiler, input_storage, output_storage, storage_map)
   1185 else:
   1186     post_thunk_clear = None
-> 1188 vm = self.make_vm(
   1189     order,
   1190     thunks,
   1191     input_storage,
   1192     output_storage,
   1193     storage_map,
   1194     post_thunk_clear,
   1195     computed,
   1196     compute_map,
   1197     self.updated_vars,
   1198 )
   1200 vm.storage_map = storage_map
   1201 vm.compute_map = compute_map

File ~/anaconda3/envs/vb_model_2/lib/python3.9/site-packages/theano/link/vm.py:893, in VMLinker.make_vm(self, nodes, thunks, input_storage, output_storage, storage_map, post_thunk_clear, computed, compute_map, updated_vars)
    890 pre_call_clear = [storage_map[v] for v in self.no_recycling]
    892 try:
--> 893     from theano.link.c.cvm import CVM
    894 except (MissingGXX, ImportError):
    895     CVM = None

File ~/anaconda3/envs/vb_model_2/lib/python3.9/site-packages/theano/link/c/cvm.py:13, in <module>
      9 if not config.cxx:
     10     raise MissingGXX(
     11         "lazylinker will not be imported if theano.config.cxx is not set."
     12     )
---> 13 from theano.link.c import lazylinker_c
     15 class CVM(lazylinker_c.CLazyLinker, VM):
     16     def __init__(self, fgraph, *args, **kwargs):

File ~/anaconda3/envs/vb_model_2/lib/python3.9/site-packages/theano/link/c/lazylinker_c.py:157, in <module>
    153             _logger.info(f"New version {lazylinker_ext._version}")
    155 from lazylinker_ext.lazylinker_ext import *  # noqa
--> 157 assert force_compile or (version == get_version())

AssertionError: 

I have tried changing the pytensor.config.optimizer settings, but it doesn’t make a difference.
I’m using python 3.9.12, pytensor 2.11.2, theano 1.1.2, pymc 3.11.4, numpy 1.21.5

I have learned that pytensor is a fork of theano for newer PyMC versions, so I updated to a newer version of PyMC (5.0.1), deleted theano and replaced theano with pytensor in the code. Now it works.

Just for your reference, the most recent version of PyMC is currently 5.3.1.

[When I try to import pymc and run MCMC, it throws an assertion error, as below:

This is just last 2 lines:let me know if traceback is needed
167 from lazylinker_ext.lazylinker_ext import CLazyLinker, get_version # noqa
168 from lazylinker_ext.lazylinker_ext import * # noqa
→ 170 assert force_compile or (version == get_version())

AssertionError:

When i import pymc3, the mcmc runs fine but then arviz does not work

It may be easier to open a new thread and provide the details (e.g., versions of different packages you have installed) there.