

/**
 * This class writes English and Picture files
 * for the approximate compilation, derived in
 * Tuc07a- arXiv:0706.0479, for the evolution operator
 * e^{iH_{line}}, where H_{line} is proportional to
 * the incidence matrix of a line (open string) graph.
 */
 
public class LineSEO_writer extends SEO_writer{
	//private String 	_filePrefix;
	//private int 		_numBits;
    private double 	_strength;
    private int		_numTrots;
	private int 	_suzukiHalfOrder;
	
/**
 *
 */
    public LineSEO_writer(
        String 	filePrefix,
        int 	numBits,
        double 	strength,
        int 	numTrots,
        int		suzukiHalfOrder)
    {
    	super(filePrefix + "_qline", numBits);
 
        _strength= strength;
        _numTrots = numTrots;
        Throw.If(suzukiHalfOrder<1, "suzukiHalfOrder must be >= 1");
        _suzukiHalfOrder = suzukiHalfOrder;
        
      
        write();
        
        closeFiles();        
    }
/**
 * 
 */
    public LineSEO_writer(
    		java.io.PrintWriter  englishOut,
    		java.io.PrintWriter  pictureOut,
    		Boolean doWrite,
    		int numBits,
    		int numBitsInP0Pad,
            double 	strength,
            int 	numTrots,
            int		suzukiHalfOrder)
        {
        	super(englishOut, pictureOut, numBits, numBitsInP0Pad);
 
            _strength= strength;
            _numTrots = numTrots;
            Throw.If(suzukiHalfOrder<1, "suzukiHalfOrder must be >= 1");
            _suzukiHalfOrder = suzukiHalfOrder;
       	
        	
        	if(doWrite){write();}
        }
         
    
    
    
/**
 * 
 */
	public void write(){
		
        SuzWriter sw = new SuzWriter();
        SuzFunctions funs = new SuzFuns1();
    	if(_numTrots>1){
    		int loopNum = getLineCount();
    		writeLOOP(loopNum, _numTrots);
    		SuzWriter.writeSuzuki2k(_suzukiHalfOrder, 
    				_strength/_numTrots, true, funs);
    		writeNEXT(loopNum);
    	}else{
    		SuzWriter.writeSuzuki2k(_suzukiHalfOrder, 
    				_strength, true, funs);
    	}
		
		
	}

/**
*
*/
    private class SuzFuns1 extends SuzFunctions{
    /**
     * 
     */
    	public void writeExpAtimes(double t){
    		writeOneBitGate(
				0, //targetBitPosition, 
	            new OneBitRot(t, OneBitRot.X_AXIS));
    	}

    /**
    *
    */
    	public void writeExpBtimes(double t){
    		int numControls, b, controlCounter;
    		for(numControls=1; numControls<_numBits; numControls++){
                Controls controls = new Controls(_numBits, numControls);
                controls.setControl(0, numControls-1, true);
                controlCounter = 1;
                for(b=numControls-2; b>= 0; b--){
                    controls.setControl(controlCounter, b, false);
                    controlCounter++;
                }
    			writeControlledGate(
    				numControls, //targetBitPosition, 
    	            controls, 
    	            new OneBitRot(t, OneBitRot.X_AXIS));
    		
    		}   	
    	}

    }

/**
*
*/    
   public static void main(String[] args){
       
       new LineSEO_writer(
           "test",// filePrefix, 
           4, //numBits,
           .3, //strength
           3,//numTrots
           3//susukiHalfOrder
           );
          
       
   }   
       
}

