def create_EPR(self, host_a_id, host_b_id, q_id=None, block=False): """ Creates an EPR pair for two qubits and returns one of the qubits. Args: host_a_id (String): ID of the first host who gets the EPR state. host_b_id (String): ID of the second host who gets the EPR state. q_id (String): Optional id which both qubits should have. block (bool): Determines if the created pair should be blocked or not. Returns: Returns a qubit. The qubit belongs to host a. To get the second qubit of host b, the receive_epr function has to be called. """ name1 = str(uuid.uuid4()) name2 = str(uuid.uuid4()) host_a = self._hosts.get_from_dict(host_a_id) host_b = self._hosts.get_from_dict(host_b_id) qubit1 = (QuTipBackend.QubitCollection(name1), name1) qubit2 = (QuTipBackend.QubitCollection(name2), name2) qubit1[0].apply_single_gate(snot(), qubit1[1]) qubit1[0].add_qubit(qubit2[0]) qubit2 = (qubit1[0], name2) qubit1[0].apply_double_gate(cnot(), qubit1[1], qubit2[1]) q1 = Qubit(host_a, qubit=qubit1, q_id=q_id, blocked=block) q2 = Qubit(host_b, qubit=qubit2, q_id=q1.id, blocked=block) self.store_ent_pair(host_a.host_id, host_b.host_id, q2) return q1
def H(self, qubit): """ Perform Hadamard gate on a qubit. Args: qubit (Qubit): Qubit on which gate should be applied to. """ gate = snot() qubit_collection, name = qubit.qubit qubit_collection.apply_single_gate(gate, name)
def __init__(self, initialState_list, targetGate=snot(1), configPath='./problems/hadamard/hadamard_config.yaml', verbose=2): targetState_list = [ targetGate * initialState for initialState in initialState_list ] testState_list = [ singleStateFunc(initialState_list[i], targetState_list[i]) for i in range(len(initialState_list)) ] testGate = singleGateFunc(targetGate) problem.__init__(self, testState_list=testState_list, testGate=testGate, configPath=configPath, verbose=verbose)
from qutip.qip.operations import snot from qutip.qip.operations import gate_expand_1toN from numToByte import numToByte from byteToNum import byteToNum from measureTest import measure ser = serial.Serial('COM4', 115200) numQ = 2 #number of qubits measureQ = 0 #index of qubit being measured count = 0 outState = qt.basis(2**numQ) - qt.basis(2**numQ) #empty state of appropriate size #----------------------------------------------------------------------------- #State and gate to test stateNotNorm = qt.basis(2**numQ, 0) + qt.basis(2**numQ, 2) state = stateNotNorm.unit() #normalized input state gate = gate_expand_1toN(snot(), numQ, 1) #testing gate #gate = snot() #----------------------------------------------------------------------------- for i in range(2**numQ): #write each element of input state to serial as 8-bit fixed pt probAmp = state.__getitem__(i)[0][0] ser.write(numToByte(probAmp.real)) ser.write(numToByte(probAmp.imag)) for j in range(2**numQ): #write each element of input gate to serial as 8-bit fixed pt rowArray = gate.__getitem__(j) row = rowArray[0] for num in row: ser.write(numToByte(num.real)) ser.write(numToByte(num.imag)) print("Receiving") while (count < 2**numQ): #read each element of output state and convert to float, then put into outState numRe = byteToNum(ser.readline().rstrip().lstrip()[0])
def ch(): return controlled_gate(snot())
def evolute(state): state = cnot(3, 0, 1) * state state = snot(3, 0) * state return state.unit()
"No problem specified in config. Please specify a problem e.g. 'problem: hadamard'" ) initial_state_list = [] if 'input-states' in config.keys(): input_states = config['input-states'] else: input_states = [] for state in input_states: qubit_list = [] for qubit in reversed(state): if qubit == 'r': qubit_list.append(rand_ket(2)) elif qubit == '+': qubit_list.append(snot(1) * qt.basis(2, 0)) elif qubit == '-': qubit_list.append(snot(1) * qt.basis(2, 1)) elif qubit == '0': qubit_list.append(qt.basis(2, 0)) elif qubit == '1': qubit_list.append(qt.basis(2, 1)) else: raise Exception( "Invalid qubit choice: %s, please choose '0', '1', '+', or '-'" .format(qubit)) initial_state_list.append(tensor(qubit_list)) if len(initial_state_list) == 0 and 'state' in config.keys(): raise Exception( "No states specified, please specify 'input-states:' in {}".format(
LAST = bytearray() LAST.append(0) numQ = 3 #number of qubits measureQ = 0 #index of qubit being measured #----------------------------------------------------------------------------- #Initial state state = qt.basis(2**numQ, 1) state = state.unit() #----------------------------------------------------------------------------- #----------------------------------------------------------------------------- #Gates (operate on state from highest to lowest) gates = [] gates.append(qt.tensor(snot(), snot(), snot())) #gates.append(qt.tensor(qt.qeye(4), qt.sigmax())) #constant f ex. 1 #gates.append(qt.qeye(8)) #constant f ex. 2 #gates.append(cnot(numQ, 0, 2)) #balanced f ex. 1 gates.append(qt.tensor(qt.qeye(2), cnot())) #balanced f ex. 2 gates.append(qt.tensor(snot(), snot(), qt.qeye(2))) #----------------------------------------------------------------------------- def emulate(): ser = serial.Serial('COM4', 115200, timeout=1) #open COM4 port at 115200 baud count = 0 gateCount = 0 outState = qt.basis(2**numQ) - qt.basis( 2**numQ) #empty state of appropriate size
import numpy as np import matplotlib.pyplot as plt from qutip import sigmaz, destroy, basis from qutip.qip.device import Processor from qutip.qip.operations import snot a = destroy(2) Hadamard = snot() plus_state = (basis(2, 1) + basis(2, 0)).unit() tlist = np.arange(0.00, 20.2, 0.2) T2 = 5 processor = Processor(1, t2=T2) processor.add_control(sigmaz()) processor.pulses[0].coeff = np.ones(len(tlist)) processor.pulses[0].tlist = tlist result = processor.run_state( plus_state, e_ops=[a.dag() * a, Hadamard * a.dag() * a * Hadamard]) fig, ax = plt.subplots() # detail about length of tlist needs to be fixed ax.plot(tlist[:-1], result.expect[1][:-1], '.', label="simulation") ax.plot(tlist[:-1], np.exp(-1. / T2 * tlist[:-1]) * 0.5 + 0.5, label="theory") ax.set_xlabel("t") ax.set_ylabel("Ramsey signal") ax.legend() ax.set_title("Relaxation T2=5") ax.grid() fig.tight_layout() fig.show()
num = num - 8 if (num >= 4): tot += 0.0625 num = num - 4 if (num >= 2): tot += 0.03125 num = num - 2 if (num >= 1): tot += 0.015625 num = num - 1 if (negative): tot = -tot return tot ser = serial.Serial('COM4', 9600) j = 1 numQ = 2 nums = [] gate = gate_expand_1toN(snot(), numQ, 1) for i in range(2**numQ): rowArray = gate.__getitem__(i) row = rowArray[0] for num in row: nums.append(numToByte(num.real)) nums.append(numToByte(num.imag)) for num in nums: ser.write(num) print(j, ": ", byteToNum(ser.readline().rstrip().lstrip()[0])) j += 1 ser.close()