Skip to content

Custom script with pyCALPHAD caused a System.ArgumentOutOfRangeException #4836

@hotswitchEXE

Description

@hotswitchEXE

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest released version
  • Search the existing issues, especially the pinned issues.

Exception report

Exception:
System.ArgumentOutOfRangeException: Arvon on oltava vähintään nolla ja pienempi kuin konsolin puskurikoko kyseissä ulottuvuudessa. (Translation: Value must be at least zero and smaller than the console's buffer size in the specific dimension.)
Parametrin nimi: left (Parameter's name: left)
Todellinen arvo oli -2. (True value was -2.)
   kohteessa Microsoft.PowerShell.Internal.VirtualTerminal.set_CursorLeft(Int32 value)
   kohteessa Microsoft.PowerShell.PSConsoleReadLine.ReallyRender(RenderData renderData, String defaultColor)
   kohteessa Microsoft.PowerShell.PSConsoleReadLine.ForceRender()
   kohteessa Microsoft.PowerShell.PSConsoleReadLine.Insert(Char c)
   kohteessa Microsoft.PowerShell.PSConsoleReadLine.SelfInsert(Nullable`1 key, Object arg)
   kohteessa Microsoft.PowerShell.PSConsoleReadLine.ProcessOneKey(ConsoleKeyInfo key, Dictionary`2 dispatchTable, Boolean ignoreIfNoAction, Object arg)
   kohteessa Microsoft.PowerShell.PSConsoleReadLine.InputLoop()
   kohteessa Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics)

Screenshot

Last 200 Keys:
Ctrl+Alt+\ O m i s t a j a Ctrl+Alt+\ a n a c o n d a 3 Ctrl+Alt+\ p y t h o n . e x e ' Space ' c : Ctrl+Alt+\ U s e r s Ctrl+Alt+\ O m i s t a j a Ctrl+Alt+\ . v s c o d e Ctrl+Alt+\ e x t e n s i o n s Ctrl+Alt+\ m s - p y t h o n . d e b u g p y - 2 0 2 5 . 1 0 . 0 - w i n 3 2 - x 6 4 Ctrl+Alt+\ b u n d l e d Ctrl+Alt+\ l i b s Ctrl+Alt+\ d e b u g p y Ctrl+Alt+\ l a u n c h e r ' Space ' 5 1 3 2 3 ' Space ' - - ' Space ' C : Ctrl+Alt+\ U s e r s Ctrl+Alt+\ O m i s t a j a Ctrl+Alt+\ m e
t a l l i c _ g l a s s _ a n a l y s i s . p y ' Space Enter

Environment data

PS Version: 5.1.19041.6093
PS HostName: ConsoleHost
PSReadLine Version: 2.0.0-beta2
PSReadLine EditMode: Windows
OS: 10.0.19041.1 (WinBuild.160101.0800)
BufferWidth: 166
BufferHeight: 12

Steps to reproduce

Step 1. Download pyCALPHAD and launch it from VSCode using Anaconda Navigator.
Step 2. Download the mmc1.TDB database.
Step 3. Run the script below:
`from pycalphad import Database, equilibrium, variables as v
import numpy as np
import matplotlib.pyplot as plt

Load thermodynamic database

dbf = Database(r'C:\Users\Omistaja\anaconda3\Lib\site-packages\pycalphad\tests\databases\mmc1.TDB')

Define system components

components = ['AL', 'Y', 'FE', 'SI', 'VA']

Define temperature and composition range

T_range = np.linspace(500, 1500, 200)
conds = {
v.X('Y'): 0.006,
v.X('FE'): 0.094,
v.X('SI'): 0.01,
v.T: T_range,
v.P: 101325
}

Define phases to consider (expand if needed)

phases = ['LIQUID', 'FCC_A1', 'BCC_A2', 'HCP_A3', 'AL13FE4', 'Y5SI3', 'SI', 'C14_LAVES']

Run equilibrium calculation

eq = equilibrium(dbf, components, phases, conds, output='NP')

Extract temperature array

T = np.squeeze(eq['T'].values)

Prepare clean dictionary of phase fractions

phase_fractions = {}
all_phases = np.unique(eq['Phase'].values)

for phase in all_phases:
try:
# Extract and squeeze NP values
np_vals = eq.sel(Phase=phase)['NP'].values
np_vals = np.squeeze(np_vals).astype(float)

    # Skip phases with NaN or shape mismatch
    if np_vals.shape != T.shape:
        continue
    if np.isnan(np_vals).all():
        continue

    phase_fractions[phase] = np_vals
except Exception as e:
    print(f"Skipping phase {phase} due to error: {e}")
    continue

Plot

plt.figure(figsize=(10, 6))
for phase, np_vals in phase_fractions.items():
plt.plot(T, np_vals, label=phase, linewidth=2)

Detect melting and crystallization if LIQUID is present

if 'LIQUID' in phase_fractions:
liq = phase_fractions['LIQUID']
for i in range(len(liq) - 1):
if np.isnan(liq[i]) or np.isnan(liq[i + 1]):
continue
if liq[i] > 1e-3 and liq[i + 1] <= 1e-3:
T_cryst = T[i]
print(f"Crystallization temperature: {T_cryst:.2f} K")
plt.axvline(T_cryst, color='blue', linestyle='--', linewidth=1)
plt.text(T_cryst + 10, 0.5, 'Cryst.', color='blue', rotation=90)
if liq[i] <= 1e-3 and liq[i + 1] > 1e-3:
T_melt = T[i + 1]
print(f"Melting temperature: {T_melt:.2f} K")
plt.axvline(T_melt, color='red', linestyle='--', linewidth=1)
plt.text(T_melt + 10, 0.5, 'Melt', color='red', rotation=90)

plt.xlabel("Temperature (K)")
plt.ylabel("Phase Fraction")
plt.title("Phase Stability vs Temperature")
plt.legend()
plt.grid(True)
plt.tight_layout()
plt.show()`

Expected behavior

Output with the phase diagram and the crystallisation and melting temperatures of a custom aluminium alloy.

Actual behavior

The phase diagram contained no phase lines, and no temperatures were calculated. Instead, the terminal gave the following output:
Skipping phase due to error: "'Phase' is not a valid dimension or coordinate"
Skipping phase AL13FE4 due to error: "'Phase' is not a valid dimension or coordinate"
Skipping phase FCC_A1 due to error: "'Phase' is not a valid dimension or coordinate"
Skipping phase LIQUID due to error: "'Phase' is not a valid dimension or coordinate"
No artists with labels found to put in legend. Note that artists whose label start with an underscore are ignored when legend() is called with no argument.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions