Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set default logging level for tests #2105

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions test/unit/test_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def test_unsupported_dynamical_decoupling_with_dynamic_circuits(self):
dynamic_circuit.if_else(
(0, True), QuantumCircuit(3, 1), QuantumCircuit(3, 1), [0, 1, 2], [0]
)
dynamic_circuit.measure_all()

in_pubs = [(dynamic_circuit,)]
backend = get_mocked_backend()
Expand Down Expand Up @@ -144,18 +145,21 @@ def test_sampler_validations(self):
) as session:
inst = SamplerV2(mode=session)
circ = QuantumCircuit(QuantumRegister(2), ClassicalRegister(0))
circ.measure_all()
with self.assertRaisesRegex(ValueError, "Classical register .* is of size 0"):
inst.run([(circ,)])

creg = ClassicalRegister(2, "not-an-identifier")
circ = QuantumCircuit(QuantumRegister(2), creg)
circ.measure_all()
with self.assertRaisesRegex(
ValueError, "Classical register names must be valid identifiers"
):
inst.run([(circ,)])

creg = ClassicalRegister(2, "lambda")
circ = QuantumCircuit(QuantumRegister(2), creg)
circ.measure_all()
with self.assertRaisesRegex(
ValueError, "Classical register names cannot be Python keywords"
):
Expand All @@ -175,6 +179,7 @@ def test_run_dynamic_circuit_with_fractional_opted(self):
dynamic_circuit.if_else(
(0, True), QuantumCircuit(3, 1), QuantumCircuit(3, 1), [0, 1, 2], [0]
)
dynamic_circuit.measure_all()

inst = SamplerV2(mode=backend)
with self.assertRaises(IBMInputValueError):
Expand Down Expand Up @@ -292,6 +297,7 @@ def test_rzz_fixed_angle_validation(self, angle):

circ = QuantumCircuit(2)
circ.rzz(angle, 0, 1)
circ.measure_all()

if angle == 1:
SamplerV2(backend).run(pubs=[(circ)])
Expand All @@ -308,6 +314,7 @@ def test_rzz_parametrized_angle_validation(self, angle):

circ = QuantumCircuit(2)
circ.rzz(param, 0, 1)
circ.measure_all()

if angle == 1:
SamplerV2(backend).run(pubs=[(circ, [angle])])
Expand Down Expand Up @@ -387,6 +394,7 @@ def test_rzz_validation_skips_param_exp(self):

circ = QuantumCircuit(2)
circ.rzz(2 * param, 0, 1)
circ.measure_all()

# Since we currently don't validate parameter expressions, the following line should run
# without an error, in spite of the angle being larger than pi/2
Expand Down
3 changes: 2 additions & 1 deletion test/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def setup_test_logging(logger: logging.Logger, filename: str) -> None:
file_handler.setFormatter(formatter)
logger.addHandler(file_handler)

logger.setLevel(os.getenv("LOG_LEVEL", "DEBUG"))
logger.setLevel(os.getenv("LOG_LEVEL", "INFO"))


def most_busy_backend(
Expand Down Expand Up @@ -459,6 +459,7 @@ def transpile_pubs(in_pubs, backend, program):
"""Return pubs with transformed circuits and observables."""
t_pubs = []
for pub in in_pubs:
pub[0].measure_all()
t_circ = transpile(pub[0], backend=backend)
if program == "estimator":
t_obs = remap_observables(pub[1], t_circ)
Expand Down
Loading