function measureGatesArePositionedLast(circuitState){
  let measureGates = [];
  for (let i = 0; i < circuitState.steps.length; i++) {
    let gates = circuitState.steps[i]["gates"];
    for (let j = 0; j < gates.length; j++) {
      let gate = gates[j];
      if (gate.name.includes("measure-")){
        measureGates.push(gate.targets[0]);
      } else {
        if (Object.prototype.hasOwnProperty.call(gate, "targets")) {
          let targets = gate.targets;
          for (let j = 0; j < targets.length; j++){
            if (measureGates.includes(targets[j])) {
              return false;
            }
          }
        }
        if (Object.prototype.hasOwnProperty.call(gate, "controls")) {
          for (let i = 0; i < gate["controls"].length; i++) {
            let controlInfo = gate["controls"][i];
            let target = controlInfo["target"];
            if (measureGates.includes(target)) {
              return false;
            }
          }
        }
      }
    }
  }
  return true;
}
// make sure that no non-measure gate is placed after a measure gate on any given qubit
make sure that no non-measure gate is placed after a measure gate on any given qubit
make sure that no non - measure gate is placed after a measure gate on any given qubit
function measureGatesArePositionedLast(circuitState){
  let measureGates = [];
  for (let i = 0; i < circuitState.steps.length; i++) {
    let gates = circuitState.steps[i]["gates"];
    for (let j = 0; j < gates.length; j++) {
      let gate = gates[j];
      if (gate.name.includes("measure-")){
        measureGates.push(gate.targets[0]);
      } else {
        if (Object.prototype.hasOwnProperty.call(gate, "targets")) {
          let targets = gate.targets;
          for (let j = 0; j < targets.length; j++){
            if (measureGates.includes(targets[j])) {
              return false;
            }
          }
        }
        if (Object.prototype.hasOwnProperty.call(gate, "controls")) {
          for (let i = 0; i < gate["controls"].length; i++) {
            let controlInfo = gate["controls"][i];
            let target = controlInfo["target"];
            if (measureGates.includes(target)) {
              return false;
            }
          }
        }
      }
    }
  }
  return true;
}
function measureGatesArePositionedLast ( circuitState ) { let measureGates = [ ] ; for ( let i = 0 ; i < circuitState . steps . length ; i ++ ) { let gates = circuitState . steps [ i ] [ "gates" ] ; for ( let j = 0 ; j < gates . length ; j ++ ) { let gate = gates [ j ] ; if ( gate . name . includes ( "measure-" ) ) { measureGates . push ( gate . targets [ 0 ] ) ; } else { if ( Object . prototype . hasOwnProperty . call ( gate , "targets" ) ) { let targets = gate . targets ; for ( let j = 0 ; j < targets . length ; j ++ ) { if ( measureGates . includes ( targets [ j ] ) ) { return false ; } } } if ( Object . prototype . hasOwnProperty . call ( gate , "controls" ) ) { for ( let i = 0 ; i < gate [ "controls" ] . length ; i ++ ) { let controlInfo = gate [ "controls" ] [ i ] ; let target = controlInfo [ "target" ] ; if ( measureGates . includes ( target ) ) { return false ; } } } } } } return true ; }
make sure that no non-measure gate is placed after a measure gate on any given qubit
make sure that no non - measure gate is placed after a measure gate on any given qubit