def _circuit_u(theta, phi, lam, phase, simplify=True, atol=DEFAULT_ATOL): qr = QuantumRegister(1, "qr") circuit = QuantumCircuit(qr, global_phase=phase) if not simplify: atol = -1.0 phi = _mod_2pi(phi, atol) lam = _mod_2pi(lam, atol) if abs(theta) > atol or abs(phi) > atol or abs(lam) > atol: circuit._append(UGate(theta, phi, lam), [qr[0]], []) return circuit
def __init__(self): super().__init__( None, name="FakeV2", description="A fake BackendV2 example", online_date=datetime.datetime.utcnow(), backend_version="0.0.1", ) self._target = Target() self._theta = Parameter("theta") self._phi = Parameter("phi") self._lam = Parameter("lambda") rx_props = { (0, ): InstructionProperties(duration=5.23e-8, error=0.00038115), (1, ): InstructionProperties(duration=4.52e-8, error=0.00032115), } self._target.add_instruction(RXGate(self._theta), rx_props) rx_30_props = { (0, ): InstructionProperties(duration=1.23e-8, error=0.00018115), (1, ): InstructionProperties(duration=1.52e-8, error=0.00012115), } self._target.add_instruction(RXGate(np.pi / 6), rx_30_props, name="rx_30") u_props = { (0, ): InstructionProperties(duration=5.23e-8, error=0.00038115), (1, ): InstructionProperties(duration=4.52e-8, error=0.00032115), } self._target.add_instruction(UGate(self._theta, self._phi, self._lam), u_props) cx_props = { (0, 1): InstructionProperties(duration=5.23e-7, error=0.00098115), } self._target.add_instruction(CXGate(), cx_props) measure_props = { (0, ): InstructionProperties(duration=6e-6, error=5e-6), (1, ): InstructionProperties(duration=1e-6, error=9e-6), } self._target.add_instruction(Measure(), measure_props) ecr_props = { (1, 0): InstructionProperties(duration=4.52e-9, error=0.0000132115), } self._target.add_instruction(ECRGate(), ecr_props) self.options.set_validator("shots", (1, 4096)) self._qubit_properties = { 0: QubitProperties(t1=63.48783e-6, t2=112.23246e-6, frequency=5.17538e9), 1: QubitProperties(t1=73.09352e-6, t2=126.83382e-6, frequency=5.26722e9), }
def _circuit_u(theta, phi, lam, phase, simplify=True, atol=DEFAULT_ATOL): # pylint: disable=unused-argument qr = QuantumRegister(1, 'qr') circuit = QuantumCircuit(qr, global_phase=phase) circuit._append(UGate(theta, phi, lam), [qr[0]], []) return circuit
def __init__(self, bidirectional=True): super().__init__( None, name="Fake5QV2", description="A fake BackendV2 example", online_date=datetime.datetime.utcnow(), backend_version="0.0.1", ) self._target = Target() self._theta = Parameter("theta") self._phi = Parameter("phi") self._lam = Parameter("lambda") u_props = { (0,): InstructionProperties(duration=5.23e-8, error=0.00038115), (1,): InstructionProperties(duration=4.52e-8, error=0.00032115), (2,): InstructionProperties(duration=5.23e-8, error=0.00038115), (3,): InstructionProperties(duration=4.52e-8, error=0.00032115), (4,): InstructionProperties(duration=4.52e-8, error=0.00032115), } self._target.add_instruction(UGate(self._theta, self._phi, self._lam), u_props) cx_props = { (0, 1): InstructionProperties(duration=5.23e-7, error=0.00098115), (3, 4): InstructionProperties(duration=5.23e-7, error=0.00098115), } if bidirectional: cx_props[(1, 0)] = InstructionProperties(duration=6.23e-7, error=0.00099115) cx_props[(4, 3)] = InstructionProperties(duration=7.23e-7, error=0.00099115) self._target.add_instruction(CXGate(), cx_props) measure_props = { (0,): InstructionProperties(duration=6e-6, error=5e-6), (1,): InstructionProperties(duration=1e-6, error=9e-6), (2,): InstructionProperties(duration=6e-6, error=5e-6), (3,): InstructionProperties(duration=1e-6, error=9e-6), (4,): InstructionProperties(duration=1e-6, error=9e-6), } self._target.add_instruction(Measure(), measure_props) ecr_props = { (1, 2): InstructionProperties(duration=4.52e-9, error=0.0000132115), (2, 3): InstructionProperties(duration=4.52e-9, error=0.0000132115), } if bidirectional: ecr_props[(2, 1)] = InstructionProperties(duration=5.52e-9, error=0.0000232115) ecr_props[(3, 2)] = InstructionProperties(duration=5.52e-9, error=0.0000232115) self._target.add_instruction(ECRGate(), ecr_props) self.options.set_validator("shots", (1, 4096)) self._qubit_properties = { 0: QubitProperties(t1=63.48783e-6, t2=112.23246e-6, frequency=5.17538e9), 1: QubitProperties(t1=73.09352e-6, t2=126.83382e-6, frequency=5.26722e9), 2: QubitProperties(t1=73.09352e-6, t2=126.83382e-6, frequency=5.26722e9), 3: QubitProperties(t1=73.09352e-6, t2=126.83382e-6, frequency=5.26722e9), 4: QubitProperties(t1=73.09352e-6, t2=126.83382e-6, frequency=5.26722e9), }
def test_optimize_u_to_phase_gate(self): """U(0, 0, pi/4) -> p(pi/4). Basis [p, sx].""" qr = QuantumRegister(2, 'qr') circuit = QuantumCircuit(qr) circuit.append(UGate(0, 0, np.pi / 4), [qr[0]]) expected = QuantumCircuit(qr) expected.append(PhaseGate(np.pi / 4), [qr[0]]) basis = ['p', 'sx'] passmanager = PassManager() passmanager.append(BasisTranslator(sel, basis)) passmanager.append(Optimize1qGatesDecomposition(basis)) result = passmanager.run(circuit) self.assertEqual(expected, result)
def test_optimize_u_to_phase_gate(self): """U(0, 0, pi/4) -> p(pi/4). Basis [p, sx].""" qr = QuantumRegister(2, "qr") circuit = QuantumCircuit(qr) circuit.append(UGate(0, 0, np.pi / 4), [qr[0]]) expected = QuantumCircuit(qr) expected.append(PhaseGate(np.pi / 4), [qr[0]]) basis = ["p", "sx"] passmanager = PassManager() passmanager.append(BasisTranslator(sel, basis)) passmanager.append(Optimize1qGatesDecomposition(basis)) result = passmanager.run(circuit) msg = f"expected:\n{expected}\nresult:\n{result}" self.assertEqual(expected, result, msg=msg)
def test_optimize_u_to_p_sx_p(self): """U(pi/2, 0, pi/4) -> p(-pi/4)-sx-p(p/2). Basis [p, sx].""" qr = QuantumRegister(2, 'qr') circuit = QuantumCircuit(qr) circuit.append(UGate(np.pi / 2, 0, np.pi / 4), [qr[0]]) expected = QuantumCircuit(qr, global_phase=-np.pi / 4) expected.append(PhaseGate(-np.pi / 4), [qr[0]]) expected.append(SXGate(), [qr[0]]) expected.append(PhaseGate(np.pi / 2), [qr[0]]) basis = ['p', 'sx'] passmanager = PassManager() passmanager.append(BasisTranslator(sel, basis)) passmanager.append(Optimize1qGatesDecomposition(basis)) result = passmanager.run(circuit) msg = f"expected:\n{expected}\nresult:\n{result}" self.assertEqual(expected, result, msg=msg)
def _circuit_u(theta, phi, lam, phase, simplify=True, atol=DEFAULT_ATOL): # pylint: disable=unused-argument circuit = QuantumCircuit(1, global_phase=phase) circuit.append(UGate(theta, phi, lam), [0]) return circuit