Problem in thermal conductivity calculations

I am a new user of LAMMPS, and I am trying to test thermal conductivity calculations on metals that already have defects in the lattice. For this, I am using the SNAP potential (though I can try EAM as well), but the problem remains the same. I am using the input script provided in the LAMMPS example for the Müller-Plathe method, making changes according to my metal. The variable tdiff is defined in this script.

I have the error :ERROR: Variable tdiff: Fix in variable not computed at a compatible time (src/variable.cpp:1854)

Last command: run 20000

Most likely you have a thermo output that does not match a fix ave/time. You need to share your input file, as it is impossible to provide help with so little information available.

As this is your first post, Please Read This First: Guidelines and Suggestions for posting LAMMPS questions. It will make communication more effective.

units           metal
dimension       3
boundary        p p p
atom_style      atomic
# Lattice and region definition
variable        x equal 14
variable        y equal 14
variable        z equal 28
lattice         bcc 3.16
region          box block 0 $x 0 $y 0 $z
create_box      2 box  # Create box for two atom types
create_atoms    1 box

mass            1 183.84

# Include potential file
include         W_2940_2017_2_He_JW2013.snap
# Create 10 He atoms randomly
mass            2 4.0026
create_atoms    2 random 10 54321 box
# Create vacancies by deleting atoms in specified regions (customized)
region          vac1 block 1 2 1 2 1 2
region          vac2 block 3 4 3 4 3 4
region          vac3 block 5 6 5 6 5 6
region          vac4 block 7 8 7 8 7 8

group           tungsten type 1
group           vac1 region vac1
group           vac2 region vac2
group           vac3 region vac3
group           vac4 region vac4
group           vacancies union vac1 vac2 vac3 vac4
delete_atoms    group vacancies
# Velocity initialization
velocity        all create 300 87287
neighbor        0.3 bin
neigh_modify    delay 0 every 1

# Minimize the structure
minimize        1.0e-4 1.0e-6 100 1000

# 1st equilibration run
fix             1 all nvt temp 300 300 0.1
thermo          100
run             5000

velocity        all scale 300

unfix           1

# 2nd equilibration run
compute         ke all ke/atom
variable        temp atom c_ke/1.5

fix             1 all nve

thermo          1000
run             20000

# Compute layers and thermal conductivity
compute         layers all chunk/atom bin/1d z lower 0.05 units reduced
fix             2 all ave/chunk 10 100 1000 layers v_temp file profile.mp
fix             3 all thermal/conductivity 10 z 20
# Run simulation to gather initial data
thermo          1000
run             20000
# Now define tdiff variable after initial data collection
variable        tdiff equal f_2[11][3]-f_2[1][3]
thermo_style    custom step temp epair etotal f_3 v_tdiff
thermo_modify   colname f_3 E_delta colname v_tdiff dTemp_step
# Reset thermal/conductivity fix
unfix           3
fix             3 all thermal/conductivity 10 z 20
variable start_time equal time
variable kappa equal (f_3/(time-${start_time})/(lx*ly)/2.0)*(lz/2.0)/f_ave
fix             ave all ave/time 1 1 1000 v_tdiff ave running
thermo_style    custom step temp epair etotal f_3 v_tdiff f_ave
thermo_modify   colname f_3 E_delta colname v_tdiff dTemp_step colname f_ave dTemp
run             20000
print           "Running average thermal conductivity: $(v_kappa:%.2f)"```

Please follow the advice of @hothello and study the forum guidelines (carefully, i.e. expand all the subitems) since this will also explain how to properly quote text files so that they are properly readable and special characters are not interpreted as typesetting instructions. Have you looked at your post? does it show all characters in your input correctly??

I have corrected the above input script. Thank you very much for help. input file now looks fine after putting (```).