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

Generalized circuit drawing without needing direction hints or extra wire components #79

Open
dyc3 opened this issue May 6, 2022 · 1 comment

Comments

@dyc3
Copy link

dyc3 commented May 6, 2022

It's very frustrating to work with a circuit that you can't visualize to make sure you did it right. Unfortunately, for lcapy circuits, not all circuits that are drawable are solvable, and vice versa.

These functions generate circuits that are either drawable or solvable.

def __generate_RC_filter(high_pass: bool, order: int=1, drawable: bool=False) -> Circuit:
	"""Generate an RC filter circuit of the given order.

	If drawable is True, the circuit will be drawable when you call draw(). Otherwise, it may not. Drawable circuits may not be solvable circuits."""
	assert order > 0
	netlist = ""
	if drawable:
		netlist += f"""
		Vin 1 "0_0"; down, v=V_{{in}}
		"""
	for i in range(order):
		if high_pass:
			netlist += f"""
			C{i} {i+1} {i+2}; right
			R{i} {i+2} {f"0_{(i+1)}" if drawable else 0}; down
			"""
		else:
			netlist += f"""
			R{i} {i+1} {i+2}; right
			C{i} {i+2} {f"0_{(i+1)}" if drawable else 0}; down
			"""

		if drawable:
			netlist += f"""
			W 0_{i} 0_{i+1}; right, ground
			"""
	# if drawable:
	# 	netlist += f"""
	# 	Pout {order + 2} 0_0; down, v=V_{{out}}
	# 	"""
	netlist += f"""
	;draw_nodes=connections, cpt_size=1
	"""
	cct = Circuit(netlist)
	return cct

def low_pass_RC_filter(order: int = 1, drawable=False) -> Circuit:
	"""Generate a low pass filter circuit of the given order."""
	assert order > 0
	return __generate_RC_filter(False, order, drawable)

def high_pass_RC_filter(order: int = 1, drawable=False) -> Circuit:
	"""Generate a high pass filter circuit of the given order."""
	assert order > 0
	return __generate_RC_filter(True, order, drawable)

I think it could be possible to use something like the networkx library to compute layouts for circuits automatically.

@mph-
Copy link
Owner

mph- commented May 7, 2022

This is on my list of todos. However, it is a tricky problem. Moreover, the drawing hints are not sufficient and other heuristics are required such as symmetry.

The current algorithm solves the horizontal placement and vertical placement graphs independently but I think this more sophisticated approach will require both graphs to be solved concurrently. There is another algorithm I have tried (see schemlineqplacer.py) that could be applied but again this needs some heuristics to get a tidy solution.

I welcome any suggestions of algorithms that could be used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants