EUROPEAN ORGANIZATION FOR NUCLEAR RESEARCH

Bug in Sequences and how it might affect you

A bug was reported in July 2013 in the sequence expansion in MAD-X.

In some cases of expanding a sequence within a sequence, MAD-X ignored the implicit "REFER=centre" or any explicit "REFER= " instructions and was attempting to expand the sequence such that the entry was always at the location specified by the "at= " instruction, thereby attempting to create negative drifts in some cases, either before or after the inserted sub-sequence.

This caused MAD-X to stop with an error.

A fix has been implemented from version 5.01.03 onwards and tested to work well.

Problem with "adapted" sequences

We have also discovered that this bug has been present for quite some time and that some users have taken the habit of circumventing it by writing sequence files that do not conform to the rules of sequence expansions.

The expansion of these "adapted" sequences will fail now that the bug has been fixed.

Example of an "adapted" sequence

Here is one simple example of a sub-sequence in a sequence that was "adapted" to the bug:
SEC1 : SEQUENCE, L = 10.00; // sub-sequence
  ...
ENDSEQUENCE;
and later
MACH : SEQUENCE, L = 100.00; //main sequence
  SEC1,  at =   0.0;
  ...
ENDSEQUENCE;
Following the rules of sequence expansion, and in particular the implicit "REFER=centre" when no explicit "REFER= " is specified, the sequence SEC1 would be placed with its center at position 0.0 in the main sequence. Logically a negative drift of 5m would have to be created between the marker at the start of MACH and the marker at the start of SEC1.

The bug made that sequence expandable with no negative drift produced, i.e. with the marker at the start of SEC1 at position 0.0 in the MACH sequence.

With the bugfix implemented, the expansion of the MACH sequence as written above will fail with the following error message:

 +=+=+= fatal: negative drift between elements  mach$start:1 and sec1$start:1, length -5.00e+00 

Fix to "adapted" sequences

In order to be conforming to the sequence expansion rules, the MACH sequence could simply be rewritten with an explicit "REFER= " statement as:
MACH : SEQUENCE, REFER=entry, L = 100.00;
  SEC1,  at =   0.0;
  ...
ENDSEQUENCE;

CAUTION: The simple introduction of "REFER=entry" above is not universal. It will not work in particular if the main sequence mixes sub-sequences and simple elements.

In that case it would be more appropriate to rewrite the MACH example as follows to insert the quadrupole just at the end of sub-sequence SEC1.

MACH : SEQUENCE, REFER=centre, L = 100.00;
  SEC1,  at =   5.0;
  QD: QUADRUPOLE, L=1, at= 10.5
  ...
ENDSEQUENCE;
Some cases can be more intricate and require further manual editing.

Further help

We are sorry for the inconvenience that this might cause if you have sequences that had been "adapted" to the bug and that now need to be fixed.

In case you need assistance with this process, you can send an email to MAD-X Support and we will work out the best solution with you.

Last updated: Ghislain Roy, 22 October 2013