本文整理汇总了Python中pyquil.gates.CNOT属性的典型用法代码示例。如果您正苦于以下问题:Python gates.CNOT属性的具体用法?Python gates.CNOT怎么用?Python gates.CNOT使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类pyquil.gates
的用法示例。
在下文中一共展示了gates.CNOT属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_diffusion_operator
# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import CNOT [as 别名]
def test_diffusion_operator():
"""
Checks that the diffusion operator outputs the correct operation
"""
created = decomposed_diffusion_program(qubits[:2])
desired = Program()
for def_gate in created.defined_gates:
desired.defgate(def_gate.name, def_gate.matrix)
qubit0 = qubits[0]
qubit1 = qubits[1]
desired.inst(X(qubit0))
desired.inst(X(qubit1))
desired.inst(H(qubit1))
desired.inst(RZ(-np.pi, qubit0))
desired.inst(CNOT(qubit0, qubit1))
desired.inst(RZ(-np.pi, qubit0))
desired.inst(H(qubit1))
desired.inst(X(qubit0))
desired.inst(X(qubit1))
assert desired == created
示例2: double_control_test
# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import CNOT [as 别名]
def double_control_test(instructions, target_qubit, control_qubit_one, control_qubit_two):
"""A list of asserts testing the simple case of a double controlled Z gate. Used in the next
two tests."""
cpg = ControlledProgramBuilder()
sqrt_z = cpg.format_gate_name("SQRT", SIGMA_Z_NAME)
assert instructions[0].name == (cpg.format_gate_name("C", sqrt_z))
assert instructions[0].qubits == [control_qubit_two, target_qubit]
assert instructions[1].name == CNOT(control_qubit_one, control_qubit_two).name
assert instructions[1].qubits == [control_qubit_one, control_qubit_two]
assert instructions[2].name == cpg.format_gate_name("C", sqrt_z) + '-INV'
assert instructions[2].qubits == [control_qubit_two, target_qubit]
assert instructions[3].name == CNOT(control_qubit_one, control_qubit_two).name
assert instructions[3].qubits == [control_qubit_one, control_qubit_two]
assert instructions[4].name == cpg.format_gate_name("C", sqrt_z)
assert instructions[4].qubits == [control_qubit_one, target_qubit]
示例3: test_psiref_bar_p2
# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import CNOT [as 别名]
def test_psiref_bar_p2():
bar = [(0, 1)]
p = 2
with patch('pyquil.api.get_qc', spec=qc_mod):
inst = maxcut_qaoa(bar, steps=p)
param_prog = inst.get_parameterized_program()
# returns are the rotations correct?
prog = param_prog([1.2, 3.4, 2.1, 4.5])
result_prog = Program().inst([H(0), H(1),
CNOT(0, 1), RZ(2.1, 1), CNOT(0, 1),
X(0), PHASE(1.05, 0), X(0), PHASE(1.05, 0),
H(0), RZ(-2.4, 0), H(0),
H(1), RZ(-2.4, 1), H(1),
CNOT(0, 1), RZ(4.5, 1), CNOT(0, 1),
X(0), PHASE(2.25, 0), X(0), PHASE(2.25, 0),
H(0), RZ(-6.8, 0), H(0),
H(1), RZ(-6.8, 1), H(1),
])
assert prog == result_prog
示例4: test_parameter_not_given_error
# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import CNOT [as 别名]
def test_parameter_not_given_error(self):
"""Test that the correct error is raised if a parameter is not given."""
program = pyquil.Program()
alpha = program.declare("alpha", "REAL")
beta = program.declare("beta", "REAL")
program += g.H(0)
program += g.CNOT(0, 1)
program += g.RX(alpha, 1)
program += g.RZ(beta, 1)
a = 0.1
parameter_map = {"alpha": a}
with pytest.raises(
qml.DeviceError,
match="The PyQuil program defines a variable .* that is not present in the given variable map",
):
load_program(program)(wires=range(2), parameter_map=parameter_map)
示例5: test_qc_calibration_2q
# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import CNOT [as 别名]
def test_qc_calibration_2q(forest):
# noise model with 95% symmetrized readout fidelity per qubit
noise_model = asymmetric_ro_model([0, 1], 0.945, 0.955)
qc = get_qc("2q-qvm")
qc.qam.noise_model = noise_model
# bell state program (doesn't matter)
p = Program()
p += RESET()
p += H(0)
p += CNOT(0, 1)
p.wrap_in_numshots_loop(10000)
# ZZ experiment
sz = ExperimentSetting(in_state=sZ(0) * sZ(1), out_operator=sZ(0) * sZ(1))
e = Experiment(settings=[sz], program=p)
results = qc.calibrate(e)
# ZZ expectation should just be (1 - 2 * readout_error_q0) * (1 - 2 * readout_error_q1)
np.isclose(results[0].expectation, 0.81, atol=0.01)
assert results[0].total_counts == 40000
示例6: test_to_latex
# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import CNOT [as 别名]
def test_to_latex():
"""A test to give full coverage of latex_generation."""
p = Program()
p.inst(
X(0),
RX(1.0, 5),
Y(0),
CZ(0, 2),
SWAP(0, 1),
MEASURE(0, None),
CNOT(2, 0),
X(0).controlled(1),
Y(0).dagger(),
)
_ = to_latex(p)
# Modify settings to access non-standard control paths.
settings = DiagramSettings(impute_missing_qubits=True)
_ = to_latex(p, settings)
settings = DiagramSettings(abbreviate_controlled_rotations=True)
_ = to_latex(p, settings)
settings = DiagramSettings(label_qubit_lines=False)
_ = to_latex(p, settings)
示例7: test_measure_observables
# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import CNOT [as 别名]
def test_measure_observables(forest):
expts = [
ExperimentSetting(TensorProductState(), o1 * o2)
for o1, o2 in itertools.product([sI(0), sX(0), sY(0), sZ(0)], [sI(1), sX(1), sY(1), sZ(1)])
]
suite = Experiment(expts, program=Program(X(0), CNOT(0, 1)))
assert len(suite) == 4 * 4
gsuite = group_experiments(suite)
assert len(gsuite) == 3 * 3 # can get all the terms with I for free in this case
qc = get_qc("2q-qvm")
for res in measure_observables(qc, gsuite, n_shots=2000):
if res.setting.out_operator in [sI(), sZ(0), sZ(1), sZ(0) * sZ(1)]:
assert np.abs(res.expectation) > 0.9
else:
assert np.abs(res.expectation) < 0.1
示例8: test_measure_observables_symmetrize
# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import CNOT [as 别名]
def test_measure_observables_symmetrize(forest):
"""
Symmetrization alone should not change the outcome on the QVM
"""
expts = [
ExperimentSetting(TensorProductState(), o1 * o2)
for o1, o2 in itertools.product([sI(0), sX(0), sY(0), sZ(0)], [sI(1), sX(1), sY(1), sZ(1)])
]
suite = Experiment(expts, program=Program(X(0), CNOT(0, 1)))
assert len(suite) == 4 * 4
gsuite = group_experiments(suite)
assert len(gsuite) == 3 * 3 # can get all the terms with I for free in this case
qc = get_qc("2q-qvm")
for res in measure_observables(qc, gsuite, calibrate_readout=None):
if res.setting.out_operator in [sI(), sZ(0), sZ(1), sZ(0) * sZ(1)]:
assert np.abs(res.expectation) > 0.9
else:
assert np.abs(res.expectation) < 0.1
示例9: test_run
# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import CNOT [as 别名]
def test_run(forest):
device = NxDevice(nx.complete_graph(3))
qc = QuantumComputer(
name="testy!",
qam=QVM(connection=forest, gate_noise=[0.01] * 3),
device=device,
compiler=DummyCompiler(),
)
bitstrings = qc.run(
Program(
Declare("ro", "BIT", 3),
H(0),
CNOT(0, 1),
CNOT(1, 2),
MEASURE(0, MemoryReference("ro", 0)),
MEASURE(1, MemoryReference("ro", 1)),
MEASURE(2, MemoryReference("ro", 2)),
).wrap_in_numshots_loop(1000)
)
assert bitstrings.shape == (1000, 3)
parity = np.sum(bitstrings, axis=1) % 3
assert 0 < np.mean(parity) < 0.15
示例10: test_run_pyqvm_noisy
# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import CNOT [as 别名]
def test_run_pyqvm_noisy():
device = NxDevice(nx.complete_graph(3))
qc = QuantumComputer(
name="testy!",
qam=PyQVM(n_qubits=3, post_gate_noise_probabilities={"relaxation": 0.01}),
device=device,
compiler=DummyCompiler(),
)
prog = Program(H(0), CNOT(0, 1), CNOT(1, 2))
ro = prog.declare("ro", "BIT", 3)
for q in range(3):
prog += MEASURE(q, ro[q])
bitstrings = qc.run(prog.wrap_in_numshots_loop(1000))
assert bitstrings.shape == (1000, 3)
parity = np.sum(bitstrings, axis=1) % 3
assert 0 < np.mean(parity) < 0.15
示例11: test_exponentiate_bp1_YZ
# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import CNOT [as 别名]
def test_exponentiate_bp1_YZ():
q = QubitPlaceholder.register(8)
# testing change of basis position 1
generator = PauliTerm("Z", q[0], 1.0) * PauliTerm("Y", q[1], 1.0)
para_prog = exponential_map(generator)
prog = para_prog(1)
result_prog = Program().inst(
[
RX(math.pi / 2.0, q[1]),
CNOT(q[0], q[1]),
RZ(2.0, q[1]),
CNOT(q[0], q[1]),
RX(-math.pi / 2.0, q[1]),
]
)
assert address_qubits(prog) == address_qubits(result_prog)
示例12: test_exponentiate_3cob
# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import CNOT [as 别名]
def test_exponentiate_3cob():
# testing circuit for 3-terms with change of basis
q = QubitPlaceholder.register(8)
generator = PauliTerm("Z", q[0], 1.0) * PauliTerm("Y", q[1], 1.0) * PauliTerm("X", q[2], 1.0)
para_prog = exponential_map(generator)
prog = para_prog(1)
result_prog = Program().inst(
[
RX(math.pi / 2.0, q[1]),
H(q[2]),
CNOT(q[0], q[1]),
CNOT(q[1], q[2]),
RZ(2.0, q[2]),
CNOT(q[1], q[2]),
CNOT(q[0], q[1]),
RX(-math.pi / 2.0, q[1]),
H(q[2]),
]
)
assert address_qubits(prog) == address_qubits(result_prog)
示例13: test_exponentiate_3cob
# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import CNOT [as 别名]
def test_exponentiate_3cob():
# testing circuit for 3-terms with change of basis
generator = PauliTerm("Z", 0, 1.0) * PauliTerm("Y", 1, 1.0) * PauliTerm("X", 2, 1.0)
para_prog = exponential_map(generator)
prog = para_prog(1)
result_prog = Program().inst(
[
RX(math.pi / 2.0, 1),
H(2),
CNOT(0, 1),
CNOT(1, 2),
RZ(2.0, 2),
CNOT(1, 2),
CNOT(0, 1),
RX(-math.pi / 2.0, 1),
H(2),
]
)
assert prog == result_prog
示例14: _construct_deutsch_jozsa_circuit
# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import CNOT [as 别名]
def _construct_deutsch_jozsa_circuit(self):
"""
Builds the Deutsch-Jozsa circuit. Which can determine whether a function f mapping
:math:`\{0,1\}^n \to \{0,1\}` is constant or balanced, provided that it is one of them.
:return: A program corresponding to the desired instance of Deutsch Jozsa's Algorithm.
:rtype: Program
"""
dj_prog = Program()
# Put the first ancilla qubit (query qubit) into minus state
dj_prog.inst(X(self.ancillas[0]), H(self.ancillas[0]))
# Apply Hadamard, Oracle, and Hadamard again
dj_prog.inst([H(qubit) for qubit in self.computational_qubits])
# Build the oracle
oracle_prog = Program()
oracle_prog.defgate(ORACLE_GATE_NAME, self.unitary_matrix)
scratch_bit = self.ancillas[1]
qubits_for_funct = [scratch_bit] + self.computational_qubits
oracle_prog.inst(tuple([ORACLE_GATE_NAME] + qubits_for_funct))
dj_prog += oracle_prog
# Here the oracle does not leave the computational qubits unchanged, so we use a CNOT to
# to move the result to the query qubit, and then we uncompute with the dagger.
dj_prog.inst(CNOT(self._qubits[0], self.ancillas[0]))
dj_prog += oracle_prog.dagger()
dj_prog.inst([H(qubit) for qubit in self.computational_qubits])
return dj_prog
示例15: test_param_prog_p1_barbell
# 需要导入模块: from pyquil import gates [as 别名]
# 或者: from pyquil.gates import CNOT [as 别名]
def test_param_prog_p1_barbell():
test_graph = [(0, 1)]
p = 1
with patch('pyquil.api.get_qc', spec=qc_mod):
inst = maxcut_qaoa(test_graph, steps=p)
param_prog = inst.get_parameterized_program()
trial_prog = param_prog([1.2, 3.4])
result_prog = Program().inst([H(0), H(1), CNOT(0, 1), RZ(3.4, 1),
CNOT(0, 1), X(0), PHASE(1.7, 0), X(0),
PHASE(1.7, 0), H(0), RZ(-2.4, 0), H(0), H(1),
RZ(-2.4, 1), H(1)])
assert trial_prog == result_prog