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

heavy_hex generator functions raises PanicException if you pass d=1 #452

Closed
mtreinish opened this issue Sep 19, 2021 · 2 comments · Fixed by #453
Closed

heavy_hex generator functions raises PanicException if you pass d=1 #452

mtreinish opened this issue Sep 19, 2021 · 2 comments · Fixed by #453
Labels
bug Something isn't working

Comments

@mtreinish
Copy link
Member

Information

  • retworkx version: 0.10.2
  • Python version: 3.9
  • Rust version: 1.54
  • Operating system: Linux

What is the current behavior?

When passed d=1 to retworkx.generators.heavy_hex_graph or retworkx.generators.directed_heavy_hex_graph it raises a PanicException (meaning there was a panic in rust):

thread '<unnamed>' panicked at 'assertion failed: `(left != right)`
  left: `0`,
 right: `0`', /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/slice/mod.rs:790:9
stack backtrace:
   0:     0x7fbfa4f0d815 - std::backtrace_rs::backtrace::libunwind::trace::h34055254b57d8e79
                               at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/../../backtrace/src/backtrace/libunwind.rs:90:5
   1:     0x7fbfa4f0d815 - std::backtrace_rs::backtrace::trace_unsynchronized::h8f1e3fbd9afff6ec
                               at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7fbfa4f0d815 - std::sys_common::backtrace::_print_fmt::h3a99a796b770c360
                               at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x7fbfa4f0d815 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h32d1f94a80615d18
                               at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/sys_common/backtrace.rs:46:22
   4:     0x7fbfa4ee88ec - core::fmt::write::h306731c068f7162c
                               at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/fmt/mod.rs:1110:17
   5:     0x7fbfa4f0b9e4 - std::io::Write::write_fmt::hd2fa90334eee2a21
                               at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/io/mod.rs:1588:15
   6:     0x7fbfa4f0c9eb - std::sys_common::backtrace::_print::h5abaa2601a852287
                               at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/sys_common/backtrace.rs:49:5
   7:     0x7fbfa4f0c9eb - std::sys_common::backtrace::print::h8d81445442bb638f
                               at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/sys_common/backtrace.rs:36:9
   8:     0x7fbfa4f0c9eb - std::panicking::default_hook::{{closure}}::hcfe804496a9fa747
                               at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/panicking.rs:208:50
   9:     0x7fbfa4f0b5e1 - std::panicking::default_hook::hbea8e3ccf2ba8901
                               at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/panicking.rs:225:9
  10:     0x7fbfa4f0b5e1 - std::panicking::rust_panic_with_hook::h7ee9e1a2d0f8975a
                               at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/panicking.rs:622:17
  11:     0x7fbfa4f256f8 - std::panicking::begin_panic_handler::{{closure}}::h8ab3b4491718b2c7
                               at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/panicking.rs:519:13
  12:     0x7fbfa4f2566c - std::sys_common::backtrace::__rust_end_short_backtrace::hd489062ffa586a9f
                               at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/sys_common/backtrace.rs:141:18
  13:     0x7fbfa4f2561d - rust_begin_unwind
                               at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/panicking.rs:515:5
  14:     0x7fbfa4d471e0 - core::panicking::panic_fmt::hca6330e3e14086b4
                               at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/panicking.rs:92:14
  15:     0x7fbfa4ee8dcb - core::panicking::assert_failed_inner::h33b45280069a80ed
  16:     0x7fbfa4d3ba6a - core::panicking::assert_failed::h4b7cf0bc1bcfbd1c
  17:     0x7fbfa4e4057f - retworkx::generators::__pyo3_raw_heavy_hex_graph::h72150d4404ab93c2
  18:     0x7fbfa5d8233b - <unknown>
  19:     0x7fbfa5d7f107 - _PyEval_EvalFrameDefault
  20:     0x7fbfa5d79489 - <unknown>
  21:     0x7fbfa5d78e71 - _PyEval_EvalCodeWithName
  22:     0x7fbfa5e30b13 - PyEval_EvalCode
  23:     0x7fbfa5e40884 - <unknown>
  24:     0x7fbfa5e3c55b - <unknown>
  25:     0x7fbfa5d5d2b9 - <unknown>
  26:     0x7fbfa5d5d46f - PyRun_InteractiveLoopFlags
  27:     0x7fbfa5cea3a3 - PyRun_AnyFileExFlags
  28:     0x7fbfa5cdefe7 - <unknown>
  29:     0x7fbfa5e230a9 - Py_BytesMain
  30:     0x7fbfa5aadb25 - __libc_start_main
  31:     0x560a350db04e - _start
  32:                0x0 - <unknown>
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
pyo3_runtime.PanicException: assertion failed: `(left != right)`
  left: `0`,
 right: `0`

with RUST_BACKTRACE=full set

What is the expected behavior?

The function either works, or raises an exception on why 1 is an invalid value for d.

Steps to reproduce the problem

import retworkx
retworkx.generators.heavy_hex_graph(1)
@mtreinish mtreinish added the bug Something isn't working label Sep 19, 2021
@georgios-ts
Copy link
Collaborator

The source of the problem is this line L1536 since chunks panics if chunk size is 0 (see https://doc.rust-lang.org/std/primitive.slice.html#panics-2). Giving as input d=1 the output graph will be just a single node which is not really meaningful but i don't see also any reason to raise an exception.

@mtreinish
Copy link
Member Author

Yeah, I agree there's no reason to error, I think we should just add a short circuit return of a single node graph if d == 1.

mtreinish added a commit to mtreinish/retworkx that referenced this issue Sep 19, 2021
The *heavy_hex_graph and *heavy_square_graph generator functions all
previously had an issue where they would panic when d=1 was passed as
the input to the functions. The d=1 is just a single node, so to avoid a
panic a special case is added to return a graph with a single node which
avoids the panic.

Fixes Qiskit#452
mtreinish added a commit that referenced this issue Oct 12, 2021
* Handle d=1 edge case in heavy graph functions

The *heavy_hex_graph and *heavy_square_graph generator functions all
previously had an issue where they would panic when d=1 was passed as
the input to the functions. The d=1 is just a single node, so to avoid a
panic a special case is added to return a graph with a single node which
avoids the panic.

Fixes #452

* Document behavior when d=1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants