Class Qubit
In: rquantum.rb
Parent: Object

A quantum bit, or qubit is a unit of quantum information. That information is described by a state vector in a two-level quantum mechanical system which is formally equivalent to a two-dimensional vector space over the complex numbers. (Wikipedia)

That class represents one qubit.

 q = Qubit.new
 q.reset
 q.to_vector  # -> Vector[Complex(1, 0), Complex(0, 0)]
 q.alpha      # -> Complex(1, 0)
 q.beta       # -> Complex(1, 0)

Qubit class has also methods generated from classes with compute method from the Gates module.

 q = Qubit.new
 q.reset
 q.not
 q.to_vector  # -> Vector[Complex(0, 0), Complex(1, 0)]
 q.phase_shifter 0.2
 q.to_vector  # -> Vector[Complex(0, 0), Complex(0.309016994374947, 0.951056516295154)]

Methods

alpha   beta   measure   new   pr   reset   to_vector  

Public Class methods

At the begining qubit has random amplitudes.

 q = Qubit.new
 q.to_vector        # -> Vector[Complex(-0.273340195540226, -0.459092674794958), Complex(-0.530742833147416, 0.657899003278084)]

Public Instance methods

Returns first amplitude.

 q = Qubit.new
 q.reset
 q.alpha    # -> Complex(1, 0)

Returns second amplitude.

 q = Qubit.new
 q.reset
 q.beta     # -> Complex(0, 0)

Measure the qubit state. If the qubit is in the superposition, then that method get random state (according to the probability computed using amplitudes), set the qubit to it, and returns it - so the method is equivalent to the "real world" check qubit state.

 q = Qubit.new
 q.reset
 q.hadamard
 q.to_vector        # -> Vector[Complex(0.707106781186547, 0.0), Complex(0.707106781186547, 0.0)]
 q.measure  # -> 1
 q.to_vector        # -> Vector[Complex(0, 0), Complex(1, 0)]

Prints the state of the qubit.

Warning: that operations is possible only in the simulator environment. In the "real world" it‘s impossible to check the qubit state without changing it. The "real" check can be done with measure method.

 irb(main):021:0> q.pr
 -0.273340195540226-0.459092674794958i      |0>
 -0.530742833147416+0.657899003278084i      |1>

Resets state of the qubit to the val and deletes all quantum gates.

 q = Qubit.new
 q.hadamard
 q.reset
 q.to_vector        # -> Vector[Complex(1, 0), Complex(0, 0)]

Returns state of qubit as vector with two complex numbers.

 q = Qubit.new
 q.reset
 q.to_vector        # -> Vector[Complex(1, 0), Complex(0, 0)]

[Validate]