Operations


In addition to qubit registers, circuits contain operations (Op). All operations have to reference register qubits by their index.

Scotty supports two types of operations: Gate and Measure.

Measure is a one-qubit operation that forces the superposition to collapse at the end of the circuit execution. Scotty simulator uses the deferred measurement principle meaning that the simulator doesn’t perform any measurements until all operations (besides the Measure itself) are done executing.

RunAndMeasure returns Collapsed but run returns a generic State. If you don’t know whether your circuit contains any Measure operations you’ll have to pattern match on the return type:

QuantumSimulator().run(circuit) match {
  case s: Superposition => println("not measured")
  case s: Collapsed => println("measured")
}

Gate is another Op type and it deserves its own section.