Skip to content

Commit

Permalink
Replace overridden toString methods with toHumanString
Browse files Browse the repository at this point in the history
  • Loading branch information
vasinov committed Sep 30, 2019
1 parent 9f973ed commit c8ddf8f
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/main/scala/scotty/quantum/State.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ case class Superposition(register: QubitRegister, state: Vector) extends State {
if (state.length == 0) sp
else ctx.tensorProduct(register, this, sp)

override def toString: String = s"Superposition(${state.toList})"
def toHumanString: String = s"Superposition(${state.toList})"
}

case class Collapsed(register: QubitRegister, index: Int) extends State {
Expand Down
8 changes: 4 additions & 4 deletions src/main/scala/scotty/quantum/StateReader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ case class StateProbabilityReader(state: State)(implicit ctx: QuantumContext) ex
case c: Collapsed => Seq(StateData(c.toBinary, Complex(1), 1))
}

override def toString: String = read.flatMap(p => {
def toHumanString: String = read.flatMap(p => {
val prob = p.probability.toPercent

if (prob == 0) None
Expand Down Expand Up @@ -55,7 +55,7 @@ case class QubitProbabilityReader(register: Option[QubitRegister], state: State)

def read(label: String): Option[QubitData] = read.find(q => q.label.contains(label))

override def toString: String = read.map(_.toString).mkString("\n")
def toHumanString: String = read.map(_.toString).mkString("\n")
}

object QubitProbabilityReader {
Expand All @@ -67,7 +67,7 @@ object QubitProbabilityReader {
case class QubitData(label: Option[String], index: Int, probabilityOfOne: Double) {
val probabilityOfZero: Double = 1 - probabilityOfOne

override def toString: String = {
def toHumanString: String = {
val probZero = probabilityOfZero.toPercent
val probOne = probabilityOfOne.toPercent

Expand Down Expand Up @@ -105,7 +105,7 @@ case class BlochSphereReader(state: State)(implicit ctx: QuantumContext) extends
Array(BlochSphereData(phi, theta, Coordinates(x, y, z)))
}

override def toString: String = {
def toHumanString: String = {
val state = read(0)
val phi = Math.toDegrees(state.phi)
val theta = Math.toDegrees(state.theta)
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/scotty/quantum/gate/Gate.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ trait TargetGate extends Gate {

def matrix: Matrix = matrixGen.apply(params)

override def toString: String = matrix.toList.map(_.toList.mkString(" ")).mkString("\n")
def toHumanString: String = matrix.toList.map(_.toList.mkString(" ")).mkString("\n")
}

trait ControlGate extends Gate {
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/scotty/quantum/math/Complex.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package scotty.quantum.math
import scotty.quantum.QuantumContext.{Matrix, Vector}

case class Complex(r: Float, i: Float) {
override def toString: String = Complex.toString(this)
def toHumanString: String = Complex.toString(this)
}

object Complex {
Expand Down

0 comments on commit c8ddf8f

Please sign in to comment.