def test_depolarizer_different_gate(): q1 = cirq.QubitId() q2 = cirq.QubitId() cnot = Job(cirq.Circuit([ cirq.Moment([cirq.CNOT(q1, q2)]), ])) allerrors = DepolarizerChannel(probability=1.0, depolarizing_gates= [xmon_gates.ExpZGate(), xmon_gates.ExpWGate()]) p0 = cirq.Symbol(DepolarizerChannel._parameter_name + '0') p1 = cirq.Symbol(DepolarizerChannel._parameter_name + '1') p2 = cirq.Symbol(DepolarizerChannel._parameter_name + '2') p3 = cirq.Symbol(DepolarizerChannel._parameter_name + '3') error_sweep = (cirq.Points(p0.name, [1.0]) + cirq.Points(p1.name, [1.0]) + cirq.Points(p2.name, [1.0]) + cirq.Points(p3.name, [1.0])) cnot_then_z = Job( cirq.Circuit([ cirq.Moment([cirq.CNOT(q1, q2)]), cirq.Moment([xmon_gates.ExpZGate(half_turns=p0).on(q1), xmon_gates.ExpZGate(half_turns=p1).on(q2)]), cirq.Moment([xmon_gates.ExpWGate(half_turns=p2).on(q1), xmon_gates.ExpWGate(half_turns=p3).on(q2)]) ]), cnot.sweep * error_sweep) assert allerrors.transform_job(cnot) == cnot_then_z
def nearest_neighbor_hopping(amplitude, qubits): """ Implement a nearest neighbor hopping step between two electrons using xmon gates only. """ assert len(qubits) == 2 q0 = qubits[0] q1 = qubits[1] amplitude /= np.pi yield xmon_gates.ExpWGate(half_turns=.5, axis_half_turns=0)(q0) yield xmon_gates.ExpWGate(half_turns=-.5, axis_half_turns=.5)(q1) yield xmon_gates.ExpZGate(half_turns=1)(q1) yield xmon_gates.Exp11Gate(half_turns=1.0)(q0, q1) yield xmon_gates.ExpWGate(half_turns=amplitude, axis_half_turns=0)(q0) yield xmon_gates.ExpWGate(half_turns=-amplitude, axis_half_turns=.5)(q1) yield xmon_gates.Exp11Gate(half_turns=1.0)(q0, q1) yield xmon_gates.ExpWGate(half_turns=-.5, axis_half_turns=0)(q0) yield xmon_gates.ExpWGate(half_turns=-.5, axis_half_turns=.5)(q1) yield xmon_gates.ExpZGate(half_turns=1)(q1)
def test_depolarizer_multiple_realizations(): q1 = cirq.QubitId() q2 = cirq.QubitId() cnot = Job(cirq.Circuit([ cirq.Moment([cirq.CNOT(q1, q2)]), ])) all_errors3 = DepolarizerChannel(probability=1.0, realizations=3) p0 = cirq.Symbol(DepolarizerChannel._parameter_name + '0') p1 = cirq.Symbol(DepolarizerChannel._parameter_name + '1') error_sweep = (cirq.Points(p0.name, [1.0, 1.0, 1.0]) + cirq.Points(p1.name, [1.0, 1.0, 1.0])) cnot_then_z3 = Job( cirq.Circuit([ cirq.Moment([cirq.CNOT(q1, q2)]), cirq.Moment([xmon_gates.ExpZGate(half_turns=p0).on(q1), xmon_gates.ExpZGate(half_turns=p1).on(q2)]) ]), cnot.sweep * error_sweep) assert all_errors3.transform_job(cnot) == cnot_then_z3
def test_depolarizer_parameterized_gates(): q1 = cirq.QubitId() q2 = cirq.QubitId() cnot_param = cirq.Symbol('cnot_turns') cnot_gate = xmon_gates.Exp11Gate(half_turns=cnot_param).on(q1, q2) job_sweep = cirq.Points('cnot_turns', [0.5]) cnot = Job(cirq.Circuit([cirq.Moment([cnot_gate])]), job_sweep) all_errors = DepolarizerChannel(probability=1.0) p0 = cirq.Symbol(DepolarizerChannel._parameter_name + '0') p1 = cirq.Symbol(DepolarizerChannel._parameter_name + '1') error_sweep = cirq.Points(p0.name, [1.0]) + cirq.Points(p1.name, [1.0]) cnot_then_z = Job( cirq.Circuit([ cirq.Moment([cnot_gate]), cirq.Moment([xmon_gates.ExpZGate(half_turns=p0).on(q1), xmon_gates.ExpZGate(half_turns=p1).on(q2)]) ]), job_sweep * error_sweep) assert all_errors.transform_job(cnot) == cnot_then_z
def test_depolarizer_all_errors(): q1 = ops.QubitId() q2 = ops.QubitId() cnot = Job(circuits.Circuit([ circuits.Moment([ops.CNOT(q1, q2)]), ])) allerrors = DepolarizerChannel(probability=1.0) p0 = Symbol(DepolarizerChannel._parameter_name + '0') p1 = Symbol(DepolarizerChannel._parameter_name + '1') error_sweep = Points(p0.name, [1.0]) + Points(p1.name, [1.0]) cnot_then_z = Job( circuits.Circuit([ circuits.Moment([ops.CNOT(q1, q2)]), circuits.Moment([ xmon_gates.ExpZGate(half_turns=p0).on(q1), xmon_gates.ExpZGate(half_turns=p1).on(q2) ]) ]), cnot.sweep * error_sweep) assert allerrors.transform_job(cnot) == cnot_then_z
def _expZGate(cmd, mapping, qubits): """ Translate a ExpZ gate into a Cirq gate. Args: - cmd (:class:`projectq.ops.Command`) - a projectq command instance - mapping (:class:`dict`) - a dictionary of qubit mappings - qubits (list of :class:cirq.QubitID`) - cirq qubits Returns: - :class:`cirq.Operation` """ qb_pos = [mapping[qb.id] for qr in cmd.qubits for qb in qr] assert len(qb_pos) == 1 cirqGate = cxmon.ExpZGate(half_turns=cmd.gate.angle / cmath.pi) if get_control_count(cmd) > 0: ctrl_pos = [mapping[qb.id] for qb in cmd.control_qubits] return cop.ControlledGate(cirqGate)( *[qubits[c] for c in ctrl_pos + qb_pos]) else: return cirqGate(*[qubits[idx] for idx in qb_pos])
xmon_gate_ext = Extensions() xmon_gate_ext.add_cast( desired_type=xmon_gates.XmonGate, actual_type=ops.RotXGate, conversion=lambda e: xmon_gates.ExpWGate(half_turns=e.half_turns, axis_half_turns=0)) xmon_gate_ext.add_cast( desired_type=xmon_gates.XmonGate, actual_type=ops.RotYGate, conversion=lambda e: xmon_gates.ExpWGate(half_turns=e.half_turns, axis_half_turns=0.5)) xmon_gate_ext.add_cast( desired_type=xmon_gates.XmonGate, actual_type=ops.RotZGate, conversion=lambda e: xmon_gates.ExpZGate(half_turns=e.half_turns)) xmon_gate_ext.add_cast( desired_type=xmon_gates.XmonGate, actual_type=ops.Rot11Gate, conversion=lambda e: xmon_gates.Exp11Gate(half_turns=e.half_turns)) xmon_gate_ext.add_cast( desired_type=xmon_gates.XmonGate, actual_type=ops.MeasurementGate, conversion=lambda e: xmon_gates.XmonMeasurementGate( key=e.key, invert_mask=e.invert_mask))
def __init__(self, probability=0.001, realizations=1, depolarizing_gates=(xmon_gates.ExpZGate(),)): self.p = probability self.realizations = realizations self.depolarizing_gates = depolarizing_gates
def onsite(amplitude, qubit): """ Implement a local (onsite) fermionic term using xmon gates only. """ assert len(qubit) == 1 yield xmon_gates.ExpZGate(half_turns=amplitude / np.pi)(qubit)